--- /dev/null
+/*
+ File: Ambien.h
+ Program: Ambien
+ Original author: Michael Roßberg
+ mick@binaervarianz.de
+ Rewritten by: Joshua Wise
+ jwise@andrew.cmu.edu
+ Description: Ambien is a kernel extension to disable sleep-on-clamshell.
+
+ Ambien is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Ambien is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Ambien; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "Ambien.h"
+#include <IOKit/IOLib.h>
+#include <IOKit/pwr_mgt/RootDomain.h>
+#include <IOKit/pwr_mgt/IOPM.h>
+
+#define super IOService
+
+OSDefineMetaClassAndStructors(Ambien, IOService);
+
+bool Ambien::init(OSDictionary* properties)
+{
+ IOLog("Ambien.kext for Mac OS X Leopard, by Joshua Wise\n");
+
+ _workLoop = 0;
+ if (super::init(properties) == false) {
+ IOLog("Ambien::init: super::init failed\n");
+ return false;
+ }
+
+ return true;
+}
+
+bool Ambien::start(IOService* provider)
+{
+ static IOPMPowerState states[] =
+ {
+ {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {1, kIOPMDeviceUsable, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0}
+ };
+
+ if (!super::start(provider)) {
+ IOLog("Ambien::start: super::start failed\n");
+ return false;
+ }
+
+ PMinit();
+ provider->joinPMtree(this);
+ if (registerPowerDriver(this, states, 2) != IOPMNoErr)
+ {
+ IOLog("Ambien::start: registerPowerDriver returned error -- uh-oh!\n");
+ return false;
+ }
+
+ return true;
+}
+
+void Ambien::stop(IOService* provider)
+{
+ if (_workLoop)
+ {
+ _workLoop->release();
+ _workLoop = 0;
+ }
+
+ PMstop();
+ super::stop(provider);
+ IOLog("Ambien: your sleep schedule is back to you!\n");
+}
+
+IOReturn Ambien::setPowerState(unsigned long which, IOService *dev)
+{
+ if (which == 0)
+ {
+ IOLog("Ambien::setPowerState: system going to sleep\n");
+ } else {
+ IOLog("Ambien::setPowerState: system is awake\n");
+ }
+
+ return kIOPMAckImplied;
+}
+
+void Ambien::free()
+{
+ super::free();
+ return;
+}
+
+IOWorkLoop* Ambien::getWorkLoop()
+{
+ if (!_workLoop)
+ _workLoop = IOWorkLoop::workLoop();
+
+ return _workLoop;
+}
+
+IOReturn Ambien::message(UInt32 type, IOService *provider, void *arg)
+{
+ unsigned int argi = (unsigned int)arg;
+
+ if (type == kIOPMMessageClamshellStateChange)
+ {
+ IOPMrootDomain *root = NULL;
+
+ IOLog("Ambien::message: kIOPMMessageClamshellStateChange: lid is %s, sleep bit is %d (arg %08x)\n",
+ (argi & kClamshellStateBit) ? "closed" : "open",
+ !!(argi & kClamshellSleepBit), argi);
+
+ root = getPMRootDomain();
+ if (!root)
+ {
+ IOLog("Ambien::message: failed to get PM root?\n");
+ return 0;
+ }
+ root->receivePowerNotification((argi & kClamshellStateBit) ? kIOPMPreventSleep : kIOPMAllowSleep);
+ } else
+ IOLog("Ambien::message: unknown type %08x (so I won't worry about it)\n", (unsigned int)type);
+ return super::message(type, provider, arg);
+}
--- /dev/null
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 42;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 42E2EB6D1004514E00EC9679 /* Ambien.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A224C3EFF42367911CA2CB7 /* Ambien.h */; };
+ 42E2EB6F1004514E00EC9679 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
+ 42E2EB711004514E00EC9679 /* Ambien.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */; settings = {ATTRIBUTES = (); }; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ 089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 1A224C3EFF42367911CA2CB7 /* Ambien.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ambien.h; sourceTree = "<group>"; };
+ 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Ambien.cpp; sourceTree = "<group>"; };
+ 423F076210CF8E2B00F3AA10 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ 42E2EB7A1004514E00EC9679 /* Ambien.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Ambien.kext; sourceTree = BUILT_PRODUCTS_DIR; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 42E2EB721004514E00EC9679 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 089C166AFE841209C02AAC07 /* Insomnia */ = {
+ isa = PBXGroup;
+ children = (
+ 423F076210CF8E2B00F3AA10 /* Info.plist */,
+ 247142CAFF3F8F9811CA285C /* Source */,
+ 089C167CFE841241C02AAC07 /* Resources */,
+ 19C28FB6FE9D52B211CA2CBB /* Products */,
+ );
+ name = Insomnia;
+ sourceTree = "<group>";
+ };
+ 089C167CFE841241C02AAC07 /* Resources */ = {
+ isa = PBXGroup;
+ children = (
+ 089C167DFE841241C02AAC07 /* InfoPlist.strings */,
+ );
+ name = Resources;
+ sourceTree = "<group>";
+ };
+ 19C28FB6FE9D52B211CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 42E2EB7A1004514E00EC9679 /* Ambien.kext */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 247142CAFF3F8F9811CA285C /* Source */ = {
+ isa = PBXGroup;
+ children = (
+ 1A224C3EFF42367911CA2CB7 /* Ambien.h */,
+ 1A224C3FFF42367911CA2CB7 /* Ambien.cpp */,
+ );
+ name = Source;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 42E2EB6C1004514E00EC9679 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 42E2EB6D1004514E00EC9679 /* Ambien.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXNativeTarget section */
+ 42E2EB6A1004514E00EC9679 /* Ambien kext */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 42E2EB751004514E00EC9679 /* Build configuration list for PBXNativeTarget "Ambien kext" */;
+ buildPhases = (
+ 42E2EB6B1004514E00EC9679 /* ShellScript */,
+ 42E2EB6C1004514E00EC9679 /* Headers */,
+ 42E2EB6E1004514E00EC9679 /* Resources */,
+ 42E2EB701004514E00EC9679 /* Sources */,
+ 42E2EB721004514E00EC9679 /* Frameworks */,
+ 42E2EB731004514E00EC9679 /* Rez */,
+ 42E2EB741004514E00EC9679 /* ShellScript */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "Ambien kext";
+ productInstallPath = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+ productName = nosleep;
+ productReference = 42E2EB7A1004514E00EC9679 /* Ambien.kext */;
+ productType = "com.apple.product-type.kernel-extension.iokit";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 089C1669FE841209C02AAC07 /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = 42E2EB58100450B500EC9679 /* Build configuration list for PBXProject "Ambien" */;
+ compatibilityVersion = "Xcode 2.4";
+ hasScannedForEncodings = 1;
+ mainGroup = 089C166AFE841209C02AAC07 /* Insomnia */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 42E2EB6A1004514E00EC9679 /* Ambien kext */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 42E2EB6E1004514E00EC9679 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 42E2EB6F1004514E00EC9679 /* InfoPlist.strings in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXRezBuildPhase section */
+ 42E2EB731004514E00EC9679 /* Rez */ = {
+ isa = PBXRezBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXRezBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ 42E2EB6B1004514E00EC9679 /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPreprocess\";\nif [ -x \"$script\" ]; then\n . \"$script\"\nfi";
+ };
+ 42E2EB741004514E00EC9679 /* ShellScript */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "script=\"${SYSTEM_DEVELOPER_DIR}/ProjectBuilder Extras/Kernel Extension Support/KEXTPostprocess\";\nif [ -x \"$script\" ]; then\n . \"$script\"\nfi";
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 42E2EB701004514E00EC9679 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 42E2EB711004514E00EC9679 /* Ambien.cpp in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ 089C167DFE841241C02AAC07 /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 089C167EFE841241C02AAC07 /* English */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 42E2EB52100450B500EC9679 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Development;
+ };
+ 42E2EB53100450B500EC9679 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Deployment;
+ };
+ 42E2EB54100450B500EC9679 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Default;
+ };
+ 42E2EB761004514E00EC9679 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ FRAMEWORK_SEARCH_PATHS = "";
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_FIX_AND_CONTINUE = YES;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ HEADER_SEARCH_PATHS = "";
+ INFOPLIST_FILE = Info.plist;
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+ KERNEL_MODULE = YES;
+ LIBRARY_SEARCH_PATHS = "";
+ MODULE_IOKIT = YES;
+ MODULE_NAME = com.joshuawise.kexts.Insomnia;
+ MODULE_VERSION = 1.0.0d1;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = Ambien;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = kext;
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 42E2EB771004514E00EC9679 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ FRAMEWORK_SEARCH_PATHS = "";
+ GCC_ENABLE_FIX_AND_CONTINUE = NO;
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ HEADER_SEARCH_PATHS = "";
+ INFOPLIST_FILE = Info.plist;
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+ KERNEL_MODULE = YES;
+ LIBRARY_SEARCH_PATHS = "";
+ MODULE_IOKIT = YES;
+ MODULE_NAME = org.binaervarianz.driver.insomnia;
+ MODULE_VERSION = 1.0.0d1;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = Insomnia;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = kext;
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 42E2EB781004514E00EC9679 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ FRAMEWORK_SEARCH_PATHS = "";
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ HEADER_SEARCH_PATHS = "";
+ INFOPLIST_FILE = Info.plist;
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Extensions";
+ KERNEL_MODULE = YES;
+ LIBRARY_SEARCH_PATHS = "";
+ MODULE_IOKIT = YES;
+ MODULE_NAME = org.binaervarianz.driver.insomnia;
+ MODULE_VERSION = 1.0.0d1;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = Insomnia;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = kext;
+ };
+ name = Default;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 42E2EB58100450B500EC9679 /* Build configuration list for PBXProject "Ambien" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 42E2EB52100450B500EC9679 /* Development */,
+ 42E2EB53100450B500EC9679 /* Deployment */,
+ 42E2EB54100450B500EC9679 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 42E2EB751004514E00EC9679 /* Build configuration list for PBXNativeTarget "Ambien kext" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 42E2EB761004514E00EC9679 /* Development */,
+ 42E2EB771004514E00EC9679 /* Deployment */,
+ 42E2EB781004514E00EC9679 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 089C1669FE841209C02AAC07 /* Project object */;
+}