]>
git.saurik.com Git - apple/securityd.git/blob - src/reader.cpp
10dd3940ab52cb94cb1c2893cfc4944570f1a24c
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 // reader - token reader objects
33 Reader::Reader(const PCSC::ReaderState
&state
)
37 secdebug("reader", "%p (%s) new reader", this, name().c_str());
44 secdebug("reader", "%p (%s) destroyed", this, name().c_str());
56 void Reader::update(const PCSC::ReaderState
&state
)
63 // State transition matrix for a reader, based on PCSC state changes
65 void Reader::transit(const PCSC::ReaderState
&state
)
67 if (state
.state(SCARD_STATE_UNAVAILABLE
)) {
68 // reader is unusable (probably being removed)
69 secdebug("reader", "%p (%s) unavailable (0x%lx)",
70 this, name().c_str(), state
.state());
73 } else if (state
.state(SCARD_STATE_EMPTY
)) {
74 // reader is empty (no token present)
75 secdebug("reader", "%p (%s) empty (0x%lx)",
76 this, name().c_str(), state
.state());
79 } else if (state
.state(SCARD_STATE_PRESENT
)) {
80 // reader has a token inserted
81 secdebug("reader", "%p (%s) card present (0x%lx)",
82 this, name().c_str(), state
.state());
83 //@@@ is this hack worth it (with notifications in)??
84 if (mToken
&& CssmData(state
) != CssmData(pcscState()))
85 removeToken(); // incomplete but better than nothing
86 //@@@ or should we call some verify-still-the-same function of tokend?
90 secdebug("reader", "%p (%s) unexpected state change (0x%ld to 0x%lx)",
91 this, name().c_str(), mState
.state(), state
.state());
97 void Reader::insertToken()
99 RefPointer
<Token
> token
= new Token();
100 token
->insert(*this);
102 addReference(*token
);
103 secdebug("reader", "%p (%s) inserted token %p",
104 this, name().c_str(), mToken
);
108 void Reader::removeToken()
110 secdebug("reader", "%p (%s) removing token %p",
111 this, name().c_str(), mToken
);
114 removeReference(*mToken
);
120 // Debug dump support
122 #if defined(DEBUGDUMP)
124 void Reader::dumpNode()
126 PerGlobal::dumpNode();
127 Debug::dump(" [%s] state=0x%lx", name().c_str(), mState
.state());