]>
git.saurik.com Git - apple/securityd.git/blob - src/reader.cpp
   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 // reader - token reader objects 
  33 // This does not commence state tracking; call update to start up the reader. 
  35 Reader::Reader(TokenCache 
&tc
, const PCSC::ReaderState 
&state
) 
  36         : cache(tc
), mType(pcsc
), mToken(NULL
) 
  38         mName 
= state
.name();   // remember separate copy of name 
  39         mPrintName 
= mName
;             //@@@ how to make this readable? Use IOKit information? 
  40         secdebug("reader", "%p (%s) new PCSC reader", this, name().c_str()); 
  43 Reader::Reader(TokenCache 
&tc
, const string 
&identifier
) 
  44         : cache(tc
), mType(software
), mToken(NULL
) 
  48         secdebug("reader", "%p (%s) new software reader", this, name().c_str()); 
  53         secdebug("reader", "%p (%s) destroyed", this, name().c_str()); 
  58 // Type qualification. None matches anything. 
  60 bool Reader::isType(Type reqType
) const 
  62         return reqType 
== this->type(); 
  67 // Killing a reader forcibly removes its Token, if any 
  78 // State transition matrix for a reader, based on PCSC state changes 
  80 void Reader::update(const PCSC::ReaderState 
&state
) 
  83         IFDEBUG(unsigned long oldState 
= mState
.state()); 
  85         mState
.name(mName
.c_str());             // (fix name pointer, unchanged) 
  88                 if (state
.state(SCARD_STATE_UNAVAILABLE
)) { 
  89                         // reader is unusable (probably being removed) 
  90                         secdebug("reader", "%p (%s) unavailable (0x%lx)", 
  91                                 this, name().c_str(), state
.state()); 
  94                 } else if (state
.state(SCARD_STATE_EMPTY
)) { 
  95                         // reader is empty (no token present) 
  96                         secdebug("reader", "%p (%s) empty (0x%lx)", 
  97                                 this, name().c_str(), state
.state()); 
 100                 } else if (state
.state(SCARD_STATE_PRESENT
)) { 
 101                         // reader has a token inserted 
 102                         secdebug("reader", "%p (%s) card present (0x%lx)", 
 103                                 this, name().c_str(), state
.state()); 
 104                         //@@@ is this hack worth it (with notifications in)?? 
 105                         if (mToken 
&& CssmData(state
) != CssmData(pcscState())) 
 106                                 removeToken();  // incomplete but better than nothing 
 107                         //@@@ or should we call some verify-still-the-same function of tokend? 
 108                         //@@@ (I think pcsc will return an error if the card changed?) 
 112                         secdebug("reader", "%p (%s) unexpected state change (0x%lx to 0x%lx)", 
 113                                 this, name().c_str(), oldState
, state
.state()); 
 116                 secdebug("reader", "state update exception (ignored)"); 
 121 void Reader::insertToken(TokenDaemon 
*tokend
) 
 123         RefPointer
<Token
> token 
= new Token(); 
 124         token
->insert(*this, tokend
); 
 126         addReference(*token
); 
 127         secdebug("reader", "%p (%s) inserted token %p", 
 128                 this, name().c_str(), mToken
); 
 132 void Reader::removeToken() 
 134         secdebug("reader", "%p (%s) removing token %p", 
 135                 this, name().c_str(), mToken
); 
 138         removeReference(*mToken
); 
 144 // Debug dump support 
 146 #if defined(DEBUGDUMP) 
 148 void Reader::dumpNode() 
 150         PerGlobal::dumpNode(); 
 151         Debug::dump(" [%s] state=0x%lx", name().c_str(), mState
.state());