2 * Copyright (c) 2004 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@
26 // pcscmonitor - use PCSC to monitor smartcard reader/card state for securityd
28 #ifndef _H_PCSCMONITOR
29 #define _H_PCSCMONITOR
32 #include "tokencache.h"
35 #include "notifications.h"
36 #include <security_utilities/unixchild.h>
37 #include <security_utilities/powerwatch.h>
38 #include <security_utilities/pcsc++.h>
39 #include <security_utilities/iodevices.h>
44 // A PCSCMonitor uses PCSC to monitor the state of smartcard readers and
45 // tokens (cards) in the system, and dispatches messages and events to the
46 // various related players in securityd. There should be at most one of these
47 // objects active within securityd.
49 class PCSCMonitor
: private Listener
,
50 private MachServer::Timer
,
51 private IOKit::NotificationPort::Receiver
,
52 private MachPlusPlus::PowerWatcher
,
53 private UnixPlusPlus::Child
,
57 forcedOff
, // no service under any circumstances
58 conservative
, // launch pcscd for certain smartcard devices
59 aggressive
, // launch pcscd for possible (and certain) smartcard devices
60 forcedOn
, // keep pcscd running at all times
61 externalDaemon
// use externally launched daemon if present (do not manage pcscd)
64 PCSCMonitor(Server
&server
, const char* pathToCache
, ServiceLevel level
= conservative
);
71 std::string cachePath
;
72 TokenCache
& getTokenCache ();
76 void notifyMe(SecurityServer::NotificationDomain domain
,
77 SecurityServer::NotificationEvent event
, const CssmData
&data
);
82 // NotificationPort::Receiver
83 void ioChange(IOKit::DeviceIterator
&iterator
);
86 void systemWillSleep();
87 void systemIsWaking();
95 void scheduleTimer(bool enable
);
97 void noDeviceTimeout();
100 impossible
, // certain this is not a smartcard
101 definite
, // definitely a smartcard device
102 possible
// perhaps... we're not sure
104 DeviceSupport
deviceSupport(const IOKit::Device
&dev
);
107 ServiceLevel mServiceLevel
; // level of service requested/determined
108 void (PCSCMonitor::*mTimerAction
)(); // what to do when our timer fires
109 bool mGoingToSleep
; // between sleep and wakeup; special timer handling
111 PCSC::Session mSession
; // PCSC client session
112 IOKit::MachPortNotificationPort mIOKitNotifier
; // IOKit connection
114 typedef map
<string
, RefPointer
<Reader
> > ReaderMap
;
115 typedef set
<RefPointer
<Reader
> > ReaderSet
;
116 ReaderMap mReaders
; // presently known PCSC Readers (aka slots)
120 #endif //_H_PCSCMONITOR