2 * Copyright (c) 2004,2007-2008 Apple 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 // token - internal representation of a (single distinct) hardware token
31 #include "structure.h"
32 #include "tokencache.h"
35 #include <security_utilities/pcsc++.h>
36 #include <securityd_client/ssnotify.h>
43 // Token is the global-scope object representing a smartcard token.
44 // It also acts as the global-scope database object for the TokenDatabase representing
45 // its content, and carries the ObjectAcls for objects on the token.
47 class Token
: public PerGlobal
, public virtual TokenAcl
, public FaultRelay
{
49 class Access
; friend class Access
;
55 ::Reader
&reader() const;
56 TokenDaemon
&tokend();
57 GenericHandle
tokenHandle() const;
58 uint32
subservice() const { return mSubservice
; }
59 std::string
printName() const { return mPrintName
; }
60 TokenCache::Token
&cache() const { return *mCache
; }
62 void insert(::Reader
&slot
, RefPointer
<TokenDaemon
> tokend
);
65 void notify(NotificationEvent event
);
66 void fault(bool async
);
70 IFDUMP(void dumpNode());
72 static RefPointer
<Token
> find(uint32 ssid
);
74 void getAcl(const char *tag
, uint32
&count
, AclEntryInfo
*&acls
);
75 ResetGeneration
resetGeneration() const;
76 bool resetGeneration(ResetGeneration rg
) const { return rg
== resetGeneration(); }
80 // SecurityServerAcl and TokenAcl personalities
81 AclKind
aclKind() const;
82 Token
&token(); // myself
84 // FaultRelay personality
85 void relayFault(bool async
);
95 TokenDaemon
&tokend() const { return *mTokend
; }
96 TokenDaemon
&operator () () const { return tokend(); }
99 RefPointer
<TokenDaemon
> mTokend
;
103 // keep track of TokenDbCommons for reset processing
104 // (this interface is for TokenDbCommon only)
105 void addCommon(TokenDbCommon
&dbc
);
106 void removeCommon(TokenDbCommon
&dbc
);
109 RefPointer
<TokenDaemon
> chooseTokend();
112 bool mFaulted
; // fault state flag
113 RefPointer
<TokenDaemon
> mTokend
; // the (one) tokend that runs the card
114 RefPointer
<TokenCache::Token
> mCache
; // token cache reference
115 std::string mPrintName
; // print name of token
117 Guid mGuid
; // our CSP/DL's Guid
118 uint32 mSubservice
; // dynamic subservice of gGuidAppleSdCSPDL
119 PCSC::ReaderState mState
; // reader state as of insertion
122 typedef map
<uint32
, Token
*> SSIDMap
;
123 static SSIDMap mSubservices
;
124 static Mutex mSSIDLock
;
126 typedef set
<TokenDbCommon
*> CommonSet
;
128 ResetGeneration mResetLevel
;