1/*
2 * Copyright (c) 2003 - 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#include <IOKit/IOMessage.h>
24#include <IOKit/pwr_mgt/RootDomain.h>
25
26extern "C"
27{
28#include <sys/smb_apple.h>
29#include <sys/syslog.h>
30#include <sys/kernel.h>
31#include <netsmb/smb_subr.h>
32
33#ifdef SMB_DEBUG
34	int32_t gSMBSleeping = 0;
35#endif // SMB_DEBUG
36	struct timespec gWakeTime = {0, 0};
37    void wakeup(void *);
38}
39#include <netsmb/smb_sleephandler.h>
40
41
42static IOReturn
43smb_sleepwakehandler(void *target, void *refCon, UInt32 messageType, IOService *provider, void *messageArgument, vm_size_t argSize)
44{
45#pragma unused (target, refCon, provider, messageArgument, argSize)
46	switch (messageType) {
47
48	case kIOMessageSystemWillSleep:
49		SMBDEBUG(" going to sleep\n");
50#ifdef SMB_DEBUG
51		gSMBSleeping = 1;
52#endif // SMB_DEBUG
53		break;
54
55	case kIOMessageSystemHasPoweredOn:
56		SMBDEBUG("  waking up\n");
57#ifdef SMB_DEBUG
58		gSMBSleeping = 0;
59#endif // SMB_DEBUG
60		nanouptime(&gWakeTime);
61		break;
62
63	default:
64		break;
65	}
66
67	return (IOPMAckImplied);
68}
69
70extern "C" {
71	IONotifier *fNotifier = NULL;
72
73	__attribute__((visibility("hidden"))) void smbfs_install_sleep_wake_notifier()
74	{
75		fNotifier = registerSleepWakeInterest(smb_sleepwakehandler, NULL, NULL);
76	}
77
78	__attribute__((visibility("hidden"))) void smbfs_remove_sleep_wake_notifier()
79	{
80		if (fNotifier != NULL) {
81			fNotifier->disable();
82			//fNotifier->release();  /* if you call this, you kernel panic radar 2946001 */
83			fNotifier = NULL;
84		}
85	}
86}
87