]> git.saurik.com Git - apple/securityd.git/blob - src/pcscmonitor.h
6ef6328567c0afbfd519fdefe9611834f9d7e706
[apple/securityd.git] / src / pcscmonitor.h
1 /*
2 * Copyright (c) 2004 Apple Computer, 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
24
25 //
26 // pcscmonitor - use PCSC to monitor smartcard reader/card state for securityd
27 //
28 #ifndef _H_PCSCMONITOR
29 #define _H_PCSCMONITOR
30
31 #include "server.h"
32 #include "tokencache.h"
33 #include "reader.h"
34 #include "token.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 <set>
41
42
43 //
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.
48 //
49 class PCSCMonitor : private Listener,
50 private MachServer::Timer,
51 private IOKit::NotificationPort::Receiver,
52 private MachPlusPlus::PowerWatcher,
53 private UnixPlusPlus::Child,
54 private Mutex {
55 public:
56 enum ServiceLevel {
57 forcedOff, // no service under any circumstances
58 conservative, // launch pcscd for certain smartcard devices
59 aggressive, // launch pcscd for possible smartcard devices
60 forcedOn, // keep pcscd running at all times
61 externalDaemon // use externally launched daemon
62 };
63
64 PCSCMonitor(Server &server, TokenCache &cache, ServiceLevel level = conservative);
65
66 protected:
67 void pollReaders();
68
69 Server &server;
70 TokenCache &cache;
71
72 protected:
73 // Listener
74 void notifyMe(SecurityServer::NotificationDomain domain,
75 SecurityServer::NotificationEvent event, const CssmData &data);
76
77 // MachServer::Timer
78 void action();
79
80 // NotificationPort::Receiver
81 void ioChange(IOKit::DeviceIterator &iterator);
82
83 // PowerWatcher
84 void systemWillSleep();
85 void systemIsWaking();
86
87 // Unix++/Child
88 void childAction();
89 void dying();
90
91 protected:
92 void launchPcscd();
93 void scheduleTimer(bool enable);
94 void initialSetup();
95 void noDeviceTimeout();
96
97 enum DeviceSupport {
98 impossible, // certain this is not a smartcard
99 definite, // definitely a smartcard device
100 possible // perhaps... we're not sure
101 };
102 DeviceSupport deviceSupport(const IOKit::Device &dev);
103
104 private:
105 ServiceLevel mServiceLevel; // level of service requested/determined
106 void (PCSCMonitor::*mTimerAction)(); // what to do when our timer fires
107 bool mGoingToSleep; // between sleep and wakeup; special timer handling
108
109 PCSC::Session mSession; // PCSC client session
110 IOKit::MachPortNotificationPort mIOKitNotifier; // IOKit connection
111
112 typedef map<string, RefPointer<Reader> > ReaderMap;
113 typedef set<RefPointer<Reader> > ReaderSet;
114 ReaderMap mReaders; // presently known PCSC Readers (aka slots)
115 };
116
117
118 #endif //_H_PCSCMONITOR