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>
40 #include <security_utilities/coderepository.h>
45 // A PCSCMonitor uses PCSC to monitor the state of smartcard readers and
46 // tokens (cards) in the system, and dispatches messages and events to the
47 // various related players in securityd. There should be at most one of these
48 // objects active within securityd.
50 class PCSCMonitor
: private Listener
,
51 private MachServer::Timer
,
52 private IOKit::NotificationPort::Receiver
,
53 private MachPlusPlus::PowerWatcher
,
54 private UnixPlusPlus::Child
,
58 forcedOff
, // no service under any circumstances
59 conservative
, // launch pcscd for certain smartcard devices
60 aggressive
, // launch pcscd for possible (and certain) smartcard devices
61 forcedOn
, // keep pcscd running at all times
62 externalDaemon
// use externally launched daemon if present (do not manage pcscd)
65 PCSCMonitor(Server
&server
, const char* pathToCache
, ServiceLevel level
= conservative
);
69 void clearReaders(Reader::Type type
);
72 TokenCache
& tokenCache();
76 void notifyMe(Notification
*message
);
81 // NotificationPort::Receiver
82 void ioChange(IOKit::DeviceIterator
&iterator
);
85 void systemWillSleep();
86 void systemIsWaking();
94 void scheduleTimer(bool enable
);
96 void noDeviceTimeout();
99 void startSoftTokens();
100 void loadSoftToken(Bundle
*tokendBundle
);
103 impossible
, // certain this is not a smartcard
104 definite
, // definitely a smartcard device
105 possible
// perhaps... we're not sure
107 DeviceSupport
deviceSupport(const IOKit::Device
&dev
);
108 bool isExcludedDevice(const IOKit::Device
&dev
);
111 ServiceLevel mServiceLevel
; // level of service requested/determined
112 void (PCSCMonitor::*mTimerAction
)(); // what to do when our timer fires
113 bool mGoingToSleep
; // between sleep and wakeup; special timer handling
115 std::string mCachePath
; // path to cache directory
116 TokenCache
*mTokenCache
; // cache object (lazy)
118 PCSC::Session mSession
; // PCSC client session
119 IOKit::MachPortNotificationPort mIOKitNotifier
; // IOKit connection
121 typedef map
<string
, RefPointer
<Reader
> > ReaderMap
;
122 typedef set
<RefPointer
<Reader
> > ReaderSet
;
123 ReaderMap mReaders
; // presently known PCSC Readers (aka slots)
127 #endif //_H_PCSCMONITOR