[SmartcardServices-Changes] [65] releases/Apple/Mac OS X 10.6.0
source_changes at macosforge.org
source_changes at macosforge.org
Mon Sep 7 14:57:09 PDT 2009
Revision: 65
http://trac.macosforge.org/projects/smartcardservices/changeset/65
Author: geddis at apple.com
Date: 2009-09-07 14:57:09 -0700 (Mon, 07 Sep 2009)
Log Message:
-----------
Added Paths:
-----------
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/APPLE_LICENSE
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Info-PCSC.plist
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Makefile.installPhase
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/SmartCardServices.xcodeproj/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/SmartCardServices.xcodeproj/project.pbxproj
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/Extensions/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/Info.plist
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/MacOS/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/MacOS/ifd-ASEIIIeUSB
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcscd.8
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctest.8
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctool.8
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/sc_auth.8
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/sc_auth
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/config.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSC.exp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/config.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.l
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.l
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_generic.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_macosx.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdhandler.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/mscdefines.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/muscletest.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdaemon.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscexport.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcsclite.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_generic.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_macosx.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_generic.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_macosx.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_unix.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/testpcsc.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_generic.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_macosx.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.l
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/utils/
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/utils/bundleTool.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_clnt.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg_srv.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.c
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/wintypes.h
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.cpp
releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.h
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/APPLE_LICENSE
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/APPLE_LICENSE (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/APPLE_LICENSE 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,372 @@
+APPLE PUBLIC SOURCE LICENSE
+Version 1.1 - April 19,1999
+
+Please read this License carefully before downloading this software.
+By downloading and using this software, you are agreeing to be bound
+by the terms of this License. If you do not or cannot agree to the
+terms of this License, please do not download or use the software.
+
+1. General; Definitions. This License applies to any program or other
+work which Apple Computer, Inc. ("Apple") publicly announces as
+subject to this Apple Public Source License and which contains a
+notice placed by Apple identifying such program or work as "Original
+Code" and stating that it is subject to the terms of this Apple Public
+Source License version 1.1 (or subsequent version thereof), as it may
+be revised from time to time by Apple ("License"). As used in this
+License:
+
+1.1 "Affected Original Code" means only those specific portions of
+Original Code that allegedly infringe upon any party's intellectual
+property rights or are otherwise the subject of a claim of
+infringement.
+
+1.2 "Applicable Patent Rights" mean: (a) in the case where Apple is
+the grantor of rights, (i) claims of patents that are now or hereafter
+acquired, owned by or assigned to Apple and (ii) that cover subject
+matter contained in the Original Code, but only to the extent
+necessary to use, reproduce and/or distribute the Original Code
+without infringement; and (b) in the case where You are the grantor of
+rights, (i) claims of patents that are now or hereafter acquired,
+owned by or assigned to You and (ii) that cover subject matter in Your
+Modifications, taken alone or in combination with Original Code.
+
+1.3 "Covered Code" means the Original Code, Modifications, the
+combination of Original Code and any Modifications, and/or any
+respective portions thereof.
+
+1.4 "Deploy" means to use, sublicense or distribute Covered Code other
+than for Your internal research and development (R&D), and includes
+without limitation, any and all internal use or distribution of
+Covered Code within Your business or organization except for R&D use,
+as well as direct or indirect sublicensing or distribution of Covered
+Code by You to any third party in any form or manner.
+
+1.5 "Larger Work" means a work which combines Covered Code or portions
+thereof with code not governed by the terms of this License.
+
+1.6 "Modifications" mean any addition to, deletion from, and/or change
+to, the substance and/or structure of Covered Code. When code is
+released as a series of files, a Modification is: (a) any addition to
+or deletion from the contents of a file containing Covered Code;
+and/or (b) any new file or other representation of computer program
+statements that contains any part of Covered Code.
+
+1.7 "Original Code" means (a) the Source Code of a program or other
+work as originally made available by Apple under this License,
+including the Source Code of any updates or upgrades to such programs
+or works made available by Apple under this License, and that has been
+expressly identified by Apple as such in the header file(s) of such
+work; and (b) the object code compiled from such Source Code and
+originally made available by Apple under this License.
+
+1.8 "Source Code" means the human readable form of a program or other
+work that is suitable for making modifications to it, including all
+modules it contains, plus any associated interface definition files,
+scripts used to control compilation and installation of an executable
+(object code).
+
+1.9 "You" or "Your" means an individual or a legal entity exercising
+rights under this License. For legal entities, "You" or "Your"
+includes any entity which controls, is controlled by, or is under
+common control with, You, where "control" means (a) the power, direct
+or indirect, to cause the direction or management of such entity,
+whether by contract or otherwise, or (b) ownership of fifty percent
+(50%) or more of the outstanding shares or beneficial ownership of
+such entity.
+
+2. Permitted Uses; Conditions & Restrictions. Subject to the terms
+and conditions of this License, Apple hereby grants You, effective on
+the date You accept this License and download the Original Code, a
+world-wide, royalty-free, non- exclusive license, to the extent of
+Apple's Applicable Patent Rights and copyrights covering the Original
+Code, to do the following:
+
+2.1 You may use, copy, modify and distribute Original Code, with or
+without Modifications, solely for Your internal research and
+development, provided that You must in each instance:
+
+(a) retain and reproduce in all copies of Original Code the copyright
+and other proprietary notices and disclaimers of Apple as they appear
+in the Original Code, and keep intact all notices in the Original Code
+that refer to this License;
+
+(b) include a copy of this License with every copy of Source Code of
+Covered Code and documentation You distribute, and You may not offer
+or impose any terms on such Source Code that alter or restrict this
+License or the recipients' rights hereunder, except as permitted under
+Section 6; and
+
+(c) completely and accurately document all Modifications that you have
+made and the date of each such Modification, designate the version of
+the Original Code you used, prominently include a file carrying such
+information with the Modifications, and duplicate the notice in
+Exhibit A in each file of the Source Code of all such Modifications.
+
+2.2 You may Deploy Covered Code, provided that You must in each
+ instance:
+
+(a) satisfy all the conditions of Section 2.1 with respect to the
+Source Code of the Covered Code;
+
+(b) make all Your Deployed Modifications publicly available in Source
+Code form via electronic distribution (e.g. download from a web site)
+under the terms of this License and subject to the license grants set
+forth in Section 3 below, and any additional terms You may choose to
+offer under Section 6. You must continue to make the Source Code of
+Your Deployed Modifications available for as long as you Deploy the
+Covered Code or twelve (12) months from the date of initial
+Deployment, whichever is longer;
+
+(c) if You Deploy Covered Code containing Modifications made by You,
+inform others of how to obtain those Modifications by filling out and
+submitting the information found at
+http://www.apple.com/publicsource/modifications.html, if available;
+and
+
+(d) if You Deploy Covered Code in object code, executable form only,
+include a prominent notice, in the code itself as well as in related
+documentation, stating that Source Code of the Covered Code is
+available under the terms of this License with information on how and
+where to obtain such Source Code.
+
+3. Your Grants. In consideration of, and as a condition to, the
+licenses granted to You under this License:
+
+(a) You hereby grant to Apple and all third parties a non-exclusive,
+royalty-free license, under Your Applicable Patent Rights and other
+intellectual property rights owned or controlled by You, to use,
+reproduce, modify, distribute and Deploy Your Modifications of the
+same scope and extent as Apple's licenses under Sections 2.1 and 2.2;
+and
+
+(b) You hereby grant to Apple and its subsidiaries a non-exclusive,
+worldwide, royalty-free, perpetual and irrevocable license, under Your
+Applicable Patent Rights and other intellectual property rights owned
+or controlled by You, to use, reproduce, execute, compile, display,
+perform, modify or have modified (for Apple and/or its subsidiaries),
+sublicense and distribute Your Modifications, in any form, through
+multiple tiers of distribution.
+
+4. Larger Works. You may create a Larger Work by combining Covered
+Code with other code not governed by the terms of this License and
+distribute the Larger Work as a single product. In each such
+instance, You must make sure the requirements of this License are
+fulfilled for the Covered Code or any portion thereof.
+
+5. Limitations on Patent License. Except as expressly stated in
+Section 2, no other patent rights, express or implied, are granted by
+Apple herein. Modifications and/or Larger Works may require
+additional patent licenses from Apple which Apple may grant in its
+sole discretion.
+
+6. Additional Terms. You may choose to offer, and to charge a fee
+for, warranty, support, indemnity or liability obligations and/or
+other rights consistent with the scope of the license granted herein
+("Additional Terms") to one or more recipients of Covered
+Code. However, You may do so only on Your own behalf and as Your sole
+responsibility, and not on behalf of Apple. You must obtain the
+recipient's agreement that any such Additional Terms are offered by
+You alone, and You hereby agree to indemnify, defend and hold Apple
+harmless for any liability incurred by or claims asserted against
+Apple by reason of any such Additional Terms.
+
+7. Versions of the License. Apple may publish revised and/or new
+versions of this License from time to time. Each version will be
+given a distinguishing version number. Once Original Code has been
+published under a particular version of this License, You may continue
+to use it under the terms of that version. You may also choose to use
+such Original Code under the terms of any subsequent version of this
+License published by Apple. No one other than Apple has the right to
+modify the terms applicable to Covered Code created under this
+License.
+
+8. NO WARRANTY OR SUPPORT. The Original Code may contain in whole or
+in part pre-release, untested, or not fully tested works. The
+Original Code may contain errors that could cause failures or loss of
+data, and may be incomplete or contain inaccuracies. You expressly
+acknowledge and agree that use of the Original Code, or any portion
+thereof, is at Your sole and entire risk. THE ORIGINAL CODE IS
+PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND
+AND APPLE AND APPLE'S LICENSOR(S) (FOR THE PURPOSES OF SECTIONS 8 AND
+9, APPLE AND APPLE'S LICENSOR(S) ARE COLLECTIVELY REFERRED TO AS
+"APPLE") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+AND/OR CONDITIONS OF MERCHANTABILITY OR SATISFACTORY QUALITY AND
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+RIGHTS. APPLE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE
+ORIGINAL CODE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF
+THE ORIGINAL CODE WILL BE UNINTERRUPTED OR ERROR- FREE, OR THAT
+DEFECTS IN THE ORIGINAL CODE WILL BE CORRECTED. NO ORAL OR WRITTEN
+INFORMATION OR ADVICE GIVEN BY APPLE OR AN APPLE AUTHORIZED
+REPRESENTATIVE SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE
+SCOPE OF THIS WARRANTY. You acknowledge that the Original Code is not
+intended for use in the operation of nuclear facilities, aircraft
+navigation, communication systems, or air traffic control machines in
+which case the failure of the Original Code could lead to death,
+personal injury, or severe physical or environmental damage.
+
+9. Liability.
+
+9.1 Infringement. If any portion of, or functionality implemented by,
+the Original Code becomes the subject of a claim of infringement,
+Apple may, at its option: (a) attempt to procure the rights necessary
+for Apple and You to continue using the Affected Original Code; (b)
+modify the Affected Original Code so that it is no longer infringing;
+or (c) suspend Your rights to use, reproduce, modify, sublicense and
+distribute the Affected Original Code until a final determination of
+the claim is made by a court or governmental administrative agency of
+competent jurisdiction and Apple lifts the suspension as set forth
+below. Such suspension of rights will be effective immediately upon
+Apple's posting of a notice to such effect on the Apple web site that
+is used for implementation of this License. Upon such final
+determination being made, if Apple is legally able, without the
+payment of a fee or royalty, to resume use, reproduction,
+modification, sublicensing and distribution of the Affected Original
+Code, Apple will lift the suspension of rights to the Affected
+Original Code by posting a notice to such effect on the Apple web site
+that is used for implementation of this License. If Apple suspends
+Your rights to Affected Original Code, nothing in this License shall
+be construed to restrict You, at Your option and subject to applicable
+law, from replacing the Affected Original Code with non-infringing
+code or independently negotiating for necessary rights from such third
+party.
+
+9.2 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES SHALL APPLE BE
+LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF OR RELATING TO THIS LICENSE OR YOUR USE OR INABILITY TO
+USE THE ORIGINAL CODE, OR ANY PORTION THEREOF, WHETHER UNDER A THEORY
+OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY
+OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF
+ANY REMEDY. In no event shall Apple's total liability to You for all
+damages under this License exceed the amount of fifty dollars
+($50.00).
+
+10. Trademarks. This License does not grant any rights to use the
+trademarks or trade names "Apple", "Apple Computer", "Mac OS X", "Mac
+OS X Server" or any other trademarks or trade names belonging to Apple
+(collectively "Apple Marks") and no Apple Marks may be used to endorse
+or promote products derived from the Original Code other than as
+permitted by and in strict compliance at all times with Apple's third
+party trademark usage guidelines which are posted at
+http://www.apple.com/legal/guidelinesfor3rdparties.html.
+
+11. Ownership. Apple retains all rights, title and interest in and to
+the Original Code and any Modifications made by or on behalf of Apple
+("Apple Modifications"), and such Apple Modifications will not be
+automatically subject to this License. Apple may, at its sole
+discretion, choose to license such Apple Modifications under this
+License, or on different terms from those contained in this License or
+may choose not to license them at all. Apple's development, use,
+reproduction, modification, sublicensing and distribution of Covered
+Code will not be subject to this License.
+
+12. Termination.
+
+12.1 Termination. This License and the rights granted hereunder will
+ terminate:
+
+(a) automatically without notice from Apple if You fail to comply with
+any term(s) of this License and fail to cure such breach within 30
+days of becoming aware of such breach; (b) immediately in the event of
+the circumstances described in Section 13.5(b); or (c) automatically
+without notice from Apple if You, at any time during the term of this
+License, commence an action for patent infringement against Apple.
+
+12.2 Effect of Termination. Upon termination, You agree to
+immediately stop any further use, reproduction, modification,
+sublicensing and distribution of the Covered Code and to destroy all
+copies of the Covered Code that are in your possession or control.
+All sublicenses to the Covered Code which have been properly granted
+prior to termination shall survive any termination of this License.
+Provisions which, by their nature, should remain in effect beyond the
+termination of this License shall survive, including but not limited
+to Sections 3, 5, 8, 9, 10, 11, 12.2 and 13. Neither party will be
+liable to the other for compensation, indemnity or damages of any sort
+solely as a result of terminating this License in accordance with its
+terms, and termination of this License will be without prejudice to
+any other right or remedy of either party.
+
+13. Miscellaneous.
+
+13.1 Government End Users. The Covered Code is a "commercial item" as
+defined in FAR 2.101. Government software and technical data rights
+in the Covered Code include only those rights customarily provided to
+the public as defined in this License. This customary commercial
+license in technical data and software is provided in accordance with
+FAR 12.211 (Technical Data) and 12.212 (Computer Software) and, for
+Department of Defense purchases, DFAR 252.227-7015 (Technical Data --
+Commercial Items) and 227.7202-3 (Rights in Commercial Computer
+Software or Computer Software Documentation). Accordingly, all U.S.
+Government End Users acquire Covered Code with only those rights set
+forth herein.
+
+13.2 Relationship of Parties. This License will not be construed as
+creating an agency, partnership, joint venture or any other form of
+legal association between You and Apple, and You will not represent to
+the contrary, whether expressly, by implication, appearance or
+otherwise.
+
+13.3 Independent Development. Nothing in this License will impair
+Apple's right to acquire, license, develop, have others develop for
+it, market and/or distribute technology or products that perform the
+same or similar functions as, or otherwise compete with,
+Modifications, Larger Works, technology or products that You may
+develop, produce, market or distribute.
+
+13.4 Waiver; Construction. Failure by Apple to enforce any provision
+of this License will not be deemed a waiver of future enforcement of
+that or any other provision. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+will not apply to this License.
+
+13.5 Severability. (a) If for any reason a court of competent
+jurisdiction finds any provision of this License, or portion thereof,
+to be unenforceable, that provision of the License will be enforced to
+the maximum extent permissible so as to effect the economic benefits
+and intent of the parties, and the remainder of this License will
+continue in full force and effect. (b) Notwithstanding the foregoing,
+if applicable law prohibits or restricts You from fully and/or
+specifically complying with Sections 2 and/or 3 or prevents the
+enforceability of either of those Sections, this License will
+immediately terminate and You must immediately discontinue any use of
+the Covered Code and destroy all copies of it that are in your
+possession or control.
+
+13.6 Dispute Resolution. Any litigation or other dispute resolution
+between You and Apple relating to this License shall take place in the
+Northern District of California, and You and Apple hereby consent to
+the personal jurisdiction of, and venue in, the state and federal
+courts within that District with respect to this License. The
+application of the United Nations Convention on Contracts for the
+International Sale of Goods is expressly excluded.
+
+13.7 Entire Agreement; Governing Law. This License constitutes the
+entire agreement between the parties with respect to the subject
+matter hereof. This License shall be governed by the laws of the
+United States and the State of California, except that body of
+California law concerning conflicts of law.
+
+Where You are located in the province of Quebec, Canada, the following
+clause applies: The parties hereby confirm that they have requested
+that this License and all related documents be drafted in English. Les
+parties ont exige que le present contrat et tous les documents
+connexes soient rediges en anglais.
+
+EXHIBIT A.
+
+"Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights
+Reserved. This file contains Original Code and/or Modifications of
+Original Code as defined in and that are subject to the Apple Public
+Source License Version 1.1 (the "License"). You may not use this file
+except in compliance with the License. Please obtain a copy of the
+License at http://www.apple.com/publicsource and read it before using
+this file.
+
+The Original Code and all software distributed under the License are
+distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
+License for the specific language governing rights and limitations
+under the License."
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Info-PCSC.plist
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Info-PCSC.plist (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Info-PCSC.plist 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>PCSC</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.apple.pcsc</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>7.0</string>
+ <key>CFBundleName</key>
+ <string>PCSC</string>
+ <key>CFBundlePackageType</key>
+ <string>FMWK</string>
+ <key>CFBundleShortVersionString</key>
+ <string>7.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>36160</string>
+</dict>
+</plist>
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Makefile.installPhase
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Makefile.installPhase (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/Makefile.installPhase 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,81 @@
+# The other phases do nothing
+
+MAN_DIR=$(DSTROOT)/usr/share/man/man8
+PCSCDIR=$(DSTROOT)/usr/libexec/SmartCardServices
+PKCS11_DIR=$(DSTROOT)/Library/Application\ Support/Mozilla/
+EXTENSIONS_DIR=$(DSTROOT)/System/Library/Extensions
+SCRIPTS_LOCATION=$(DSTROOT)/usr/sbin
+
+build:
+ @echo null build.
+
+debug:
+ @echo null debug.
+
+profile:
+ @echo null profile.
+
+install:
+ mkdir -p $(PCSCDIR)
+ mkdir -p $(PCSCDIR)/drivers
+ mkdir -p $(PCSCDIR)/services
+ chmod 755 $(PCSCDIR)
+ cp -r installPhase/drivers/*.bundle $(PCSCDIR)/drivers/
+ -rm -rf $(PCSCDIR)/drivers/*.bundle/CVS
+ -rm -rf $(PCSCDIR)/drivers/*.bundle/Contents/CVS
+ -rm -rf $(PCSCDIR)/drivers/*.bundle/Contents/MacOS/CVS
+ chmod 755 $(PCSCDIR)/drivers/*.bundle
+ chmod 755 $(PCSCDIR)/drivers/*.bundle/Contents
+ chmod 755 $(PCSCDIR)/drivers/*.bundle/Contents/MacOS
+ chmod 644 $(PCSCDIR)/drivers/*.bundle/Contents/*.*
+ chmod 644 $(PCSCDIR)/drivers/*.bundle/Contents/MacOS/*
+ /usr/bin/strip -S $(PCSCDIR)/drivers/*.bundle/Contents/MacOS/*
+ifdef haveExtensions
+ mkdir -p $(EXTENSIONS_DIR)
+ chmod 755 $(DSTROOT)/System
+ chmod 755 $(DSTROOT)/System/Library
+ chmod 755 $(EXTENSIONS_DIR)
+ cp -r installPhase/Extensions/*.kext $(EXTENSIONS_DIR)/
+ -rm -rf $(EXTENSIONS_DIR)/*.kext/CVS
+ -rm -rf $(EXTENSIONS_DIR)/*.kext/Contents/CVS
+ -rm -rf $(EXTENSIONS_DIR)/*.kext/Contents/MacOS/CVS
+ -rm -rf $(EXTENSIONS_DIR)/*.kext/Contents/Resources/CVS
+ -rm -rf $(EXTENSIONS_DIR)/*.kext/Contents/Resources/*.lproj/CVS
+ chmod 755 $(EXTENSIONS_DIR)/*.kext
+ chmod 755 $(EXTENSIONS_DIR)/*.kext/Contents
+ chmod 755 $(EXTENSIONS_DIR)/*.kext/Contents/MacOS
+ -chmod 755 $(EXTENSIONS_DIR)/*.kext/Contents/Resources
+ -chmod 755 $(EXTENSIONS_DIR)/*.kext/Contents/Resources/*.lproj
+ chmod 644 $(EXTENSIONS_DIR)/*.kext/Contents/*.*
+ chmod 644 $(EXTENSIONS_DIR)/*.kext/Contents/MacOS/*
+ -chmod 644 $(EXTENSIONS_DIR)/*.kext/Contents/Resources/*.lproj/*.*
+ /usr/bin/strip -S $(EXTENSIONS_DIR)/*.kext/Contents/MacOS/*
+endif
+
+ mkdir -p $(SCRIPTS_LOCATION)
+
+ cp installPhase/scripts/sc_auth $(SCRIPTS_LOCATION)
+ chown root:wheel $(SCRIPTS_LOCATION)/sc_auth
+ chmod 755 $(SCRIPTS_LOCATION)/sc_auth
+
+# Copy over man pages
+
+ mkdir -p $(MAN_DIR)
+ cp installPhase/man/pcscd.8 $(MAN_DIR)
+ cp installPhase/man/pcsctool.8 $(MAN_DIR)
+ cp installPhase/man/pcsctest.8 $(MAN_DIR)
+ cp installPhase/man/sc_auth.8 $(MAN_DIR)
+ chown root:wheel $(MAN_DIR)/sc_auth.8
+
+# Deleting CVS subdirectories from the copy phase
+
+ rm -rf `find $(PCSCDIR)/drivers -name CVS`
+
+installhdrs:
+ @echo null installhdrs.
+
+installsrc:
+ @echo null installsrc.
+
+clean:
+ @echo null clean.
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/SmartCardServices.xcodeproj/project.pbxproj
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/SmartCardServices.xcodeproj/project.pbxproj (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/SmartCardServices.xcodeproj/project.pbxproj 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1560 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 42;
+ objects = {
+
+/* Begin PBXAggregateTarget section */
+ 5234B66B0E78286000F02D95 /* World */ = {
+ isa = PBXAggregateTarget;
+ buildConfigurationList = 5234B6780E78286000F02D95 /* Build configuration list for PBXAggregateTarget "World" */;
+ buildPhases = (
+ );
+ dependencies = (
+ 5234B72F0E78286000F02D95 /* PBXTargetDependency */,
+ 5234B7310E78286000F02D95 /* PBXTargetDependency */,
+ 5234B7330E78286000F02D95 /* PBXTargetDependency */,
+ 5234B7350E78286000F02D95 /* PBXTargetDependency */,
+ 5234B7390E78286000F02D95 /* PBXTargetDependency */,
+ );
+ name = World;
+ productName = World;
+ };
+/* End PBXAggregateTarget section */
+
+/* Begin PBXBuildFile section */
+ 5234B67F0E78286000F02D95 /* atrhandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A948F0254242101B94B21 /* atrhandler.h */; };
+ 5234B6800E78286000F02D95 /* configfile.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94910254242101B94B21 /* configfile.h */; };
+ 5234B6810E78286000F02D95 /* debuglog.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94930254242101B94B21 /* debuglog.h */; };
+ 5234B6820E78286000F02D95 /* dyn_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94940254242101B94B21 /* dyn_generic.h */; };
+ 5234B6830E78286000F02D95 /* eventhandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94970254242101B94B21 /* eventhandler.h */; };
+ 5234B6840E78286000F02D95 /* hotplug.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94990254242101B94B21 /* hotplug.h */; };
+ 5234B6850E78286000F02D95 /* ifdhandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A949A0254242101B94B21 /* ifdhandler.h */; };
+ 5234B6860E78286000F02D95 /* ifdwrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A949C0254242101B94B21 /* ifdwrapper.h */; };
+ 5234B6870E78286000F02D95 /* pcsclite.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A949E0254242101B94B21 /* pcsclite.h */; };
+ 5234B6880E78286000F02D95 /* prothandler.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A00254242101B94B21 /* prothandler.h */; };
+ 5234B6890E78286000F02D95 /* readerfactory.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A20254242101B94B21 /* readerfactory.h */; };
+ 5234B68A0E78286000F02D95 /* sys_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A30254242101B94B21 /* sys_generic.h */; };
+ 5234B68B0E78286000F02D95 /* thread_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A50254242101B94B21 /* thread_generic.h */; };
+ 5234B68C0E78286000F02D95 /* winscard_msg.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A80254242101B94B21 /* winscard_msg.h */; };
+ 5234B68D0E78286000F02D95 /* winscard_svc.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94AA0254242101B94B21 /* winscard_svc.h */; };
+ 5234B68E0E78286000F02D95 /* winscard.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94AC0254242101B94B21 /* winscard.h */; };
+ 5234B68F0E78286000F02D95 /* wintypes.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94AD0254242101B94B21 /* wintypes.h */; };
+ 5234B6900E78286000F02D95 /* powermgt_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F555DF370274968F01D2E99F /* powermgt_generic.h */; };
+ 5234B6910E78286000F02D95 /* PCSCDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 5286293E0A87EA8E004FE8DC /* PCSCDevice.h */; };
+ 5234B6920E78286000F02D95 /* PCSCDriverBundle.h in Headers */ = {isa = PBXBuildFile; fileRef = 528629400A87EA8E004FE8DC /* PCSCDriverBundle.h */; };
+ 5234B6930E78286000F02D95 /* PCSCDriverBundles.h in Headers */ = {isa = PBXBuildFile; fileRef = 528629420A87EA8E004FE8DC /* PCSCDriverBundles.h */; };
+ 5234B6940E78286000F02D95 /* reader.h in Headers */ = {isa = PBXBuildFile; fileRef = 52D00D1A0A9252350093277A /* reader.h */; };
+ 5234B6950E78286000F02D95 /* pcscdmonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 527CF60B0AA5192B007589FF /* pcscdmonitor.h */; };
+ 5234B6960E78286000F02D95 /* pcscdserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 527CF60D0AA5192B007589FF /* pcscdserver.h */; };
+ 5234B6970E78286000F02D95 /* readerstate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5236DD1D0B9DDBD7007CEF56 /* readerstate.h */; };
+ 5234B6990E78286000F02D95 /* atrhandler.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94510254232701B94B21 /* atrhandler.c */; };
+ 5234B69A0E78286000F02D95 /* readerstate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5236DD1C0B9DDBD7007CEF56 /* readerstate.cpp */; };
+ 5234B69B0E78286000F02D95 /* configfile.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94900254242101B94B21 /* configfile.c */; settings = {COMPILER_FLAGS = "-DYY_NO_UNPUT"; }; };
+ 5234B69C0E78286000F02D95 /* debuglog.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94920254242101B94B21 /* debuglog.c */; };
+ 5234B69D0E78286000F02D95 /* dyn_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94950254242101B94B21 /* dyn_macosx.c */; };
+ 5234B69E0E78286000F02D95 /* eventhandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F52A94960254242101B94B21 /* eventhandler.cpp */; };
+ 5234B69F0E78286000F02D95 /* ifdwrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A949B0254242101B94B21 /* ifdwrapper.c */; };
+ 5234B6A00E78286000F02D95 /* pcscdaemon.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A949D0254242101B94B21 /* pcscdaemon.c */; };
+ 5234B6A10E78286000F02D95 /* prothandler.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A949F0254242101B94B21 /* prothandler.c */; };
+ 5234B6A20E78286000F02D95 /* readerfactory.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A10254242101B94B21 /* readerfactory.c */; };
+ 5234B6A30E78286000F02D95 /* thread_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A60254242101B94B21 /* thread_macosx.c */; };
+ 5234B6A40E78286000F02D95 /* winscard_msg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A70254242101B94B21 /* winscard_msg.cpp */; };
+ 5234B6A50E78286000F02D95 /* winscard_svc.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A90254242101B94B21 /* winscard_svc.c */; };
+ 5234B6A60E78286000F02D95 /* powermgt_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = F555DF350274962801D2E99F /* powermgt_macosx.c */; };
+ 5234B6A70E78286000F02D95 /* sys_macosx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2F2094A0662B851001DFD06 /* sys_macosx.cpp */; };
+ 5234B6A80E78286000F02D95 /* hotplug_macosx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5286293C0A87EA8E004FE8DC /* hotplug_macosx.cpp */; };
+ 5234B6A90E78286000F02D95 /* PCSCDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5286293D0A87EA8E004FE8DC /* PCSCDevice.cpp */; };
+ 5234B6AA0E78286000F02D95 /* PCSCDriverBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5286293F0A87EA8E004FE8DC /* PCSCDriverBundle.cpp */; };
+ 5234B6AB0E78286000F02D95 /* PCSCDriverBundles.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 528629410A87EA8E004FE8DC /* PCSCDriverBundles.cpp */; };
+ 5234B6AC0E78286000F02D95 /* reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52D00D1B0A9252350093277A /* reader.cpp */; };
+ 5234B6AD0E78286000F02D95 /* pcscdmonitor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 527CF60A0AA5192B007589FF /* pcscdmonitor.cpp */; };
+ 5234B6AE0E78286000F02D95 /* pcscdserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 527CF60C0AA5192B007589FF /* pcscdserver.cpp */; };
+ 5234B6AF0E78286000F02D95 /* winscard_msg_srv.c in Sources */ = {isa = PBXBuildFile; fileRef = 52D2492C0BA07E1100F9827A /* winscard_msg_srv.c */; };
+ 5234B6B00E78286000F02D95 /* winscard.c in Sources */ = {isa = PBXBuildFile; fileRef = 52E0D59D0BA7006D008DFDDF /* winscard.c */; };
+ 5234B6B20E78286000F02D95 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F503CADB025428F601B94B21 /* CoreFoundation.framework */; };
+ 5234B6B30E78286000F02D95 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F503CADC025428F601B94B21 /* IOKit.framework */; };
+ 5234B6B40E78286000F02D95 /* libl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F503CADF0254294101B94B21 /* libl.a */; };
+ 5234B6B50E78286000F02D95 /* security_utilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D58C080A87FEA000DC3F19 /* security_utilities.framework */; };
+ 5234B6BF0E78286000F02D95 /* thread_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A50254242101B94B21 /* thread_generic.h */; };
+ 5234B6C00E78286000F02D95 /* pcsclite.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A949E0254242101B94B21 /* pcsclite.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 5234B6C10E78286000F02D95 /* mscdefines.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94CD025424AC01B94B21 /* mscdefines.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 5234B6C20E78286000F02D95 /* musclecard.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94CF025424AC01B94B21 /* musclecard.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 5234B6C30E78286000F02D95 /* winscard_msg.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94A80254242101B94B21 /* winscard_msg.h */; };
+ 5234B6C40E78286000F02D95 /* tokenfactory.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94D1025424AC01B94B21 /* tokenfactory.h */; };
+ 5234B6C50E78286000F02D95 /* winscard.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94AC0254242101B94B21 /* winscard.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 5234B6C60E78286000F02D95 /* dyn_generic.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94940254242101B94B21 /* dyn_generic.h */; };
+ 5234B6C70E78286000F02D95 /* wintypes.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94AD0254242101B94B21 /* wintypes.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 5234B6C80E78286000F02D95 /* debuglog.h in Headers */ = {isa = PBXBuildFile; fileRef = F52A94930254242101B94B21 /* debuglog.h */; settings = {ATTRIBUTES = (); }; };
+ 5234B6C90E78286000F02D95 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = F537A7B30379EB7B01B94948 /* config.h */; };
+ 5234B6CC0E78286000F02D95 /* readerstate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5236DD1C0B9DDBD7007CEF56 /* readerstate.cpp */; };
+ 5234B6CD0E78286000F02D95 /* thread_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A60254242101B94B21 /* thread_macosx.c */; };
+ 5234B6CE0E78286000F02D95 /* musclecard.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94CE025424AC01B94B21 /* musclecard.c */; };
+ 5234B6CF0E78286000F02D95 /* dyn_macosx.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94950254242101B94B21 /* dyn_macosx.c */; };
+ 5234B6D00E78286000F02D95 /* winscard_msg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A70254242101B94B21 /* winscard_msg.cpp */; };
+ 5234B6D10E78286000F02D95 /* tokenfactory.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94D0025424AC01B94B21 /* tokenfactory.c */; };
+ 5234B6D20E78286000F02D95 /* sys_unix.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94A40254242101B94B21 /* sys_unix.c */; };
+ 5234B6D30E78286000F02D95 /* tokenparser.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94D2025424AC01B94B21 /* tokenparser.c */; settings = {COMPILER_FLAGS = "-DYY_NO_UNPUT"; }; };
+ 5234B6D40E78286000F02D95 /* debuglog.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94920254242101B94B21 /* debuglog.c */; };
+ 5234B6D50E78286000F02D95 /* winscard_clnt.c in Sources */ = {isa = PBXBuildFile; fileRef = F52A94D4025424AC01B94B21 /* winscard_clnt.c */; };
+ 5234B6D80E78286000F02D95 /* security_utilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D58C080A87FEA000DC3F19 /* security_utilities.framework */; };
+ 5234B6D90E78286000F02D95 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F503CADB025428F601B94B21 /* CoreFoundation.framework */; };
+ 5234B6E40E78286000F02D95 /* testpcsc.c in Sources */ = {isa = PBXBuildFile; fileRef = F503CACD025425E601B94B21 /* testpcsc.c */; };
+ 5234B6E60E78286000F02D95 /* PCSC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5448E630379F08001B94948 /* PCSC.framework */; };
+ 5234B6F10E78286000F02D95 /* bundleTool.c in Sources */ = {isa = PBXBuildFile; fileRef = F511212C0272F8D9017BB957 /* bundleTool.c */; };
+ 5234B6F30E78286000F02D95 /* PCSC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5448E630379F08001B94948 /* PCSC.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 5234B72E0E78286000F02D95 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = F5294A4F0090C4CA01CD285A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 5234B6BD0E78286000F02D95;
+ remoteInfo = "PCSC (Upgraded)";
+ };
+ 5234B7300E78286000F02D95 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = F5294A4F0090C4CA01CD285A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 5234B67D0E78286000F02D95;
+ remoteInfo = "pcscd (Upgraded)";
+ };
+ 5234B7320E78286000F02D95 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = F5294A4F0090C4CA01CD285A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 5234B6E10E78286000F02D95;
+ remoteInfo = "pcsctest (Upgraded)";
+ };
+ 5234B7340E78286000F02D95 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = F5294A4F0090C4CA01CD285A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 5234B6EE0E78286000F02D95;
+ remoteInfo = "pcsctool (Upgraded)";
+ };
+ 5234B7380E78286000F02D95 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = F5294A4F0090C4CA01CD285A /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 5234B7280E78286000F02D95;
+ remoteInfo = "InstallPhase (Copied)";
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 2CC9AB9A06CC036D0048A811 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
+ 2CC9ABC806CC03A10048A811 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
+ 4CB55A760592598500B25B27 /* Makefile.installPhase */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Makefile.installPhase; sourceTree = "<group>"; };
+ 5234B6BB0E78286000F02D95 /* pcscd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pcscd; sourceTree = BUILT_PRODUCTS_DIR; };
+ 5234B6DF0E78286000F02D95 /* Info-PCSC.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-PCSC.plist"; sourceTree = "<group>"; };
+ 5234B6E00E78286000F02D95 /* PCSC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PCSC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 5234B6EC0E78286000F02D95 /* pcsctest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pcsctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 5234B6F90E78286000F02D95 /* pcsctool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pcsctool; sourceTree = BUILT_PRODUCTS_DIR; };
+ 5236DD1C0B9DDBD7007CEF56 /* readerstate.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = readerstate.cpp; path = src/PCSC/readerstate.cpp; sourceTree = "<group>"; };
+ 5236DD1D0B9DDBD7007CEF56 /* readerstate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = readerstate.h; path = src/PCSC/readerstate.h; sourceTree = "<group>"; };
+ 527CF60A0AA5192B007589FF /* pcscdmonitor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = pcscdmonitor.cpp; path = src/PCSC/pcscdmonitor.cpp; sourceTree = "<group>"; };
+ 527CF60B0AA5192B007589FF /* pcscdmonitor.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pcscdmonitor.h; path = src/PCSC/pcscdmonitor.h; sourceTree = "<group>"; };
+ 527CF60C0AA5192B007589FF /* pcscdserver.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = pcscdserver.cpp; path = src/PCSC/pcscdserver.cpp; sourceTree = "<group>"; };
+ 527CF60D0AA5192B007589FF /* pcscdserver.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pcscdserver.h; path = src/PCSC/pcscdserver.h; sourceTree = "<group>"; };
+ 5286293C0A87EA8E004FE8DC /* hotplug_macosx.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = hotplug_macosx.cpp; path = src/PCSC/hotplug_macosx.cpp; sourceTree = "<group>"; };
+ 5286293D0A87EA8E004FE8DC /* PCSCDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PCSCDevice.cpp; path = src/PCSC/PCSCDevice.cpp; sourceTree = "<group>"; };
+ 5286293E0A87EA8E004FE8DC /* PCSCDevice.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = PCSCDevice.h; path = src/PCSC/PCSCDevice.h; sourceTree = "<group>"; };
+ 5286293F0A87EA8E004FE8DC /* PCSCDriverBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PCSCDriverBundle.cpp; path = src/PCSC/PCSCDriverBundle.cpp; sourceTree = "<group>"; };
+ 528629400A87EA8E004FE8DC /* PCSCDriverBundle.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = PCSCDriverBundle.h; path = src/PCSC/PCSCDriverBundle.h; sourceTree = "<group>"; };
+ 528629410A87EA8E004FE8DC /* PCSCDriverBundles.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = PCSCDriverBundles.cpp; path = src/PCSC/PCSCDriverBundles.cpp; sourceTree = "<group>"; };
+ 528629420A87EA8E004FE8DC /* PCSCDriverBundles.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = PCSCDriverBundles.h; path = src/PCSC/PCSCDriverBundles.h; sourceTree = "<group>"; };
+ 52D00D1A0A9252350093277A /* reader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = reader.h; path = src/PCSC/reader.h; sourceTree = "<group>"; };
+ 52D00D1B0A9252350093277A /* reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = reader.cpp; path = src/PCSC/reader.cpp; sourceTree = "<group>"; };
+ 52D2492C0BA07E1100F9827A /* winscard_msg_srv.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = winscard_msg_srv.c; path = src/PCSC/winscard_msg_srv.c; sourceTree = "<group>"; };
+ 52D58C080A87FEA000DC3F19 /* security_utilities.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = security_utilities.framework; path = /usr/local/SecurityPieces/Frameworks/security_utilities.framework; sourceTree = "<absolute>"; };
+ 52DBCAAE0BB851C8007D06A5 /* PCSC.exp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.exports; name = PCSC.exp; path = src/PCSC/PCSC.exp; sourceTree = "<group>"; };
+ 52E0D59D0BA7006D008DFDDF /* winscard.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = winscard.c; path = src/PCSC/winscard.c; sourceTree = "<group>"; };
+ C2F2094A0662B851001DFD06 /* sys_macosx.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = sys_macosx.cpp; path = src/PCSC/sys_macosx.cpp; sourceTree = "<group>"; };
+ F503CACD025425E601B94B21 /* testpcsc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testpcsc.c; path = src/PCSC/testpcsc.c; sourceTree = "<group>"; };
+ F503CACE025425E601B94B21 /* muscletest.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = muscletest.c; path = src/PCSC/muscletest.c; sourceTree = "<group>"; };
+ F503CADB025428F601B94B21 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = "<absolute>"; };
+ F503CADC025428F601B94B21 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = "<absolute>"; };
+ F503CADF0254294101B94B21 /* libl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libl.a; path = /usr/lib/libl.a; sourceTree = "<absolute>"; };
+ F511212C0272F8D9017BB957 /* bundleTool.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = bundleTool.c; path = src/PCSC/utils/bundleTool.c; sourceTree = "<group>"; };
+ F52A94510254232701B94B21 /* atrhandler.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = atrhandler.c; path = src/PCSC/atrhandler.c; sourceTree = SOURCE_ROOT; };
+ F52A948F0254242101B94B21 /* atrhandler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = atrhandler.h; path = src/PCSC/atrhandler.h; sourceTree = SOURCE_ROOT; };
+ F52A94900254242101B94B21 /* configfile.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = configfile.c; path = src/PCSC/configfile.c; sourceTree = SOURCE_ROOT; };
+ F52A94910254242101B94B21 /* configfile.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = configfile.h; path = src/PCSC/configfile.h; sourceTree = SOURCE_ROOT; };
+ F52A94920254242101B94B21 /* debuglog.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = debuglog.c; path = src/PCSC/debuglog.c; sourceTree = SOURCE_ROOT; };
+ F52A94930254242101B94B21 /* debuglog.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = debuglog.h; path = src/PCSC/debuglog.h; sourceTree = SOURCE_ROOT; };
+ F52A94940254242101B94B21 /* dyn_generic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = dyn_generic.h; path = src/PCSC/dyn_generic.h; sourceTree = SOURCE_ROOT; };
+ F52A94950254242101B94B21 /* dyn_macosx.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = dyn_macosx.c; path = src/PCSC/dyn_macosx.c; sourceTree = SOURCE_ROOT; };
+ F52A94960254242101B94B21 /* eventhandler.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = eventhandler.cpp; path = src/PCSC/eventhandler.cpp; sourceTree = "<group>"; };
+ F52A94970254242101B94B21 /* eventhandler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = eventhandler.h; path = src/PCSC/eventhandler.h; sourceTree = SOURCE_ROOT; };
+ F52A94990254242101B94B21 /* hotplug.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = hotplug.h; path = src/PCSC/hotplug.h; sourceTree = SOURCE_ROOT; };
+ F52A949A0254242101B94B21 /* ifdhandler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ifdhandler.h; path = src/PCSC/ifdhandler.h; sourceTree = SOURCE_ROOT; };
+ F52A949B0254242101B94B21 /* ifdwrapper.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ifdwrapper.c; path = src/PCSC/ifdwrapper.c; sourceTree = SOURCE_ROOT; };
+ F52A949C0254242101B94B21 /* ifdwrapper.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ifdwrapper.h; path = src/PCSC/ifdwrapper.h; sourceTree = SOURCE_ROOT; };
+ F52A949D0254242101B94B21 /* pcscdaemon.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = pcscdaemon.c; path = src/PCSC/pcscdaemon.c; sourceTree = "<group>"; };
+ F52A949E0254242101B94B21 /* pcsclite.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = pcsclite.h; path = src/PCSC/pcsclite.h; sourceTree = SOURCE_ROOT; };
+ F52A949F0254242101B94B21 /* prothandler.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = prothandler.c; path = src/PCSC/prothandler.c; sourceTree = SOURCE_ROOT; };
+ F52A94A00254242101B94B21 /* prothandler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = prothandler.h; path = src/PCSC/prothandler.h; sourceTree = SOURCE_ROOT; };
+ F52A94A10254242101B94B21 /* readerfactory.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = readerfactory.c; path = src/PCSC/readerfactory.c; sourceTree = "<group>"; };
+ F52A94A20254242101B94B21 /* readerfactory.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = readerfactory.h; path = src/PCSC/readerfactory.h; sourceTree = "<group>"; };
+ F52A94A30254242101B94B21 /* sys_generic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = sys_generic.h; path = src/PCSC/sys_generic.h; sourceTree = SOURCE_ROOT; };
+ F52A94A40254242101B94B21 /* sys_unix.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = sys_unix.c; path = src/PCSC/sys_unix.c; sourceTree = SOURCE_ROOT; };
+ F52A94A50254242101B94B21 /* thread_generic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = thread_generic.h; path = src/PCSC/thread_generic.h; sourceTree = SOURCE_ROOT; };
+ F52A94A60254242101B94B21 /* thread_macosx.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = thread_macosx.c; path = src/PCSC/thread_macosx.c; sourceTree = SOURCE_ROOT; };
+ F52A94A70254242101B94B21 /* winscard_msg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = winscard_msg.cpp; path = src/PCSC/winscard_msg.cpp; sourceTree = "<group>"; };
+ F52A94A80254242101B94B21 /* winscard_msg.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = winscard_msg.h; path = src/PCSC/winscard_msg.h; sourceTree = SOURCE_ROOT; };
+ F52A94A90254242101B94B21 /* winscard_svc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = winscard_svc.c; path = src/PCSC/winscard_svc.c; sourceTree = SOURCE_ROOT; };
+ F52A94AA0254242101B94B21 /* winscard_svc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = winscard_svc.h; path = src/PCSC/winscard_svc.h; sourceTree = SOURCE_ROOT; };
+ F52A94AC0254242101B94B21 /* winscard.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = winscard.h; path = src/PCSC/winscard.h; sourceTree = SOURCE_ROOT; };
+ F52A94AD0254242101B94B21 /* wintypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = wintypes.h; path = src/PCSC/wintypes.h; sourceTree = SOURCE_ROOT; };
+ F52A94CD025424AC01B94B21 /* mscdefines.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = mscdefines.h; path = src/PCSC/mscdefines.h; sourceTree = SOURCE_ROOT; };
+ F52A94CE025424AC01B94B21 /* musclecard.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = musclecard.c; path = src/PCSC/musclecard.c; sourceTree = SOURCE_ROOT; };
+ F52A94CF025424AC01B94B21 /* musclecard.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = musclecard.h; path = src/PCSC/musclecard.h; sourceTree = SOURCE_ROOT; };
+ F52A94D0025424AC01B94B21 /* tokenfactory.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = tokenfactory.c; path = src/PCSC/tokenfactory.c; sourceTree = SOURCE_ROOT; };
+ F52A94D1025424AC01B94B21 /* tokenfactory.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = tokenfactory.h; path = src/PCSC/tokenfactory.h; sourceTree = SOURCE_ROOT; };
+ F52A94D2025424AC01B94B21 /* tokenparser.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = tokenparser.c; path = src/PCSC/tokenparser.c; sourceTree = SOURCE_ROOT; };
+ F52A94D4025424AC01B94B21 /* winscard_clnt.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = winscard_clnt.c; path = src/PCSC/winscard_clnt.c; sourceTree = SOURCE_ROOT; };
+ F537A7B30379EB7B01B94948 /* config.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = config.h; path = src/PCSC/config.h; sourceTree = SOURCE_ROOT; };
+ F5448E630379F08001B94948 /* PCSC.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PCSC.framework; path = /System/Library/Frameworks/PCSC.framework; sourceTree = "<absolute>"; };
+ F555DF350274962801D2E99F /* powermgt_macosx.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = powermgt_macosx.c; path = src/PCSC/powermgt_macosx.c; sourceTree = SOURCE_ROOT; };
+ F555DF370274968F01D2E99F /* powermgt_generic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = powermgt_generic.h; path = src/PCSC/powermgt_generic.h; sourceTree = SOURCE_ROOT; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 5234B6B10E78286000F02D95 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6B20E78286000F02D95 /* CoreFoundation.framework in Frameworks */,
+ 5234B6B30E78286000F02D95 /* IOKit.framework in Frameworks */,
+ 5234B6B40E78286000F02D95 /* libl.a in Frameworks */,
+ 5234B6B50E78286000F02D95 /* security_utilities.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6D70E78286000F02D95 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6D80E78286000F02D95 /* security_utilities.framework in Frameworks */,
+ 5234B6D90E78286000F02D95 /* CoreFoundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6E50E78286000F02D95 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6E60E78286000F02D95 /* PCSC.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6F20E78286000F02D95 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6F30E78286000F02D95 /* PCSC.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 5234B4EF0E7826E200F02D95 /* Linked Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 52D58C080A87FEA000DC3F19 /* security_utilities.framework */,
+ F5448E630379F08001B94948 /* PCSC.framework */,
+ 2CC9AB9A06CC036D0048A811 /* CoreFoundation.framework */,
+ 2CC9ABC806CC03A10048A811 /* IOKit.framework */,
+ );
+ name = "Linked Frameworks";
+ sourceTree = "<group>";
+ };
+ 527CF6040AA51879007589FF /* pcscd */ = {
+ isa = PBXGroup;
+ children = (
+ 5236DD1C0B9DDBD7007CEF56 /* readerstate.cpp */,
+ 5236DD1D0B9DDBD7007CEF56 /* readerstate.h */,
+ F52A949D0254242101B94B21 /* pcscdaemon.c */,
+ 527CF60A0AA5192B007589FF /* pcscdmonitor.cpp */,
+ 527CF60B0AA5192B007589FF /* pcscdmonitor.h */,
+ 527CF60C0AA5192B007589FF /* pcscdserver.cpp */,
+ 527CF60D0AA5192B007589FF /* pcscdserver.h */,
+ 5286293C0A87EA8E004FE8DC /* hotplug_macosx.cpp */,
+ 5286293D0A87EA8E004FE8DC /* PCSCDevice.cpp */,
+ 5286293E0A87EA8E004FE8DC /* PCSCDevice.h */,
+ 5286293F0A87EA8E004FE8DC /* PCSCDriverBundle.cpp */,
+ 528629400A87EA8E004FE8DC /* PCSCDriverBundle.h */,
+ 528629410A87EA8E004FE8DC /* PCSCDriverBundles.cpp */,
+ 528629420A87EA8E004FE8DC /* PCSCDriverBundles.h */,
+ F52A94A10254242101B94B21 /* readerfactory.c */,
+ F52A94A20254242101B94B21 /* readerfactory.h */,
+ 52D00D1A0A9252350093277A /* reader.h */,
+ 52D00D1B0A9252350093277A /* reader.cpp */,
+ );
+ name = pcscd;
+ sourceTree = "<group>";
+ };
+ 527CF6070AA51881007589FF /* framework */ = {
+ isa = PBXGroup;
+ children = (
+ 52DBCAAE0BB851C8007D06A5 /* PCSC.exp */,
+ );
+ name = framework;
+ sourceTree = "<group>";
+ };
+ 527CF6240AA51B07007589FF /* tools */ = {
+ isa = PBXGroup;
+ children = (
+ F503CACD025425E601B94B21 /* testpcsc.c */,
+ F503CACE025425E601B94B21 /* muscletest.c */,
+ F511212C0272F8D9017BB957 /* bundleTool.c */,
+ );
+ name = tools;
+ sourceTree = "<group>";
+ };
+ F5294A500090C4CA01CD285A = {
+ isa = PBXGroup;
+ children = (
+ F538896A0397E93B012F6BBF /* InstallPhase */,
+ 527CF6040AA51879007589FF /* pcscd */,
+ 527CF6240AA51B07007589FF /* tools */,
+ F537A7B50379EB8B01B94948 /* PCSC */,
+ 5234B4EF0E7826E200F02D95 /* Linked Frameworks */,
+ F5294A520090C5DF01CD285A /* Products */,
+ 5234B6DF0E78286000F02D95 /* Info-PCSC.plist */,
+ );
+ sourceTree = "<group>";
+ };
+ F5294A520090C5DF01CD285A /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 5234B6BB0E78286000F02D95 /* pcscd */,
+ 5234B6E00E78286000F02D95 /* PCSC.framework */,
+ 5234B6EC0E78286000F02D95 /* pcsctest */,
+ 5234B6F90E78286000F02D95 /* pcsctool */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ F537A7B50379EB8B01B94948 /* PCSC */ = {
+ isa = PBXGroup;
+ children = (
+ 527CF6070AA51881007589FF /* framework */,
+ F52A94510254232701B94B21 /* atrhandler.c */,
+ F52A948F0254242101B94B21 /* atrhandler.h */,
+ F52A94900254242101B94B21 /* configfile.c */,
+ F52A94910254242101B94B21 /* configfile.h */,
+ F52A94920254242101B94B21 /* debuglog.c */,
+ F52A94930254242101B94B21 /* debuglog.h */,
+ F52A94940254242101B94B21 /* dyn_generic.h */,
+ F52A94950254242101B94B21 /* dyn_macosx.c */,
+ F52A94960254242101B94B21 /* eventhandler.cpp */,
+ F52A94970254242101B94B21 /* eventhandler.h */,
+ F52A94990254242101B94B21 /* hotplug.h */,
+ F52A949A0254242101B94B21 /* ifdhandler.h */,
+ F52A949B0254242101B94B21 /* ifdwrapper.c */,
+ F52A949C0254242101B94B21 /* ifdwrapper.h */,
+ F52A949E0254242101B94B21 /* pcsclite.h */,
+ F52A949F0254242101B94B21 /* prothandler.c */,
+ F52A94A00254242101B94B21 /* prothandler.h */,
+ F52A94A30254242101B94B21 /* sys_generic.h */,
+ F52A94A40254242101B94B21 /* sys_unix.c */,
+ C2F2094A0662B851001DFD06 /* sys_macosx.cpp */,
+ F52A94A50254242101B94B21 /* thread_generic.h */,
+ F52A94A60254242101B94B21 /* thread_macosx.c */,
+ 52E0D59D0BA7006D008DFDDF /* winscard.c */,
+ F52A94A70254242101B94B21 /* winscard_msg.cpp */,
+ F52A94A80254242101B94B21 /* winscard_msg.h */,
+ F52A94A90254242101B94B21 /* winscard_svc.c */,
+ 52D2492C0BA07E1100F9827A /* winscard_msg_srv.c */,
+ F52A94AA0254242101B94B21 /* winscard_svc.h */,
+ F52A94CD025424AC01B94B21 /* mscdefines.h */,
+ F52A94AC0254242101B94B21 /* winscard.h */,
+ F52A94CF025424AC01B94B21 /* musclecard.h */,
+ F52A94AD0254242101B94B21 /* wintypes.h */,
+ F52A94CE025424AC01B94B21 /* musclecard.c */,
+ F555DF370274968F01D2E99F /* powermgt_generic.h */,
+ F555DF350274962801D2E99F /* powermgt_macosx.c */,
+ F52A94D0025424AC01B94B21 /* tokenfactory.c */,
+ F52A94D1025424AC01B94B21 /* tokenfactory.h */,
+ F52A94D2025424AC01B94B21 /* tokenparser.c */,
+ F52A94D4025424AC01B94B21 /* winscard_clnt.c */,
+ F537A7B30379EB7B01B94948 /* config.h */,
+ F503CADF0254294101B94B21 /* libl.a */,
+ F503CADC025428F601B94B21 /* IOKit.framework */,
+ F503CADB025428F601B94B21 /* CoreFoundation.framework */,
+ );
+ name = PCSC;
+ sourceTree = "<group>";
+ };
+ F538896A0397E93B012F6BBF /* InstallPhase */ = {
+ isa = PBXGroup;
+ children = (
+ 4CB55A760592598500B25B27 /* Makefile.installPhase */,
+ );
+ name = InstallPhase;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 5234B67E0E78286000F02D95 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B67F0E78286000F02D95 /* atrhandler.h in Headers */,
+ 5234B6800E78286000F02D95 /* configfile.h in Headers */,
+ 5234B6810E78286000F02D95 /* debuglog.h in Headers */,
+ 5234B6820E78286000F02D95 /* dyn_generic.h in Headers */,
+ 5234B6830E78286000F02D95 /* eventhandler.h in Headers */,
+ 5234B6840E78286000F02D95 /* hotplug.h in Headers */,
+ 5234B6850E78286000F02D95 /* ifdhandler.h in Headers */,
+ 5234B6860E78286000F02D95 /* ifdwrapper.h in Headers */,
+ 5234B6870E78286000F02D95 /* pcsclite.h in Headers */,
+ 5234B6880E78286000F02D95 /* prothandler.h in Headers */,
+ 5234B6890E78286000F02D95 /* readerfactory.h in Headers */,
+ 5234B68A0E78286000F02D95 /* sys_generic.h in Headers */,
+ 5234B68B0E78286000F02D95 /* thread_generic.h in Headers */,
+ 5234B68C0E78286000F02D95 /* winscard_msg.h in Headers */,
+ 5234B68D0E78286000F02D95 /* winscard_svc.h in Headers */,
+ 5234B68E0E78286000F02D95 /* winscard.h in Headers */,
+ 5234B68F0E78286000F02D95 /* wintypes.h in Headers */,
+ 5234B6900E78286000F02D95 /* powermgt_generic.h in Headers */,
+ 5234B6910E78286000F02D95 /* PCSCDevice.h in Headers */,
+ 5234B6920E78286000F02D95 /* PCSCDriverBundle.h in Headers */,
+ 5234B6930E78286000F02D95 /* PCSCDriverBundles.h in Headers */,
+ 5234B6940E78286000F02D95 /* reader.h in Headers */,
+ 5234B6950E78286000F02D95 /* pcscdmonitor.h in Headers */,
+ 5234B6960E78286000F02D95 /* pcscdserver.h in Headers */,
+ 5234B6970E78286000F02D95 /* readerstate.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6BE0E78286000F02D95 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6BF0E78286000F02D95 /* thread_generic.h in Headers */,
+ 5234B6C00E78286000F02D95 /* pcsclite.h in Headers */,
+ 5234B6C10E78286000F02D95 /* mscdefines.h in Headers */,
+ 5234B6C20E78286000F02D95 /* musclecard.h in Headers */,
+ 5234B6C30E78286000F02D95 /* winscard_msg.h in Headers */,
+ 5234B6C40E78286000F02D95 /* tokenfactory.h in Headers */,
+ 5234B6C50E78286000F02D95 /* winscard.h in Headers */,
+ 5234B6C60E78286000F02D95 /* dyn_generic.h in Headers */,
+ 5234B6C70E78286000F02D95 /* wintypes.h in Headers */,
+ 5234B6C80E78286000F02D95 /* debuglog.h in Headers */,
+ 5234B6C90E78286000F02D95 /* config.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6E20E78286000F02D95 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6EF0E78286000F02D95 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+ 5234B7280E78286000F02D95 /* InstallPhase */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "-f Makefile.installPhase $ALL_SETTINGS $ACTION";
+ buildConfigurationList = 5234B7290E78286000F02D95 /* Build configuration list for PBXLegacyTarget "InstallPhase" */;
+ buildPhases = (
+ );
+ buildToolPath = /usr/bin/gnumake;
+ buildWorkingDirectory = "";
+ dependencies = (
+ );
+ name = InstallPhase;
+ passBuildSettingsInEnvironment = 1;
+ productName = InstallPhase;
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 5234B67D0E78286000F02D95 /* pcscd */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 5234B6B60E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcscd" */;
+ buildPhases = (
+ 5234B67E0E78286000F02D95 /* Headers */,
+ 5234B6980E78286000F02D95 /* Sources */,
+ 5234B6B10E78286000F02D95 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = pcscd;
+ productInstallPath = /usr/sbin;
+ productName = pcscd;
+ productReference = 5234B6BB0E78286000F02D95 /* pcscd */;
+ productType = "com.apple.product-type.tool";
+ };
+ 5234B6BD0E78286000F02D95 /* PCSC */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 5234B6DA0E78286000F02D95 /* Build configuration list for PBXNativeTarget "PCSC" */;
+ buildPhases = (
+ 5234B6BE0E78286000F02D95 /* Headers */,
+ 5234B6CA0E78286000F02D95 /* Resources */,
+ 5234B6CB0E78286000F02D95 /* Sources */,
+ 5234B6D70E78286000F02D95 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = PCSC;
+ productInstallPath = /System/Library/Frameworks;
+ productName = PCSC;
+ productReference = 5234B6E00E78286000F02D95 /* PCSC.framework */;
+ productType = "com.apple.product-type.framework";
+ };
+ 5234B6E10E78286000F02D95 /* pcsctest */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 5234B6E70E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcsctest" */;
+ buildPhases = (
+ 5234B6E20E78286000F02D95 /* Headers */,
+ 5234B6E30E78286000F02D95 /* Sources */,
+ 5234B6E50E78286000F02D95 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = pcsctest;
+ productInstallPath = /usr/bin;
+ productName = testpcsc;
+ productReference = 5234B6EC0E78286000F02D95 /* pcsctest */;
+ productType = "com.apple.product-type.tool";
+ };
+ 5234B6EE0E78286000F02D95 /* pcsctool */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 5234B6F40E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcsctool" */;
+ buildPhases = (
+ 5234B6EF0E78286000F02D95 /* Headers */,
+ 5234B6F00E78286000F02D95 /* Sources */,
+ 5234B6F20E78286000F02D95 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = pcsctool;
+ productInstallPath = /usr/bin/;
+ productName = pcsctool;
+ productReference = 5234B6F90E78286000F02D95 /* pcsctool */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ F5294A4F0090C4CA01CD285A /* Project object */ = {
+ isa = PBXProject;
+ buildConfigurationList = C27AD1FD0987FCDC001272E0 /* Build configuration list for PBXProject "SmartCardServices" */;
+ compatibilityVersion = "Xcode 2.4";
+ hasScannedForEncodings = 1;
+ mainGroup = F5294A500090C4CA01CD285A;
+ productRefGroup = F5294A520090C5DF01CD285A /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 5234B66B0E78286000F02D95 /* World */,
+ 5234B67D0E78286000F02D95 /* pcscd */,
+ 5234B6BD0E78286000F02D95 /* PCSC */,
+ 5234B6E10E78286000F02D95 /* pcsctest */,
+ 5234B6EE0E78286000F02D95 /* pcsctool */,
+ 5234B7280E78286000F02D95 /* InstallPhase */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 5234B6CA0E78286000F02D95 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 5234B6980E78286000F02D95 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6990E78286000F02D95 /* atrhandler.c in Sources */,
+ 5234B69A0E78286000F02D95 /* readerstate.cpp in Sources */,
+ 5234B69B0E78286000F02D95 /* configfile.c in Sources */,
+ 5234B69C0E78286000F02D95 /* debuglog.c in Sources */,
+ 5234B69D0E78286000F02D95 /* dyn_macosx.c in Sources */,
+ 5234B69E0E78286000F02D95 /* eventhandler.cpp in Sources */,
+ 5234B69F0E78286000F02D95 /* ifdwrapper.c in Sources */,
+ 5234B6A00E78286000F02D95 /* pcscdaemon.c in Sources */,
+ 5234B6A10E78286000F02D95 /* prothandler.c in Sources */,
+ 5234B6A20E78286000F02D95 /* readerfactory.c in Sources */,
+ 5234B6A30E78286000F02D95 /* thread_macosx.c in Sources */,
+ 5234B6A40E78286000F02D95 /* winscard_msg.cpp in Sources */,
+ 5234B6A50E78286000F02D95 /* winscard_svc.c in Sources */,
+ 5234B6A60E78286000F02D95 /* powermgt_macosx.c in Sources */,
+ 5234B6A70E78286000F02D95 /* sys_macosx.cpp in Sources */,
+ 5234B6A80E78286000F02D95 /* hotplug_macosx.cpp in Sources */,
+ 5234B6A90E78286000F02D95 /* PCSCDevice.cpp in Sources */,
+ 5234B6AA0E78286000F02D95 /* PCSCDriverBundle.cpp in Sources */,
+ 5234B6AB0E78286000F02D95 /* PCSCDriverBundles.cpp in Sources */,
+ 5234B6AC0E78286000F02D95 /* reader.cpp in Sources */,
+ 5234B6AD0E78286000F02D95 /* pcscdmonitor.cpp in Sources */,
+ 5234B6AE0E78286000F02D95 /* pcscdserver.cpp in Sources */,
+ 5234B6AF0E78286000F02D95 /* winscard_msg_srv.c in Sources */,
+ 5234B6B00E78286000F02D95 /* winscard.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6CB0E78286000F02D95 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6CC0E78286000F02D95 /* readerstate.cpp in Sources */,
+ 5234B6CD0E78286000F02D95 /* thread_macosx.c in Sources */,
+ 5234B6CE0E78286000F02D95 /* musclecard.c in Sources */,
+ 5234B6CF0E78286000F02D95 /* dyn_macosx.c in Sources */,
+ 5234B6D00E78286000F02D95 /* winscard_msg.cpp in Sources */,
+ 5234B6D10E78286000F02D95 /* tokenfactory.c in Sources */,
+ 5234B6D20E78286000F02D95 /* sys_unix.c in Sources */,
+ 5234B6D30E78286000F02D95 /* tokenparser.c in Sources */,
+ 5234B6D40E78286000F02D95 /* debuglog.c in Sources */,
+ 5234B6D50E78286000F02D95 /* winscard_clnt.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6E30E78286000F02D95 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6E40E78286000F02D95 /* testpcsc.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 5234B6F00E78286000F02D95 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 5234B6F10E78286000F02D95 /* bundleTool.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 5234B72F0E78286000F02D95 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 5234B6BD0E78286000F02D95 /* PCSC */;
+ targetProxy = 5234B72E0E78286000F02D95 /* PBXContainerItemProxy */;
+ };
+ 5234B7310E78286000F02D95 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 5234B67D0E78286000F02D95 /* pcscd */;
+ targetProxy = 5234B7300E78286000F02D95 /* PBXContainerItemProxy */;
+ };
+ 5234B7330E78286000F02D95 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 5234B6E10E78286000F02D95 /* pcsctest */;
+ targetProxy = 5234B7320E78286000F02D95 /* PBXContainerItemProxy */;
+ };
+ 5234B7350E78286000F02D95 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 5234B6EE0E78286000F02D95 /* pcsctool */;
+ targetProxy = 5234B7340E78286000F02D95 /* PBXContainerItemProxy */;
+ };
+ 5234B7390E78286000F02D95 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 5234B7280E78286000F02D95 /* InstallPhase */;
+ targetProxy = 5234B7380E78286000F02D95 /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+ 5234B6790E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = debug;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = World;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B67A0E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = World;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B67B0E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = normal;
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PREBINDING = NO;
+ PRODUCT_NAME = World;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = "normal with debug";
+ };
+ 5234B67C0E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = World;
+ SECTORDER_FLAGS = "";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = Default;
+ };
+ 5234B6B70E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(NATIVE_ARCH)";
+ BUILD_VARIANTS = debug;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = (
+ "${BUILT_PRODUCTS_DIR}",
+ /usr/local/SecurityPieces/Components/Security,
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ HEADER_SEARCH_PATHS = (
+ /System/Library/Frameworks/CoreFoundation.framework/Headers,
+ /System/Library/Frameworks/IOKit.framework/Headers/usb,
+ /System/Library/Frameworks/IOKit.framework/Headers,
+ );
+ INSTALL_PATH = /usr/sbin;
+ ONLY_ACTIVE_ARCH = NO;
+ OPT_CPPXFLAGS = "$(OPT_CXFLAGS)";
+ OPT_CXFLAGS = "-DNDEBUG $(OPT_INLINEXFLAGS)";
+ OPT_INLINEXFLAGS = "-finline-functions";
+ OPT_LDXFLAGS = "-dead_strip";
+ OPT_LDXNOPIC = ",_nopic";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CXFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CXFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CPLUSPLUSFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS) -framework Security,_debug -framework securityd_client,_debug -framework security_cdsa_client,_debug -framework security_cdsa_utilities,_debug -framework security_utilities,_debug";
+ OTHER_LDFLAGS_normal = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -framework Security -framework securityd_client$(OPT_LDXNOPIC) -framework security_cdsa_client$(OPT_LDXNOPIC) -framework security_cdsa_utilities$(OPT_LDXNOPIC) -framework security_utilities$(OPT_LDXNOPIC)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -pg -framework Security,_profile -framework securityd_client,_profile -framework security_cdsa_client,_profile -framework security_cdsa_utilities,_profile -framework security_utilities,_profile";
+ PRODUCT_NAME = pcscd;
+ SECTORDER_FLAGS = "";
+ VALID_ARCHS = "i386 ppc ppc64 ppc7400 ppc970 x86_64";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B6B80E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(NATIVE_ARCH)";
+ BUILD_VARIANTS = (
+ normal,
+ debug,
+ );
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = (
+ "${BUILT_PRODUCTS_DIR}",
+ /usr/local/SecurityPieces/Components/Security,
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ HEADER_SEARCH_PATHS = (
+ /System/Library/Frameworks/CoreFoundation.framework/Headers,
+ /System/Library/Frameworks/IOKit.framework/Headers/usb,
+ /System/Library/Frameworks/IOKit.framework/Headers,
+ );
+ INSTALL_PATH = /usr/sbin;
+ ONLY_ACTIVE_ARCH = NO;
+ OPT_CPPXFLAGS = "$(OPT_CXFLAGS)";
+ OPT_CXFLAGS = "-DNDEBUG $(OPT_INLINEXFLAGS)";
+ OPT_INLINEXFLAGS = "-finline-functions";
+ OPT_LDXFLAGS = "-dead_strip";
+ OPT_LDXNOPIC = ",_nopic";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CXFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CXFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CPLUSPLUSFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS) -framework Security,_debug -framework securityd_client,_debug -framework security_cdsa_client,_debug -framework security_cdsa_utilities,_debug -framework security_utilities,_debug";
+ OTHER_LDFLAGS_normal = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -framework Security -framework securityd_client$(OPT_LDXNOPIC) -framework security_cdsa_client$(OPT_LDXNOPIC) -framework security_cdsa_utilities$(OPT_LDXNOPIC) -framework security_utilities$(OPT_LDXNOPIC)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -pg -framework Security,_profile -framework securityd_client,_profile -framework security_cdsa_client,_profile -framework security_cdsa_utilities,_profile -framework security_utilities,_profile";
+ PRODUCT_NAME = pcscd;
+ SECTORDER_FLAGS = "";
+ VALID_ARCHS = "i386 ppc ppc64 ppc7400 ppc970 x86_64";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B6B90E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(NATIVE_ARCH)";
+ BUILD_VARIANTS = normal;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = (
+ "${BUILT_PRODUCTS_DIR}",
+ /usr/local/SecurityPieces/Components/Security,
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ HEADER_SEARCH_PATHS = (
+ /System/Library/Frameworks/CoreFoundation.framework/Headers,
+ /System/Library/Frameworks/IOKit.framework/Headers/usb,
+ /System/Library/Frameworks/IOKit.framework/Headers,
+ );
+ INSTALL_PATH = /usr/sbin;
+ ONLY_ACTIVE_ARCH = NO;
+ OPT_CPPXFLAGS = "$(OPT_CXFLAGS)";
+ OPT_CXFLAGS = "-DNDEBUG $(OPT_INLINEXFLAGS)";
+ OPT_INLINEXFLAGS = "-finline-functions";
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CFLAGS_profile = "$(OPT_CXFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CPLUSPLUSFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS) -framework Security,_debug -framework securityd_client,_debug -framework security_cdsa_client,_debug -framework security_cdsa_utilities,_debug -framework security_utilities,_debug";
+ OTHER_LDFLAGS_normal = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -framework Security -framework securityd_client$(OPT_LDXNOPIC) -framework security_cdsa_client$(OPT_LDXNOPIC) -framework security_cdsa_utilities$(OPT_LDXNOPIC) -framework security_utilities$(OPT_LDXNOPIC)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -pg -framework Security,_profile -framework securityd_client,_profile -framework security_cdsa_client,_profile -framework security_cdsa_utilities,_profile -framework security_utilities,_profile";
+ PREBINDING = NO;
+ PRODUCT_NAME = pcscd;
+ SECTORDER_FLAGS = "";
+ VALID_ARCHS = "i386 ppc ppc64 ppc7400 ppc970 x86_64";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = "normal with debug";
+ };
+ 5234B6BA0E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ARCHS = "$(NATIVE_ARCH)";
+ BUILD_VARIANTS = (
+ normal,
+ debug,
+ );
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = (
+ "${BUILT_PRODUCTS_DIR}",
+ /usr/local/SecurityPieces/Components/Security,
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ HEADER_SEARCH_PATHS = (
+ /System/Library/Frameworks/CoreFoundation.framework/Headers,
+ /System/Library/Frameworks/IOKit.framework/Headers/usb,
+ /System/Library/Frameworks/IOKit.framework/Headers,
+ );
+ INSTALL_PATH = /usr/sbin;
+ ONLY_ACTIVE_ARCH = NO;
+ OPT_CPPXFLAGS = "$(OPT_CXFLAGS)";
+ OPT_CXFLAGS = "-DNDEBUG $(OPT_INLINEXFLAGS)";
+ OPT_INLINEXFLAGS = "-finline-functions";
+ OPT_LDXFLAGS = "-dead_strip";
+ OPT_LDXNOPIC = ",_nopic";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CXFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CXFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CPLUSPLUSFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPXFLAGS) $(OTHER_CPLUSPLUSFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS) -framework Security,_debug -framework securityd_client,_debug -framework security_cdsa_client,_debug -framework security_cdsa_utilities,_debug -framework security_utilities,_debug";
+ OTHER_LDFLAGS_normal = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -framework Security -framework securityd_client$(OPT_LDXNOPIC) -framework security_cdsa_client$(OPT_LDXNOPIC) -framework security_cdsa_utilities$(OPT_LDXNOPIC) -framework security_utilities$(OPT_LDXNOPIC)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDXFLAGS) $(OTHER_LDFLAGS) -pg -framework Security,_profile -framework securityd_client,_profile -framework security_cdsa_client,_profile -framework security_cdsa_utilities,_profile -framework security_utilities,_profile";
+ PRODUCT_NAME = pcscd;
+ SECTORDER_FLAGS = "";
+ VALID_ARCHS = "i386 ppc ppc64 ppc7400 ppc970 x86_64";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = Default;
+ };
+ 5234B6DB0E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = debug;
+ CURRENT_PROJECT_VERSION = 36160;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 36160;
+ EXPORTED_SYMBOLS_FILE = "$(SRCROOT)/src/PCSC/PCSC.exp";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ FRAMEWORK_VERSION = A;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ INFOPLIST_FILE = "Info-PCSC.plist";
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Frameworks";
+ OPT_CFLAGS = "-DNDEBUG $(OPT_INLINEFLAGS)";
+ OPT_CPPFLAGS = "$(OPT_CFLAGS)";
+ OPT_INLINEFLAGS = "-finline-functions";
+ OPT_LDFLAGS = "-dead_strip";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_normal = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS) -pg";
+ PRODUCT_NAME = PCSC;
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = framework;
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B6DC0E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = (
+ normal,
+ debug,
+ );
+ CURRENT_PROJECT_VERSION = 36160;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 36160;
+ EXPORTED_SYMBOLS_FILE = "$(SRCROOT)/src/PCSC/PCSC.exp";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ FRAMEWORK_VERSION = A;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ INFOPLIST_FILE = "Info-PCSC.plist";
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Frameworks";
+ OPT_CFLAGS = "-DNDEBUG $(OPT_INLINEFLAGS)";
+ OPT_CPPFLAGS = "$(OPT_CFLAGS)";
+ OPT_INLINEFLAGS = "-finline-functions";
+ OPT_LDFLAGS = "-dead_strip";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_normal = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS) -pg";
+ PRODUCT_NAME = PCSC;
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = framework;
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B6DD0E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = normal;
+ CURRENT_PROJECT_VERSION = 36160;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 36160;
+ EXPORTED_SYMBOLS_FILE = "$(SRCROOT)/src/PCSC/PCSC.exp";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ FRAMEWORK_VERSION = A;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ INFOPLIST_FILE = "Info-PCSC.plist";
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Frameworks";
+ OPT_CFLAGS = "-DNDEBUG $(OPT_INLINEFLAGS)";
+ OPT_CPPFLAGS = "$(OPT_CFLAGS)";
+ OPT_INLINEFLAGS = "-finline-functions";
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CFLAGS_profile = "$(OPT_CFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_normal = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS) -pg";
+ PREBINDING = NO;
+ PRODUCT_NAME = PCSC;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = framework;
+ };
+ name = "normal with debug";
+ };
+ 5234B6DE0E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = (
+ normal,
+ debug,
+ );
+ CURRENT_PROJECT_VERSION = 36160;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 36160;
+ EXPORTED_SYMBOLS_FILE = "$(SRCROOT)/src/PCSC/PCSC.exp";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ /usr/local/SecurityPieces/Frameworks,
+ );
+ FRAMEWORK_VERSION = A;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "PCSC_DEBUG=1",
+ "USE_SYSLOG=1",
+ "USE_DAEMON=1",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ INFOPLIST_FILE = "Info-PCSC.plist";
+ INSTALL_PATH = "$(SYSTEM_LIBRARY_DIR)/Frameworks";
+ OPT_CFLAGS = "-DNDEBUG $(OPT_INLINEFLAGS)";
+ OPT_CPPFLAGS = "$(OPT_CFLAGS)";
+ OPT_INLINEFLAGS = "-finline-functions";
+ OPT_LDFLAGS = "-dead_strip";
+ OTHER_ASFLAGS_debug = "$(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_normal = "-DNDEBUG $(OTHER_CFLAGS)";
+ OTHER_ASFLAGS_profile = "-DNDEBUG $(OTHER_CFLAGS) -pg";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CFLAGS_normal = "$(OPT_CFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CFLAGS_profile = "$(OPT_CFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_CPLUSPLUSFLAGS_debug = "$(OTHER_CFLAGS) -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS)";
+ OTHER_CPLUSPLUSFLAGS_profile = "$(OPT_CPPFLAGS) $(OTHER_CFLAGS) -pg";
+ OTHER_LDFLAGS_debug = "$(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_normal = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS)";
+ OTHER_LDFLAGS_profile = "$(OPT_LDFLAGS) $(OTHER_LDFLAGS) -pg";
+ PRODUCT_NAME = PCSC;
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ WRAPPER_EXTENSION = framework;
+ };
+ name = Default;
+ };
+ 5234B6E80E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = debug;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctest;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B6E90E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctest;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B6EA0E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = normal;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PREBINDING = NO;
+ PRODUCT_NAME = pcsctest;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = "normal with debug";
+ };
+ 5234B6EB0E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctest;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = Default;
+ };
+ 5234B6F50E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = debug;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctool;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B6F60E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctool;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B6F70E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = normal;
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_CFLAGS = "";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PREBINDING = NO;
+ PRODUCT_NAME = pcsctool;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = "normal with debug";
+ };
+ 5234B6F80E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CURRENT_PROJECT_VERSION = 36160;
+ FRAMEWORK_SEARCH_PATHS = "";
+ INSTALL_PATH = /usr/bin;
+ OTHER_CFLAGS = "";
+ OTHER_LDFLAGS = "";
+ OTHER_REZFLAGS = "";
+ PRODUCT_NAME = pcsctool;
+ REZ_EXECUTABLE = YES;
+ SECTORDER_FLAGS = "";
+ VERSIONING_SYSTEM = "apple-generic";
+ WARNING_CFLAGS = (
+ "-Wmost",
+ "-Wno-four-char-constants",
+ "-Wno-unknown-pragmas",
+ );
+ };
+ name = Default;
+ };
+ 5234B72A0E78286000F02D95 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = debug;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ PRODUCT_NAME = InstallPhase;
+ ZERO_LINK = YES;
+ };
+ name = Development;
+ };
+ 5234B72B0E78286000F02D95 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ PRODUCT_NAME = InstallPhase;
+ ZERO_LINK = NO;
+ };
+ name = Deployment;
+ };
+ 5234B72C0E78286000F02D95 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ BUILD_VARIANTS = normal;
+ OPT_LDFLAGS = "";
+ OPT_LDXFLAGS = "";
+ OPT_LDXNOPIC = "";
+ OTHER_ASFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG";
+ OTHER_CFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ OTHER_CPLUSPLUSFLAGS_normal = "$(OTHER_CFLAGS) -UNDEBUG -fno-inline";
+ PREBINDING = NO;
+ PRODUCT_NAME = InstallPhase;
+ SECTORDER_FLAGS = "";
+ };
+ name = "normal with debug";
+ };
+ 5234B72D0E78286000F02D95 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ PRODUCT_NAME = InstallPhase;
+ };
+ name = Default;
+ };
+ C27AD1FE0987FCDC001272E0 /* Development */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ CONFIGURATION_TEMP_DIR = "$(PROJECT_TEMP_DIR)";
+ };
+ name = Development;
+ };
+ C27AD1FF0987FCDC001272E0 /* Deployment */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ CONFIGURATION_TEMP_DIR = "$(PROJECT_TEMP_DIR)";
+ };
+ name = Deployment;
+ };
+ C27AD2000987FCDC001272E0 /* normal with debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ CONFIGURATION_TEMP_DIR = "$(PROJECT_TEMP_DIR)";
+ };
+ name = "normal with debug";
+ };
+ C27AD2010987FCDC001272E0 /* Default */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)";
+ CONFIGURATION_TEMP_DIR = "$(PROJECT_TEMP_DIR)";
+ };
+ name = Default;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 5234B6780E78286000F02D95 /* Build configuration list for PBXAggregateTarget "World" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B6790E78286000F02D95 /* Development */,
+ 5234B67A0E78286000F02D95 /* Deployment */,
+ 5234B67B0E78286000F02D95 /* normal with debug */,
+ 5234B67C0E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 5234B6B60E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcscd" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B6B70E78286000F02D95 /* Development */,
+ 5234B6B80E78286000F02D95 /* Deployment */,
+ 5234B6B90E78286000F02D95 /* normal with debug */,
+ 5234B6BA0E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 5234B6DA0E78286000F02D95 /* Build configuration list for PBXNativeTarget "PCSC" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B6DB0E78286000F02D95 /* Development */,
+ 5234B6DC0E78286000F02D95 /* Deployment */,
+ 5234B6DD0E78286000F02D95 /* normal with debug */,
+ 5234B6DE0E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 5234B6E70E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcsctest" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B6E80E78286000F02D95 /* Development */,
+ 5234B6E90E78286000F02D95 /* Deployment */,
+ 5234B6EA0E78286000F02D95 /* normal with debug */,
+ 5234B6EB0E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 5234B6F40E78286000F02D95 /* Build configuration list for PBXNativeTarget "pcsctool" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B6F50E78286000F02D95 /* Development */,
+ 5234B6F60E78286000F02D95 /* Deployment */,
+ 5234B6F70E78286000F02D95 /* normal with debug */,
+ 5234B6F80E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ 5234B7290E78286000F02D95 /* Build configuration list for PBXLegacyTarget "InstallPhase" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 5234B72A0E78286000F02D95 /* Development */,
+ 5234B72B0E78286000F02D95 /* Deployment */,
+ 5234B72C0E78286000F02D95 /* normal with debug */,
+ 5234B72D0E78286000F02D95 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+ C27AD1FD0987FCDC001272E0 /* Build configuration list for PBXProject "SmartCardServices" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C27AD1FE0987FCDC001272E0 /* Development */,
+ C27AD1FF0987FCDC001272E0 /* Deployment */,
+ C27AD2000987FCDC001272E0 /* normal with debug */,
+ C27AD2010987FCDC001272E0 /* Default */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Default;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = F5294A4F0090C4CA01CD285A /* Project object */;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/Info.plist
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/Info.plist (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/Info.plist 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>ifd-ASEIIIeUSB</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.athena.AseIIIeUSB</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>CFPlugInDynamicRegisterFunction</key>
+ <string></string>
+ <key>CFPlugInDynamicRegistration</key>
+ <string>NO</string>
+ <key>CFPlugInFactories</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <string>MyFactoryFunction</string>
+ </dict>
+ <key>CFPlugInTypes</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <array>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </array>
+ </dict>
+ <key>CFPlugInUnloadFunction</key>
+ <string></string>
+ <key>NSPrincipalClass</key>
+ <string>0x60000</string>
+ <key>ifdCapabilities</key>
+ <string>0x00000000</string>
+ <key>ifdFriendlyName</key>
+ <string>AseIIIeUSB</string>
+ <key>ifdManufacturerString</key>
+ <string>Athena</string>
+ <key>ifdManufacturerURL</key>
+ <string>http://www.athena-scs.com/</string>
+ <key>ifdMaxSpeed</key>
+ <string>153600</string>
+ <key>ifdProductID</key>
+ <string>0x0802</string>
+ <key>ifdProductString</key>
+ <string>AseIIIeUSB</string>
+ <key>ifdProtocolSupport</key>
+ <string>0x00000001</string>
+ <key>ifdReadTimeOut</key>
+ <string>60000</string>
+ <key>ifdVendorID</key>
+ <string>0x0DC3</string>
+ <key>ifdVersionNumber</key>
+ <string>0x00000001</string>
+</dict>
+</plist>
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/MacOS/ifd-ASEIIIeUSB
===================================================================
(Binary files differ)
Property changes on: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/drivers/ifd-ASEIIIeUSB.bundle/Contents/MacOS/ifd-ASEIIIeUSB
___________________________________________________________________
Added: svn:executable
+
Added: svn:mime-type
+ application/octet-stream
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcscd.8
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcscd.8 (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcscd.8 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,149 @@
+.\" Process this file with
+.\" groff -man -Tascii pcscd.txt
+.\"
+.TH PCSCD 8 "March 2002" Linux "User Manual"
+.SH NAME
+pcscd \- PC/SC Smartcard Daemon
+.SH SYNOPSIS
+.BI "pcscd [" options "]"
+.SH OPTIONS
+.TP
+\fB\-a\fR, \fB\-\-apdu\fR
+log APDUs and SW using the debug method (see \fB\-d\fR)
+.TP
+\fB\-c\fR, \fB\-\-config\fR \fIfile\fR
+Specifies the file \fIfile\fR as an alternate location for
+\fIreader.conf\fR
+.TP
+\fB\-d\fR, \fB\-\-debug\fR \fIOUTPUT\fR
+display debug messages.
+
+\fIOUTPUT\fR may be:
+ \fBstdout\fR (imply \fB\-f\fR),
+ \fBstderr\fR (imply \fB\-f\fR),
+ or \fBsyslog\fR
+.TP
+\fB\-f\fR, \fB\-\-foreground\fR
+Runs pcscd in the foreground (no daemon)
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Displays information about the pcscd command line
+.TP
+\fB\-v\fR, \fB\-\-version\fR
+Displays the program version number
+.SH DESCRIPTION
+pcscd is the daemon program for pcsc-lite and musclecard framework. It is
+a resource manager that coordinates communications with smart-card readers
+and smart cards and cryptographic tokens that are connected to the system.
+
+pcscd is normally started at boot time from
+.IR /System/Library/StartupItems/SmartCardServices .
+It allows applications to access smart cards and readers without knowing
+details of the card or reader.
+
+pcscd coordinates the loading of drivers for card readers and plug-ins
+for different card types.
+
+The purpose of pcsc-lite is to provide both a cross compatible API for
+migrating Windows based PCSC applications to Unix and to provide a
+pluggable architecture for supporting smartcards and cryptographic tokens
+through high level API's.
+
+At startup, pcscd loads the smart card reader drivers specified in the
+.I /etc/reader.conf
+file (or specified using \fB-c\fR \fIfile\fR).
+
+When a smart card is inserted into a reader, pcscd uses the ATR string from
+the card to identify this card. The
+.I /usr/libexec/SmartCardServices/services
+directory contains plug-ins for the card. These plug-ins are searched. If
+the ATR string matches, the client library loads that plug-in for that
+token.
+
+.SH "USB SMART CARD READER DRIVERS"
+USB Smart card reader drivers are placed in the
+.I /usr/libexec/SmartCardServices/drivers
+directory. Each driver is simply a
+bundle. The bundle contains an XML file Info.plist
+which is parsed by pcscd. This file contains the vendor
+and product id of the device. This information allows
+pcscd to automatically determine when a reader is inserted
+or removed.
+
+.SH "SERIAL SMART CARD READER DRIVERS"
+Serial Smart card reader drivers are placed in the
+.I /usr/libexec/SmartCardServices/drivers
+directory. Each driver is simply a
+.I shared object
+file. The pcscd locates serial drivers with the
+.I /etc/reader.conf
+file. The file has the following format:
+
+ # comment
+ FRIENDLYNAME <Descriptive name>
+ DEVICENAME <Short name>
+ LIBPATH <Location of the driver library>
+ CHANNELID <Hexadecimal channel identificator>
+
+.IP FRIENDLYNAME
+is a user-friendly name of the reader that is served by this driver.
+This name is displayed to the user when necessary.
+
+.IP DEVICENAME
+is a driver specific value. If you do not know this value,
+GEN_SMART_RDR is a good choice.
+
+.IP LIBPATH
+is the full path to the shared library.
+
+.IP CHANNELID
+is the channel ID for serial-port, smart-card readers. This could vary
+depending on the driver in which you are using - check the driver README
+for more information. Some use the following:
+
+ \fI/dev/ttyS0\fR (COM1) -> 0x0103F8 or 1
+ \fI/dev/ttyS1\fR (COM2) -> 0x0102F8 or 2
+ \fI/dev/ttyS2\fR (COM3) -> 0x0103E8 or 3
+ \fI/dev/ttyS3\fR (COM4) -> 0x0102E8 or 4
+.PP
+Example:
+
+ # Configuration file for pcsc-lite
+
+ FRIENDLYNAME "My Smartcard Reader"
+ DEVICENAME GEN_SMART_RDR
+ LIBPATH /usr/libexec/SmartCardServices/drivers/my_reader.so
+ CHANNELID 0x0103F8
+
+ # End of file
+
+Multiple drivers can be listed in
+.I /etc/reader.conf.
+
+Drivers are available at \fIhttp://www.musclecard.com/drivers.html\fR.
+.SH "SMART CARD PLUG-INS"
+pcsc-lite uses plug-ins to handle different types of smart cards. There is
+a plug-in for each smart-card type. Plug-ins are installed in the
+.I /usr/libexec/SmartCardServices/services
+directory. Plug-ins for cards/tokens are available from the MUSCLE
+web site \fIhttp://www.musclecard.com\fR.
+.SH FILES
+.I /etc/reader.conf
+: Reader configuration file
+.br
+.I /System/Library/StartupItems/SmartCardServices
+: pcscd startup script
+.br
+.I /var/run/pcscd.pid
+: process id of the running pcscd
+.br
+.I /usr/libexec/SmartCardServices/drivers/
+: directory containing bundles for USB
+drivers"
+.SH BUGS
+None known.
+.SH "SEE ALSO"
+.BR pcsctool (1),
+.SH AUTHORS
+David Corcoran <corcoran at identityalliance.com> and Ludovic Rousseau
+<ludovic.rousseau at free.fr>
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctest.8
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctest.8 (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctest.8 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,57 @@
+.\" Process this file with
+.\" groff -man -Tascii pcsctool.8
+.\"
+.TH PCSCTEST 8 "March 2003" MacOSX "User Manual"
+.SH NAME
+pcsctest
+.SH SYNOPSIS
+.B pcsctest
+.SH DESCRPTION
+pcsctest runs a test on pcscd, lists the readers currently connected, and
+displays card information if a card is inserted.
+.SH OPTIONS
+None
+.SH USAGE
+pcsctest lists the currently connected readers and asks the user
+to choose one. After choosing the reader, pcsctest will ask the
+user to insert a card into the card reader. If this happens pcsctest
+will display the cards's ATR and other information.
+
+Example:
+
+The following will occur if no reader is inserted and recognized:
+
+MUSCLE PC/SC Lite Test Program
+
+ Testing SCardEstablishContext : Command successful.
+ Testing SCardGetStatusChange
+
+Once a reader is inserted and recognized the following will occur:
+
+ MUSCLE PC/SC Lite Test Program
+
+ Testing SCardEstablishContext : Command successful.
+ Testing SCardGetStatusChange
+ Please insert a working reader : Command successful.
+ Testing SCardListReaders : Command successful.
+ Reader 01: SCM SCR-331 CCID 0 0
+ Enter the reader number : 1
+
+ Waiting for card insertion
+ : Command successful.
+ Testing SCardConnect : Command successful.
+ Testing SCardStatus : Command successful.
+ Current Reader Name : CCID USB Reader 0 0
+ Current Reader State : 34
+ Current Reader Protocol : 0
+ Current Reader ATR Size : 9
+ Current Reader ATR Value : 3B E2 00 00 04 03 00
+ Testing SCardDisconnect : Command successful.
+ Testing SCardReleaseContext : Command successful.
+
+ PC/SC Test Completed Successfully !
+
+
+.SH SEE ALSO
+.BR pcscd (8)
+.SH BUGS
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctool.8
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctool.8 (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/pcsctool.8 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,37 @@
+.\" Process this file with
+.\" groff -man -Tascii pcsctool.8
+.\"
+.TH PCSCTOOL 8 "March 2002" Linux "User Manual"
+.SH NAME
+pcsctool
+.SH SYNOPSIS
+.B pcsctool
+.SH DESCRPTION
+pcsctool introduces new smart cards to pcsc-lite and assigns a
+plugin to service the card.
+.SH OPTIONS
+None
+.SH USAGE
+pcsctool lists the currently installed bundles and asks you to
+select one. You select the plugin bundle that services your
+smartcard. pcsctool will then ask you to insert the new card. The
+application exits and pcsc is now configured to use your card.
+
+Example:
+
+ [root at osx]# pcsctool
+ Select the approprate token driver:
+ -----------------------------------
+ 1. mscMuscleCard.bundle
+ -----------------------------------
+ Enter the number: 1
+
+ Insert your token in: My Friendly Reader 0 0
+
+ Token support updated successfully !
+ [root at osx]#
+.SH SEE ALSO
+.BR pcscd (8)
+.SH BUGS
+Plugins MUST reside in
+.I /usr/libexec/SmartCardServices/services
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/sc_auth.8
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/sc_auth.8 (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/man/sc_auth.8 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,91 @@
+.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
+.\"See Also:
+.\"man mdoc.samples for a complete listing of options
+.\"man mdoc for the short list of editing options
+.\"/usr/share/misc/mdoc.template
+.Dd December 11, 2006 \" DATE
+.Dt sc_auth 8 \" Program name and manual section number
+.Os MacOSX
+.Sh NAME \" Section Header - required - don't modify
+.Nm sc_auth
+.\" The following lines are read in generating the apropos(man -k) database. Use only key
+.\" words here as the database is built based on the words here and in the .ND line.
+.\" Use .Nm macro to designate other names for the documented program.
+.Nd smart card authorization setup script
+.Sh SYNOPSIS \" Section Header - required - don't modify
+.Nm
+.Ar accept
+.Op Fl v
+.Op Fl u Ar user
+.Op Fl d Ar domain
+.Op Fl k Ar keyname
+.Nm
+.Ar accept
+.Op Fl v
+.Op Fl u Ar user
+.Op Fl d Ar domain
+.Fl h Ar hash
+.Nm
+.Ar remove
+.Op Fl v
+.Op Fl u Ar user
+.Op Fl d Ar domain
+.Nm
+.Ar hash " "
+.Op Fl k Ar keyname
+.Nm
+.Ar list " "
+.Op Fl v
+.Op Fl u Ar user
+.Op Fl d Ar domain
+.Sh DESCRIPTION \" Section Header - required - don't modify
+.Nm
+configures a local user account to permit authentication using a supported
+smart card. Authentication is via asymmetric key (also known as
+public-key) encryption.
+.Nm
+works with signing keys, but not encryption keys.
+.Pp
+.Nm
+can perform the following actions:
+.Bl -tag -width -indent \" Begins a tagged list
+.It Ar accept
+Associate a user with a public key on a card. The key to use can be
+specified either by its name or its hash.
+.It Ar remove
+Remove all public keys associated with a user.
+.It Ar hash
+Print the hashes for all keys on all inserted cards.
+.It Ar list
+List all public keys associated with a user.
+.El \" Ends the list
+.Pp
+.Sh OPTIONS
+.Bl -tag -width -indent \" Differs from above in tag removed
+.It Fl u Ar user
+Specifies the user whose account is to be modified
+.It Fl d Ar domain
+Specifies the directory domain containing the user account
+.It Fl k Ar keyname
+Specifies a public key by its name
+.It Fl h Ar hash
+Specifies a public key by its hash
+.It Fl v
+Verbose mode
+.El \" Ends the list
+.Sh NOTES
+.Nm
+is a shell script. It is intended to be modified by administrators to
+suit their local environments.
+.Pp
+.Nm
+is only known to work with a local directory. Consult the script's source
+for some limited guidance to using remote directories.
+.Sh BUGS
+.Nm
+.Ar hash
+might display the hashes of encryption keys as well as signing keys, even
+though
+.Nm
+.Ar accept
+does not work with encryption keys.
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/sc_auth
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/sc_auth (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/sc_auth 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,148 @@
+#!/bin/bash
+#
+# sc_auth - smart card authorization setup script
+#
+# You can log in with a smart card if the authentication_authority field
+# of your user record contains an entry of the form
+# ;pubkeyhash;THEHASH
+# where THEHASH is the hex encoding of the SHA1 of the public key to be used.
+# (In keychains, this is the value in the Label attribute of keys, and of
+# the PublicKeyHash # attribute of certificate records.)
+#
+# This script allows you to get the hash from a smartcard, and to create
+# the appropriate authority entry in a user account. It also lets you list
+# and delete them. It works as is for (local) NetInfo directories. If you
+# use LDAP or more exotic directory sources, you'll have to find your own
+# way to store the authentication_authority information, but the workflow
+# is the same. Feel free to hack.
+#
+# This script assumes the Tiger version of the /usr/bin/security command.
+# It will probably not work (without modification) with future versions.
+#
+# This script has been updated to use the dscl command in place of the
+# deprecated nicl command. To use the standard name in the header file:
+# /System/Library/Frameworks/DirectoryService.framework/Headers/DirServicesConst.h
+# we have replaced "authentication_authority" with "AuthenticationAuthority"
+
+#set -x
+
+# general functions
+die() { echo "$*" 1>&2; exit 1; }
+note() { [ $verbose = yes ] && echo "$*" 1>&2; }
+
+usage() {
+cat <<EOU
+Usage: $(basename $0) accept [-v] [-u user] [-d domain] [-k keyname] # by key on inserted card(s)
+ $(basename $0) accept [-v] [-u user] [-d domain] -h hash # by known pubkey hash
+ $(basename $0) remove [-v] [-u user] [-d domain] # remove all public keys for this user
+ $(basename $0) hash [-k keyname] # print hashes for keys on inserted card(s)
+ $(basename $0) list [-v] [-u user] [-d domain] # list pubkey hashes that can authenticate this user
+EOU
+exit 2
+}
+
+# first argument is a command word
+[ -n "$1" ] || usage
+command=$1; shift
+
+# parse options
+user=${USER:-$(logname)}
+keyname=
+hash=
+verbose=no
+domain="."
+while getopts d:h:k:u:v arg; do
+ case $arg in
+ d) domain="$OPTARG";;
+ h) hash="$OPTARG";;
+ k) keyname="$OPTARG";;
+ u) user="$OPTARG";;
+ v) verbose=yes;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+
+#
+# Using "security dump-keychain", extract the public key hash for a key
+# on a smartcard and print it to stdout.
+# The optional argument is a regular expression to match against the
+# print name of the key.
+# Prints all matching keys; aborts if none are found.
+#
+hash_for_key() {
+ # hash_for_key [string in name]
+ string=${1:-'.*'}
+ HOME=/no/where /usr/bin/security dump-keychain |
+ awk -v RE="$string" '
+ /^ 0x00000001/ {
+ if (matched = ($2 ~ RE)) { name=$0; sub("^.*<blob>=\"", "", name); sub("\"$", "", name); count++; }}
+ /^ 0x00000006/ {
+ if (matched) { hash=$2; sub("<blob>=0x", "", hash); print hash, name; }}
+ '
+ HOME=/no/where /usr/bin/security dump-keychain |
+ awk -v RE="$string" '
+ /^ 0x01000000/ {
+ if (matched = ($2 ~ RE)) { name=$0; sub("^.*<blob>=\"", "", name); sub("\"$", "", name); count++; }}
+ /^ 0x06000000/ {
+ if (matched) { hash=$2; sub("<blob>=0x", "", hash); print hash, name; }}
+ '
+}
+
+
+get_hash() {
+ if [ -n "$hash" ]; then # passed in
+ echo "$hash"
+ else # find it
+ hash_for_key "$keyname" |
+ (
+ read hash rest
+ [ -n "$hash" ] || die "No matching keys found"
+ [ $verbose = yes ] && note "Using key \"$rest\""
+ echo $hash
+ )
+ fi
+}
+
+
+accept_user() {
+ local hash="$1"
+ [ -n "$hash" ] || die "No hash specified"
+ dscl "$domain" -append "/Users/$user" AuthenticationAuthority ";pubkeyhash;$hash"
+}
+
+remove_user() {
+ set -- $(dscl "$domain" -read "/Users/$user" AuthenticationAuthority)
+ shift # skip authentication_authority: header
+ while [ -n "$1" ]; do
+ case "$1" in
+ \;pubkeyhash\;*)
+ dscl "$domain" -delete "/Users/$user" AuthenticationAuthority "$1"
+ [ $verbose = yes ] && note "Removed $1"
+ ;;
+ esac
+ shift
+ done
+}
+
+list_hashes() {
+ set -- $(dscl "$domain" -read "/Users/$user" AuthenticationAuthority)
+ shift # skip authentication_authority: header
+ while [ -n "$1" ]; do
+ case "$1" in
+ \;pubkeyhash\;*)
+ echo $1 | sed -e 's/;pubkeyhash;//'
+ ;;
+ esac
+ shift
+ done
+}
+
+
+case "$command" in
+ hash) hash_for_key "$keyname";;
+ accept) accept_user $(get_hash);;
+ remove) remove_user;;
+ list) list_hashes;;
+ *) usage;;
+esac
Property changes on: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/installPhase/scripts/sc_auth
___________________________________________________________________
Added: svn:executable
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/config.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/config.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/config.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,36 @@
+/* config.h.in. Generated automatically from configure.in by autoheader. */
+
+/* Define if you have the daemon function. */
+#define HAVE_DAEMON 1
+
+/* Name of package */
+#define PACKAGE "PCSC Framework"
+
+/* Version number of package */
+#define VERSION "1.1.1"
+
+/* OSX */
+#define PCSC_TARGET_OSX 1
+#define MSC_TARGET_OSX 1
+
+/* Define if you have POSIX threads libraries and header files. */
+#define HAVE_PTHREAD 1
+
+/* enable full PCSC debug messaging. */
+ #define PCSC_DEBUG 1
+
+/* enable full musclecard debug messaging. */
+ #define MSC_DEBUG 1
+
+/* display ATR parsing debug messages. */
+/* #define ATR_DEBUG */
+
+/* send messages to syslog instead of stdout */
+/* #define USE_SYSLOG */
+
+/* pcsc runs as a daemon in the background. */
+#define USE_DAEMON 1
+
+/* enable client side thread safety. */
+#define USE_THREAD_SAFETY 1
+
Property changes on: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/pbx/config.h
___________________________________________________________________
Added: svn:executable
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSC.exp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSC.exp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSC.exp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,71 @@
+_DebugLogSetLevel
+_DebugLogSetLogType
+_MSCBeginTransaction
+_MSCCancelEventWait
+_MSCChangePIN
+_MSCClearReset
+_MSCComputeCrypt
+_MSCCreateObject
+_MSCCreatePIN
+_MSCDeleteObject
+_MSCEndTransaction
+_MSCEstablishConnection
+_MSCExportKey
+_MSCExtAuthenticate
+_MSCExtendedFeature
+_MSCGenerateKeys
+_MSCGetCapabilities
+_MSCGetChallenge
+_MSCGetKeyAttributes
+_MSCGetObjectAttributes
+_MSCGetStatus
+_MSCImportKey
+_MSCIsTokenChanged
+_MSCIsTokenKnown
+_MSCIsTokenMoved
+_MSCIsTokenReset
+_MSCListKeys
+_MSCListObjects
+_MSCListPINs
+_MSCListTokens
+_MSCLogoutAll
+_MSCReEstablishConnection
+_MSCReadAllocateObject
+_MSCReadObject
+_MSCReleaseConnection
+_MSCUnblockPIN
+_MSCVerifyPIN
+_MSCWaitForTokenEvent
+_MSCWriteFramework
+_MSCWriteObject
+_PCSCVersionNumber
+_PCSCVersionString
+_SCardBeginTransaction
+_SCardCancel
+_SCardCancelTransaction
+_SCardConnect
+_SCardControl
+_SCardControl132
+_SCardDisconnect
+_SCardEndTransaction
+_SCardEstablishContext
+_SCardGetAttrib
+_SCardGetStatusChange
+_SCardIsValidContext
+_SCardListReaderGroups
+_SCardListReaders
+_SCardReconnect
+_SCardReleaseContext
+_SCardSetAttrib
+_SCardSetTimeout
+_SCardStatus
+_SCardTransmit
+_SCardUnload
+_TPSvcDropdir
+_mscLockThread
+_mscUnLockThread
+_msc_error
+_pcsc_stringify_error
+_g_rgSCardT0Pci
+_g_rgSCardT1Pci
+_g_rgSCardRawPci
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * PCSCDevice.cpp
+ * SmartCardServices
+ *
+ */
+
+#include "PCSCDevice.h"
+#include <security_utilities/debugging.h>
+#include <IOKit/IOCFPlugIn.h>
+#include <IOKit/IOKitLib.h>
+#include <IOKit/usb/IOUSBLib.h>
+
+namespace PCSCD {
+
+Device::~Device() throw()
+{
+}
+
+void Device::dump()
+{
+ //, serial: %s", // always empty for known readers, mSerialNumber.c_str());
+ secdebug("device", " Service: 0x%04X, Address: 0x%08X, vendor/product: 0x%04X/0x%04X, vendor/product: %s/%s",
+ ioObject(), mAddress, mVendorid, mProductid, mVendorName.c_str(), mProductName.c_str());
+ secdebug("device", " path: %s", path().c_str());
+}
+
+/*
+Device::Device(const Device& x) throw() // copy constructor
+{
+ *this = x;
+}
+
+Device& Device::operator= (const Device& x) throw() // assignment operator
+{
+ mAddress = x.mAddress;
+ mName = x.mName;
+ mLibPath = x.mLibPath;
+ return *this;
+}
+*/
+
+} // end namespace PCSCD
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDevice.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * PCSCDevice.h
+ * SmartCardServices
+ *
+ */
+
+#ifndef _H_PCSCDEVICE
+#define _H_PCSCDEVICE
+
+#include <security_utilities/iodevices.h>
+#include <security_utilities/refcount.h>
+
+#if defined(__cplusplus)
+
+namespace PCSCD {
+
+class Device : public IOKit::Device, public RefCount
+{
+public:
+// Device() : { }
+ Device(io_service_t d) : IOKit::Device(d) { }
+
+ virtual ~Device() throw();
+
+ bool operator < (const Device &other) const { return this->address() < other.address(); }
+
+ void setAddress(uint32_t address) { mAddress = address; }
+ void setInterfaceClass(uint32_t interfaceClass) { mInterfaceClass = interfaceClass; }
+ void setDeviceClass(uint32_t deviceClass) { mDeviceClass = deviceClass; }
+ void setVendorid(uint32_t vendorid) { mVendorid = vendorid; }
+ void setProductid(uint32_t productid) { mProductid = productid; }
+ void setPath(const std::string path) { mLibPath = path; }
+ void setName(const std::string name) { mName = name; }
+ void setIsPCCard(bool isPCCard) { mIsPCCard = isPCCard; }
+
+ uint32_t address() const { return mAddress; }
+ uint32_t interfaceClass() const { return mInterfaceClass; }
+ uint32_t deviceClass() const { return mDeviceClass; }
+ uint32_t vendorid() const { return mVendorid; }
+ uint32_t productid() const { return mProductid; }
+ std::string path() const { return mLibPath; }
+ std::string name() const { return mName; }
+ bool isPCCard() const { return mIsPCCard; }
+
+ std::string vendorName() const { return mVendorName; }
+ std::string productName() const { return mProductName; }
+ std::string serialNumber() const { return mSerialNumber; }
+
+ void setDebugParams(const std::string vendorName, const std::string productName,
+ const std::string serialNumber)
+ { mVendorName = vendorName; mProductName = productName; mSerialNumber = serialNumber;}
+
+ void dump();
+
+private:
+
+ uint32_t mAddress;
+
+ std::string mName; // Manufacturer's name for device
+ std::string mLibPath; // path to driver bundle from PCSCDriverBundle
+
+ uint32_t mInterfaceClass; // If present, one of kUSBChipSmartCardInterfaceClass/kUSBVendorSpecificInterfaceClass
+ uint32_t mDeviceClass; // If == kUSBVendorSpecificClass, check vendor/product
+ uint32_t mVendorid;
+ uint32_t mProductid;
+
+ bool mIsPCCard;
+
+ // Mainly for debugging
+ std::string mVendorName, mProductName, mSerialNumber;
+};
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif // _H_PCSCDEVICE
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * PCSCDriverBundle.cpp
+ * SmartCardServices
+ */
+
+/*
+ A driver bundle is a standard Mac OS X bundle that usually lives in the directory:
+
+ /usr/libexec/SmartCardServices/drivers/
+
+ The two major components of this bundle are the executable and the Info.plist. A single
+ driver bundle may provide support for multiple readers. See
+
+ <rdar://problem/4432039> pcscd crash for multiple VID/PIDs
+ and
+ <http://pcsclite.alioth.debian.org/ifdhandler-3/node7.html>
+
+ The key that determines if a driver supports only one reader or multiple readers is
+ "ifdVendorID", sometimes referred to as the manufacturer name. If this is a
+ CFStringRef, then only one reader is supported; if it is a CFArrayRef, then
+ multiple readers are supports. There are three fields for each reader:
+
+ VendorID uint32_t
+ ProductID uint32_t
+ Friendly name string
+
+ See e.g. http://pcsclite.alioth.debian.org/ccid.html for a working driver with multiple IDs.
+
+*/
+
+#include "PCSCDriverBundle.h"
+#include <CoreFoundation/CoreFoundation.h>
+#include <security_utilities/cfutilities.h>
+#include <security_utilities/debugging.h>
+#include <security_utilities/errors.h>
+#include <IOKit/usb/USBSpec.h>
+#include <IOKit/usb/USB.h>
+
+#define DEBUG_BUNDLE_MATCHES 1
+
+namespace PCSCD {
+
+// Keys in CFDictionary for bundle's Info.plist
+static const CFStringRef kManufacturerName = CFSTR("ifdVendorID");
+static const CFStringRef kProductName = CFSTR("ifdProductID");
+static const CFStringRef kFriendlyName = CFSTR("ifdFriendlyName");
+static const CFStringRef kInterfaceClass = CFSTR("ifdInterfaceClass");
+static const CFStringRef kInterfaceSubClass = CFSTR("ifdInterfaceSubClass");
+static const CFStringRef kInterfaceProtocol = CFSTR("ifdInterfaceProtocol");
+
+DriverBundle::DriverBundle(CFBundleRef bundle) : LoadableBundle(bundle)
+{
+ initialize(CFBundleGetInfoDictionary(bundle));
+}
+
+void DriverBundle::initialize(CFDictionaryRef dict)
+{
+ const int radix = 16;
+
+ try
+ {
+ CFTypeRef vend = CFDictionaryGetValue(dict, kManufacturerName);
+ if (!vend)
+ {
+ // Must be a class driver
+ secdebug("pcscd", "Class Driver: %s", path().c_str());
+ std::string istr(getStringAttr(dict,kInterfaceClass));
+ uint8_t dclass = strtoul(istr.c_str(), NULL, radix);
+ std::string sstr(getStringAttr(dict,kInterfaceSubClass));
+ uint8_t dsubclass = strtoul(sstr.c_str(), NULL, radix);
+ std::string pstr(getStringAttr(dict,kInterfaceProtocol));
+ uint8_t dprotocol = strtoul(pstr.c_str(), NULL, radix);
+ std::string name(getStringAttr(dict,kFriendlyName));
+ DeviceDescription *dev = new DeviceDescription(dclass, dsubclass, dprotocol, name);
+ addProduct(dev);
+ }
+ else
+ if (CFGetTypeID(vend) == CFArrayGetTypeID())
+ {
+ secdebug("pcscd", "Driver with aliases: %s", path().c_str());
+ CFTypeRef xprod = CFDictionaryGetValue(dict, kProductName);
+ CFTypeRef xname = CFDictionaryGetValue(dict, kFriendlyName);
+ if (!xprod || !xname ||
+ (CFGetTypeID(xprod) != CFArrayGetTypeID()) || (CFGetTypeID(xname) != CFArrayGetTypeID()))
+ CFError::throwMe();
+ CFRef<CFArrayRef> products(reinterpret_cast<CFArrayRef>(xprod));
+ CFRef<CFArrayRef> names (reinterpret_cast<CFArrayRef>(xname));
+ const int productCount = CFArrayGetCount(reinterpret_cast<CFArrayRef>(vend));
+ // Make sure parallel arrays vendor, product, name are same size
+ if ((productCount != CFArrayGetCount(products)) ||
+ (productCount != CFArrayGetCount(names)))
+ CFError::throwMe();
+
+ for (int ix=0;ix<productCount;++ix)
+ {
+ std::string vstr(getStringAttr(reinterpret_cast<CFArrayRef>(vend), ix));
+ uint16_t vendor = strtoul(vstr.c_str(), NULL, radix);
+ std::string pstr(getStringAttr(products, ix));
+ uint16_t product = strtoul(pstr.c_str(), NULL, radix);
+ std::string name(getStringAttr(names, ix));
+ DeviceDescription *dev = new DeviceDescription(vendor, product, name);
+ addProduct(dev);
+ }
+ }
+ else
+ if (CFGetTypeID(vend) == CFStringGetTypeID())
+ {
+ secdebug("pcscd", "Driver for single product: %s", path().c_str());
+ std::string vstr(cfString(reinterpret_cast<CFStringRef>(vend)));
+ uint16_t vendor = strtoul(vstr.c_str(), NULL, radix);
+ std::string pstr(getStringAttr(dict,kProductName));
+ uint16_t product = strtoul(pstr.c_str(), NULL, radix);
+ std::string name(getStringAttr(dict,kFriendlyName));
+ DeviceDescription *dev = new DeviceDescription(vendor, product, name);
+ addProduct(dev);
+ }
+ else
+ CFError::throwMe();
+ }
+ catch (...)
+ {
+ secdebug("pcscd", "Malformed Info.plist for: %s", path().c_str());
+ secdebug("pcscd", "error getting plugin directory bundles");
+ return;
+ }
+
+ dump();
+}
+
+std::string DriverBundle::getStringAttr(CFDictionaryRef dict, CFStringRef key)
+{
+ // Do some sanity checking on potential string values in the plist
+ CFTypeRef attr = CFDictionaryGetValue(dict, key);
+ if (!attr)
+ return std::string();
+ if (CFGetTypeID(attr) != CFStringGetTypeID())
+ CFError::throwMe();
+
+ return std::string(cfString(static_cast<CFStringRef>(attr)));
+}
+
+std::string DriverBundle::getStringAttr(CFArrayRef arr, CFIndex idx)
+{
+ // Do some sanity checking on potential string values in the plist
+ CFTypeRef attr = CFArrayGetValueAtIndex(arr, idx);
+ if (!attr)
+ return std::string();
+ if (CFGetTypeID(attr) != CFStringGetTypeID())
+ CFError::throwMe();
+
+ return std::string(cfString(static_cast<CFStringRef>(attr)));
+}
+
+DriverBundle::~DriverBundle() throw()
+{
+ // delete supported devices objects
+}
+
+uint32_t DriverBundle::matches(const PCSCD::Device &device, std::string &name) const
+{
+ // Searches for a driver bundle that matches device. If found,
+ // it sets the libpath for the device and returns true.
+
+#ifdef DEBUG_BUNDLE_MATCHES
+ secdebug("device", " DEVICE: vendor/product: 0x%04X/0x%04X, interfaceClass: 0x%04X, vendor/product: %s/%s",
+ device.vendorid(), device.productid(), device.interfaceClass(),
+ device.vendorName().c_str(), device.productName().c_str());
+#endif
+
+ // Look for a manufacturer-specific driver first
+ for (ConstDeviceDescriptionIterator it=mDeviceDescriptions.begin();it!=mDeviceDescriptions.end();++it)
+ {
+ const DeviceDescription *desc = static_cast<DeviceDescription *>(*it);
+#ifdef DEBUG_BUNDLE_MATCHES
+ secdebug("device", " DESC: vendor/product: 0x%04X/0x%04X, interfaceClass: 0x%04X, path: %s",
+ desc->vendorid(), desc->productid(), desc->interfaceClass(), path().c_str());
+#endif
+ if (desc->vendorid() && (desc->vendorid()==device.vendorid()) &&
+ desc->productid() && (desc->productid()==device.productid()))
+ {
+ name = desc->name();
+ return eMatchVendorSpecific;
+ }
+ }
+
+ if (device.interfaceClass())
+ for (ConstDeviceDescriptionIterator it=mDeviceDescriptions.begin();it!=mDeviceDescriptions.end();++it)
+ {
+ const DeviceDescription *desc = static_cast<DeviceDescription *>(*it);
+ if (desc->interfaceClass() && (desc->interfaceClass()==device.interfaceClass()))
+ {
+ name = desc->name();
+ return eMatchInterfaceClass;
+ }
+ }
+
+ return eMatchNone;
+}
+
+#pragma mark -------------------- Operators --------------------
+
+bool DriverBundle::operator < (const DriverBundle &other) const throw()
+{
+ return this->path() < other.path();
+}
+
+bool DeviceDescription::operator < (const DeviceDescription &other) const throw()
+{
+ if (this->mVendor >= other.mVendor)
+ return false;
+
+ return (this->mProduct < other.mProduct);
+}
+
+#pragma mark -------------------- Debugging Routines --------------------
+
+void DriverBundle::dump()
+{
+#ifndef NDEBUG
+ secdebug("pcscd", "Driver at path: %s", path().c_str());
+ for (DeviceDescriptionIterator it = mDeviceDescriptions.begin(); it != mDeviceDescriptions.end();++it)
+ (*it)->dump();
+#endif
+}
+
+void DeviceDescription::dump()
+{
+#ifndef NDEBUG
+ secdebug("pcscd", " Friendly name: %s", mFriendlyName.c_str());
+ if (interfaceClass())
+ secdebug("pcscd", " Class: 0x%02X SubClass: 0x%02X Protocol: 0x%02X",
+ mDeviceClass,mDeviceSubClass,mDeviceProtocol);
+ else
+ secdebug("pcscd", " VendorID: 0x%04X ProductID: 0x%04X", mVendor, mProduct);
+#endif
+}
+
+} // end namespace PCSCD
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundle.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * PCSCDriverBundle.h
+ * SmartCardServices
+ */
+
+#ifndef _H_XPCSCDRIVERBUNDLE
+#define _H_XPCSCDRIVERBUNDLE
+
+#include <string>
+#include <vector>
+#include <security_utilities/refcount.h>
+#include <security_utilities/osxcode.h>
+#include "PCSCDevice.h"
+
+#if defined(__cplusplus)
+
+namespace PCSCD {
+
+class DeviceDescription
+{
+public:
+
+ DeviceDescription() { }
+ DeviceDescription(uint16_t vendor, uint16_t product, std::string name) :
+ mVendor(vendor), mProduct(product),
+ mDeviceClass(0), mDeviceSubClass(0), mDeviceProtocol(0),
+ mFriendlyName(name) {}
+ DeviceDescription(uint8_t deviceClass, uint8_t deviceSubClass, uint8_t protocol, std::string name) :
+ mVendor(0), mProduct(0),
+ mDeviceClass(deviceClass), mDeviceSubClass(deviceSubClass), mDeviceProtocol(protocol),
+ mFriendlyName(name) {}
+
+ bool operator < (const DeviceDescription &other) const throw();
+
+ uint8_t interfaceClass() const { return mDeviceClass; }
+ uint16_t vendorid() const { return mVendor; }
+ uint16_t productid() const { return mProduct; }
+ std::string name() const { return mFriendlyName; }
+
+ void dump();
+
+protected:
+ // Match types from <IOKit/USB.h> for IOUSBDeviceDescriptor
+
+ uint16_t mVendor; // Unique vendor's manufacturer code assigned by the USB-IF
+ uint16_t mProduct; // Manufacturer's unique product code
+
+ uint8_t mDeviceClass;
+ uint8_t mDeviceSubClass;
+ uint8_t mDeviceProtocol;
+
+ std::string mFriendlyName; // Manufacturer's name for device
+};
+
+/*
+ * An aggregation of useful information on a driver bundle in the
+ * drop directory.
+ */
+
+class DriverBundle : public LoadableBundle
+{
+private:
+ DriverBundle(const char *pathname) : LoadableBundle(pathname) { }
+
+public:
+ DriverBundle(CFBundleRef bundle);
+
+ virtual ~DriverBundle() throw();
+
+ bool operator < (const DriverBundle &other) const throw();
+
+ void addProduct(DeviceDescription *dev) { mDeviceDescriptions.push_back(dev); }
+
+ uint32_t matches(const Device &device, std::string &name) const;
+
+ enum
+ {
+ eMatchNone = 0,
+ eMatchInterfaceClass, // must be less than eMatchVendorSpecific
+ eMatchVendorSpecific
+ };
+
+protected:
+ void initialize(CFDictionaryRef dict);
+
+private:
+
+ typedef std::vector<DeviceDescription *> DeviceDescriptions;
+ typedef DeviceDescriptions::iterator DeviceDescriptionIterator;
+ typedef DeviceDescriptions::const_iterator ConstDeviceDescriptionIterator;
+ DeviceDescriptions mDeviceDescriptions;
+
+ std::string getStringAttr(CFDictionaryRef dict, CFStringRef key);
+ std::string getStringAttr(CFArrayRef arr, CFIndex idx);
+ void dump();
+};
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif /* _H_XPCSCDRIVERBUNDLE */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/*
+ * PCSCDriverBundles.cpp
+ * SmartCardServices
+ */
+
+/*
+ Creates a vector of driver bundle info structures from the hot-plug driver
+ directory.
+
+ Returns NULL on error and a pointer to an allocated HPDriver vector on
+ success. The caller must free the HPDriver with a call to HPDriversRelease().
+
+ See http://developer.apple.com/documentation/CoreFoundation/Reference/CFArrayRef/index.html#//apple_ref/doc/uid/20001192
+ for information about CFArrayApplyFunction
+*/
+
+#include "PCSCDriverBundles.h"
+#include <security_utilities/debugging.h>
+#include <security_utilities/cfutilities.h>
+#include <security_utilities/errors.h>
+#include <map>
+
+namespace PCSCD {
+
+static const char *kPCSCLITE_HP_DROPDIR = "/usr/libexec/SmartCardServices/drivers/";
+static const char *kENV_PCSC_DEBUG_DRIVER = "PCSC_DEBUG_DRIVER_DIR"; // environment var
+
+DriverBundles::DriverBundles()
+{
+ // If debugging, look in build directory
+#if !defined(NDEBUG)
+ const char *envar = kENV_PCSC_DEBUG_DRIVER;
+ if (envar)
+ if (const char *envPath = getenv(envar))
+ {
+ // treat envPath as a classic colon-separated list of directories
+ secdebug("pathlist", "%p configuring from env(\"%s\")", this, envar);
+ while (const char *p = strchr(envPath, ':'))
+ {
+ addDirectory(string(envPath, p - envPath));
+ envPath = p + 1;
+ }
+ addDirectory(envPath);
+ }
+#endif
+ addDirectory(kPCSCLITE_HP_DROPDIR);
+}
+
+bool DriverBundles::find(PCSCD::Device &device) const
+{
+ // Searches for a driver bundle that matches device. If found,
+ // it sets the libpath for the device and returns true.
+
+ ProductMatchMap matchingProducts;
+
+ for (DriverBundles::const_iterator it=this->begin();it!=this->end();++it)
+ {
+ std::string name;
+ const DriverBundle *bndl = static_cast<DriverBundle *>((*it).get());
+ if (int32_t score = bndl->matches(device, name))
+ {
+ ProductMatchInfo *mi = new ProductMatchInfo(bndl->path(),name);
+ matchingProducts.push_back(make_pair(score, mi));
+ }
+ }
+
+ if (matchingProducts.empty())
+ return false;
+
+ sort(matchingProducts.begin(), matchingProducts.end());
+ const ProductMatchInfo *mi = (*matchingProducts.rbegin()).second;
+ device.setName(mi->name());
+ device.setPath(mi->path());
+ // clean up
+ for (ProductMatchMap::iterator it = matchingProducts.begin();it!=matchingProducts.end();++it)
+ delete (*it).second;
+ return true;
+}
+
+} // end namespace PCSCD
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/PCSCDriverBundles.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * PCSCDriverBundles.h
+ * SmartCardServices
+ */
+
+#ifndef _H_XPCSCDRIVERBUNDLES
+#define _H_XPCSCDRIVERBUNDLES
+
+#include "PCSCDriverBundle.h"
+#include "PCSCDevice.h"
+#include <security_utilities/threading.h>
+#include <security_utilities/coderepository.h>
+#include <security_utilities/osxcode.h>
+#include <set>
+
+#if defined(__cplusplus)
+
+namespace PCSCD {
+
+class DriverBundles : public CodeRepository<DriverBundle>
+{
+ friend class DriverBundle;
+
+public:
+ DriverBundles();
+ ~DriverBundles() {}
+
+ bool find(Device &device) const;
+
+ // These are the things we need to know about which part of
+ // bundle we are matched up with
+
+ class ProductMatchInfo
+ {
+ public:
+ ProductMatchInfo(std::string path, std::string name) : mPath(path), mName(name) {}
+
+ std::string path() const { return mPath; }
+ std::string name() const { return mName; }
+
+ private:
+ std::string mPath;
+ std::string mName;
+ };
+
+ typedef std::vector< pair<int32_t, ProductMatchInfo * > > ProductMatchMap;
+};
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif /* _H_XPCSCDRIVERBUNDLE */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : atrhandler.c
+ Author : David Corcoran
+ Date : 7/27/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This keeps track of smartcard protocols,
+ timing issues, and atr handling.
+
+********************************************************************/
+
+#include <syslog.h>
+#include <string.h>
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "atrhandler.h"
+
+/*
+ * Uncomment the following for ATR debugging
+ */
+/*
+ * #define ATR_DEBUG 1
+ */
+
+short ATRDecodeAtr(PSMARTCARD_EXTENSION psExtension,
+ const unsigned char *pucAtr, DWORD dwLength)
+{
+
+ USHORT p;
+ UCHAR K, TCK; /* MSN of T0/Check Sum */
+ UCHAR Y1i, T; /* MSN/LSN of TDi */
+ short TAi, TBi, TCi, TDi; /* Interface characters */
+
+ /*
+ * Zero out everything
+ */
+ p = K = TCK = Y1i = T = TAi = TBi = TCi = TDi = 0;
+
+ if (dwLength < 2)
+ {
+ return 0; /* Atr must have TS and T0 */
+ }
+
+ /*
+ * Zero out the bitmasks
+ */
+
+ psExtension->CardCapabilities.AvailableProtocols = 0x00;
+ psExtension->CardCapabilities.CurrentProtocol = 0x00;
+
+ /*
+ * Decode the TS byte
+ */
+
+ if (pucAtr[0] == 0x3F)
+ { /* Inverse convention used */
+ psExtension->CardCapabilities.Convention =
+ SCARD_CONVENTION_INVERSE;
+ } else if (pucAtr[0] == 0x3B)
+ { /* Direct convention used */
+ psExtension->CardCapabilities.Convention = SCARD_CONVENTION_DIRECT;
+ } else
+ {
+ memset(psExtension, 0x00, sizeof(SMARTCARD_EXTENSION));
+ return 0;
+ }
+
+ /*
+ * Here comes the platform dependant stuff
+ */
+
+ /*
+ * Decode the T0 byte
+ */
+ Y1i = pucAtr[1] >> 4; /* Get the MSN in Y1 */
+ K = pucAtr[1] & 0x0F; /* Get the LSN in K */
+
+ p = 2;
+
+#ifdef ATR_DEBUG
+ debug_msg("Conv %02X, Y1 %02X, K %02X",
+ psExtension->CardCapabilities.Convention, Y1i, K);
+#endif
+
+ /*
+ * Examine Y1
+ */
+
+ do
+ {
+
+ TAi = (Y1i & 0x01) ? pucAtr[p++] : -1;
+ TBi = (Y1i & 0x02) ? pucAtr[p++] : -1;
+ TCi = (Y1i & 0x04) ? pucAtr[p++] : -1;
+ TDi = (Y1i & 0x08) ? pucAtr[p++] : -1;
+
+#ifdef ATR_DEBUG
+ debug_msg("T's %02X %02X %02X %02X", TAi, TBi, TCi, TDi);
+ debug_msg("P %02X", p);
+#endif
+
+ /*
+ * Examine TDi to determine protocol and more
+ */
+ if (TDi >= 0)
+ {
+ Y1i = TDi >> 4; /* Get the MSN in Y1 */
+ T = TDi & 0x0F; /* Get the LSN in K */
+
+ /*
+ * Set the current protocol TD1
+ */
+ if (psExtension->CardCapabilities.CurrentProtocol == 0x00)
+ {
+ switch (T)
+ {
+ case 0:
+ psExtension->CardCapabilities.CurrentProtocol =
+ SCARD_PROTOCOL_T0;
+ break;
+ case 1:
+ psExtension->CardCapabilities.CurrentProtocol =
+ SCARD_PROTOCOL_T1;
+ break;
+ default:
+ return 0;
+ }
+ }
+
+ if (T == 0)
+ {
+#ifdef ATR_DEBUG
+ debug_msg("T=0 Protocol Found");
+#endif
+ psExtension->CardCapabilities.AvailableProtocols |=
+ SCARD_PROTOCOL_T0;
+ psExtension->CardCapabilities.T0.BGT = 0;
+ psExtension->CardCapabilities.T0.BWT = 0;
+ psExtension->CardCapabilities.T0.CWT = 0;
+ psExtension->CardCapabilities.T0.CGT = 0;
+ psExtension->CardCapabilities.T0.WT = 0;
+ } else if (T == 1)
+ {
+#ifdef ATR_DEBUG
+ debug_msg("T=1 Protocol Found");
+#endif
+ psExtension->CardCapabilities.AvailableProtocols |=
+ SCARD_PROTOCOL_T1;
+ psExtension->CardCapabilities.T1.BGT = 0;
+ psExtension->CardCapabilities.T1.BWT = 0;
+ psExtension->CardCapabilities.T1.CWT = 0;
+ psExtension->CardCapabilities.T1.CGT = 0;
+ psExtension->CardCapabilities.T1.WT = 0;
+ } else
+ {
+ psExtension->CardCapabilities.AvailableProtocols |= T;
+ /*
+ * Do nothing for now since other protocols are not
+ * supported at this time
+ */
+ }
+
+ } else
+ {
+ Y1i = 0;
+ }
+
+ if (p > MAX_ATR_SIZE)
+ {
+ memset(psExtension, 0x00, sizeof(SMARTCARD_EXTENSION));
+ return 0;
+ }
+
+ }
+ while (Y1i != 0);
+
+ /*
+ * If TDx is not set then the current must be T0
+ */
+ if (psExtension->CardCapabilities.CurrentProtocol == 0x00)
+ {
+ psExtension->CardCapabilities.CurrentProtocol = SCARD_PROTOCOL_T0;
+ psExtension->CardCapabilities.AvailableProtocols |=
+ SCARD_PROTOCOL_T0;
+ }
+
+ /*
+ * Take care of the historical characters
+ */
+
+ psExtension->ATR.HistoryLength = K;
+ memcpy(psExtension->ATR.HistoryValue, &pucAtr[p], K);
+
+ p = p + K;
+
+ /*
+ * Check to see if TCK character is included It will be included if
+ * more than T=0 is supported
+ */
+
+ if (psExtension->CardCapabilities.AvailableProtocols &
+ SCARD_PROTOCOL_T1)
+ {
+ TCK = pucAtr[p++];
+ }
+
+ memcpy(psExtension->ATR.Value, pucAtr, p);
+ psExtension->ATR.Length = p; /* modified from p-1 */
+
+ return 1;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/atrhandler.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : atrhandler.h
+ Author : David Corcoran
+ Date : 7/27/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This keeps track of smartcard protocols,
+ timing issues, and atr handling.
+
+********************************************************************/
+
+#ifndef __atrhandler_h__
+#define __atrhandler_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SCARD_CONVENTION_DIRECT 0x0001
+#define SCARD_CONVENTION_INVERSE 0x0002
+
+ typedef struct _SMARTCARD_EXTENSION
+ {
+
+ struct _ATR
+ {
+ DWORD Length;
+ UCHAR Value[MAX_ATR_SIZE];
+ DWORD HistoryLength;
+ UCHAR HistoryValue[MAX_ATR_SIZE];
+ }
+ ATR;
+
+ DWORD ReadTimeout;
+
+ struct _CardCapabilities
+ {
+ UCHAR AvailableProtocols;
+ UCHAR CurrentProtocol;
+ UCHAR Convention;
+ USHORT ETU;
+
+ struct _PtsData
+ {
+ UCHAR F1;
+ UCHAR D1;
+ UCHAR I1;
+ UCHAR P1;
+ UCHAR N1;
+ }
+ PtsData;
+
+ struct _T1
+ {
+ USHORT BGT;
+ USHORT BWT;
+ USHORT CWT;
+ USHORT CGT;
+ USHORT WT;
+ }
+ T1;
+
+ struct _T0
+ {
+ USHORT BGT;
+ USHORT BWT;
+ USHORT CWT;
+ USHORT CGT;
+ USHORT WT;
+ }
+ T0;
+
+ }
+ CardCapabilities;
+
+ /*
+ * PREADER_CONNECTION psReaderConnection;
+ */
+
+ }
+ SMARTCARD_EXTENSION, *PSMARTCARD_EXTENSION;
+
+ /*
+ * Decodes the ATR and fills the structure
+ */
+
+ short ATRDecodeAtr(PSMARTCARD_EXTENSION psExtension,
+ const unsigned char *pucAtr, DWORD dwLength);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __smclib_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/config.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/config.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/config.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * config.h
+ * SmartCardServices
+ */
+
+/* config.h.in. Generated automatically from configure.in by autoheader. */
+
+/* display ATR parsing debug messages. */
+/* #undef ATR_DEBUG */
+
+/* Define to 1 if you have the `daemon' function. */
+#define HAVE_DAEMON 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <dl.h> header file. */
+/* #undef HAVE_DL_H */
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+/* #undef HAVE_DOPRNT */
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `flock' function. */
+#define HAVE_FLOCK 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long' function. */
+#define HAVE_GETOPT_LONG 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Libusb is available */
+/* #undef HAVE_LIBUSB */
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `nanosleep' function. */
+#define HAVE_NANOSLEEP 1
+
+/* Define if you have POSIX threads libraries and header files. */
+#define HAVE_PTHREAD 1
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+ zero-length file name argument. */
+/* #undef HAVE_STAT_EMPTY_STRING_BUG */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strlcat' function. */
+#define HAVE_STRLCAT 1
+
+/* Define to 1 if you have the `strlcpy' function. */
+#define HAVE_STRLCPY 1
+
+/* Define to 1 if you have the <syslog.h> header file. */
+#define HAVE_SYSLOG_H 1
+
+/* Define to 1 if you have the <sys/filio.h> header file. */
+#define HAVE_SYS_FILIO_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the <usb.h> header file. */
+/* #undef HAVE_USB_H */
+
+/* Define to 1 if you have the `vprintf' function. */
+#define HAVE_VPRINTF 1
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#define HAVE_VSNPRINTF 1
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+ slash. */
+/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
+
+/* Name of package */
+#define PACKAGE "PCSC Framework"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "pcsc-lite"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "pcsc-lite 1.4.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "pcsc-lite"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.4.0"
+
+/* directory containing USB drivers */
+//#define PCSCLITE_HP_DROPDIR "/usr/local/pcsc/drivers"
+
+/* PC/SC target architecture */
+#define PCSC_ARCH "MacOS"
+
+/* Define to the necessary symbol if this constant uses a non-standard name on
+ your system. */
+/* #undef PTHREAD_CREATE_JOINABLE */
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* directory containing IPC files (default /var/run) */
+/* #undef USE_IPCDIR */
+
+/* file containing pcscd pid */
+#define USE_RUN_PID "/var/run/pcscd"
+
+/* Version number of package */
+#define VERSION "1.4.0"
+
+/* Define to 1 if your processor stores words with the most significant byte
+ first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
+ `char[]'. */
+#define YYTEXT_POINTER 1
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef gid_t */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef uid_t */
+
+/* enable full musclecard debug messaging. */
+ #define MSC_DEBUG 1
+
Property changes on: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/config.h
___________________________________________________________________
Added: svn:executable
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1781 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/*
+ * A lexical scanner generated by flex
+ */
+
+/*
+ * Scanner skeleton version: $Header:
+ * /home/cvsroot/muscle/PCSC/src/configfile.c,v 1.3 2002/03/31 07:05:07
+ * corcoran Exp $
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+
+/*
+ * cfront 1.2 defines "c_plusplus" instead of "__cplusplus"
+ */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * Use prototypes in function declarations.
+ */
+#define YY_USE_PROTOS
+
+/*
+ * The "const" storage-class-modifier is valid.
+ */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef __TURBOC__
+#pragma warn -rch
+#pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/*
+ * Returned upon end-of-file.
+ */
+#define YY_NULL 0
+
+/*
+ * Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative, we
+ * want to instead treat it as an 8-bit unsigned char, hence the double
+ * cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/*
+ * Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/*
+ * Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/*
+ * Action number for EOF rule of a given start state.
+ */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/*
+ * Special action meaning "start processing a new file".
+ */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/*
+ * Size of default input buffer.
+ */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/*
+ * The funky do-while in the following #define is used to turn the
+ * definition int a single C statement (which needs a semi-colon
+ * terminator). This avoids problems with code like: if (
+ * condition_holds ) yyless( 5 ); else do_something_else(); Prior to
+ * using the do-while the compiler would get upset at the "else" because
+ * it interpreted the "if" statement as being all done when it reached the
+ * ';' after the yyless() call.
+ */
+
+/*
+ * Return all but the first 'n' matched characters back to the input
+ * stream.
+ */
+
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ *yy_cp = yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/*
+ * The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+struct yy_buffer_state
+{
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /*
+ * Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /*
+ * Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /*
+ * Whether we "own" the buffer - i.e., we know we created it, and can
+ * realloc() it to grow it, and should free() it to delete it.
+ */
+ int yy_is_our_buffer;
+
+ /*
+ * Whether this is an "interactive" input source; if so, and if we're
+ * using stdio for input, then we want to use getc() instead of
+ * fread(), to make sure we stop fetching input after each newline.
+ */
+ int yy_is_interactive;
+
+ /*
+ * Whether we're considered to be at the beginning of a line. If so,
+ * '^' rules will be active on the next match, otherwise not.
+ */
+ int yy_at_bol;
+
+ /*
+ * Whether to try to fill the input buffer when we reach the end of
+ * it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /*
+ * When an EOF's been seen but there's still some text to process then
+ * we mark the buffer as YY_EOF_PENDING, to indicate that we shouldn't
+ * try reading from the input source any more. We might still have a
+ * bunch of tokens to match, though, because of possible backing-up.
+ * When we actually see the EOF, we change the status to "new" (via
+ * yyrestart()), so that the user can continue scanning by just
+ * pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/*
+ * We provide macros for accessing buffer states in case in the future we
+ * want to put the buffer states in a more general "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+/*
+ * yy_hold_char holds the character lost when yytext is formed.
+ */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into
+ * yy_ch_buf */
+
+int yyleng;
+
+/*
+ * Points to current character in buffer.
+ */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/*
+ * Flag which is used to allow yywrap()'s to do buffer switches instead of
+ * setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO((FILE * input_file));
+
+void yy_switch_to_buffer YY_PROTO((YY_BUFFER_STATE new_buffer));
+void yy_load_buffer_state YY_PROTO((void));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO((FILE * file, int size));
+void yy_delete_buffer YY_PROTO((YY_BUFFER_STATE b));
+void yy_init_buffer YY_PROTO((YY_BUFFER_STATE b, FILE * file));
+void yy_flush_buffer YY_PROTO((YY_BUFFER_STATE b));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO((char *base, yy_size_t size));
+YY_BUFFER_STATE yy_scan_string YY_PROTO((yyconst char *yy_str));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO((yyconst char *bytes, int len));
+
+static void *yy_flex_alloc YY_PROTO((yy_size_t));
+static void *yy_flex_realloc YY_PROTO((void *, yy_size_t));
+static void yy_flex_free YY_PROTO((void *));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO((void));
+static yy_state_type yy_try_NUL_trans YY_PROTO((yy_state_type
+ current_state));
+static int yy_get_next_buffer YY_PROTO((void));
+static void yy_fatal_error YY_PROTO((yyconst char msg[]));
+
+/*
+ * Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 7
+#define YY_END_OF_BUFFER 8
+static yyconst short int yy_accept[17] = { 0,
+ 0, 0, 8, 6, 4, 2, 6, 1, 6, 5,
+ 0, 3, 1, 0, 5, 0
+};
+
+static yyconst int yy_ec[256] = { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 4, 5, 1, 1, 1, 6, 1,
+ 1, 1, 1, 1, 7, 7, 7, 8, 8, 8,
+ 8, 8, 8, 8, 8, 8, 8, 1, 1, 1,
+ 1, 1, 1, 7, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 1, 7, 1, 1, 7, 1, 10, 10, 10, 10,
+
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+};
+
+static yyconst int yy_meta[11] = { 0,
+ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1
+};
+
+static yyconst short int yy_base[20] = { 0,
+ 0, 0, 15, 31, 31, 31, 8, 0, 10, 10,
+ 18, 31, 0, 20, 0, 31, 26, 13, 28
+};
+
+static yyconst short int yy_def[20] = { 0,
+ 16, 1, 16, 16, 16, 16, 17, 18, 19, 16,
+ 17, 16, 18, 19, 10, 0, 16, 16, 16
+};
+
+static yyconst short int yy_nxt[42] = { 0,
+ 4, 5, 6, 7, 8, 9, 10, 10, 10, 10,
+ 12, 12, 12, 13, 16, 12, 15, 15, 15, 15,
+ 12, 12, 12, 16, 16, 12, 11, 11, 14, 14,
+ 3, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16
+};
+
+static yyconst short int yy_chk[42] = { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 7, 7, 9, 18, 3, 9, 10, 10, 10, 10,
+ 11, 11, 14, 0, 0, 14, 17, 17, 19, 19,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16
+};
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/*
+ * The intent behind this definition is that it'll catch any uses of
+ * REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "configfile.l"
+#define INITIAL 0
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+#line 14 "configfile.l"
+int evaluatetoken(char *pcToken);
+
+static int iLinenumber = 1;
+static char *pcPrevious = 0;
+static char *pcCurrent = 0;
+static char *pcFriendlyname = 0;
+static char *pcDevicename = 0;
+static char *pcLibpath = 0;
+static char *pcChannelid = 0;
+static int badError = 0;
+
+void tok_error(char *pcToken_error);
+
+#line 399 "lex.yy.c"
+
+/*
+ * Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO((void));
+#else
+extern int yywrap YY_PROTO((void));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO((int c, char *buf_ptr));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO((char *, yyconst char *, int));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO((yyconst char *));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO((void));
+#else
+static int input YY_PROTO((void));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO((int new_state));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO((void));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO((void));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/*
+ * Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/*
+ * Amount of stuff to slurp up with each read.
+ */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/*
+ * Copy whatever the last rule matched to the standard output.
+ */
+
+#ifndef ECHO
+/*
+ * This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/*
+ * Gets input and stuffs it into "buf". number of characters read, or
+ * YY_NULL, is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+ && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/*
+ * No semi-colon after return; correct usage is to write "yyterminate();"
+ * - we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/*
+ * Number of entries by which start-condition stack grows.
+ */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/*
+ * Report a fatal error.
+ */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/*
+ * Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/*
+ * Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/*
+ * Code executed at the end of each rule.
+ */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 29 "configfile.l"
+
+#line 553 "lex.yy.c"
+
+ if (yy_init)
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if (!yy_start)
+ yy_start = 1; /* first start state */
+
+ if (!yyin)
+ yyin = stdin;
+
+ if (!yyout)
+ yyout = stdout;
+
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_load_buffer_state();
+ }
+
+ while (1) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /*
+ * Support of yytext.
+ */
+ *yy_cp = yy_hold_char;
+
+ /*
+ * yy_bp points to the position in yy_ch_buf of the start of the
+ * current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+ yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 17)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while (yy_base[yy_current_state] != 31);
+
+ yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if (yy_act == 0)
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+ do_action: /* This label is used only to access EOF actions. */
+
+ switch (yy_act)
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /*
+ * undo the effects of YY_DO_BEFORE_ACTION
+ */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+ case 1:
+ YY_RULE_SETUP
+#line 31 "configfile.l"
+ {
+ }
+ YY_BREAK case 2:
+ YY_RULE_SETUP
+#line 32 "configfile.l"
+ {
+ iLinenumber++;
+ }
+ YY_BREAK case 3:
+ YY_RULE_SETUP
+#line 33 "configfile.l"
+ {
+ evaluatetoken(yytext);
+ }
+ YY_BREAK case 4:
+ YY_RULE_SETUP
+#line 34 "configfile.l"
+ {
+ }
+ YY_BREAK case 5:
+ YY_RULE_SETUP
+#line 35 "configfile.l"
+ {
+ evaluatetoken(yytext);
+ }
+ YY_BREAK case 6:
+ YY_RULE_SETUP
+#line 36 "configfile.l"
+ {
+ tok_error(yytext);
+ }
+ YY_BREAK case 7:
+ YY_RULE_SETUP
+#line 37 "configfile.l"
+ ECHO;
+ YY_BREAK
+#line 671 "lex.yy.c"
+ case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /*
+ * Amount of text matched not including the EOB char.
+ */
+ int yy_amount_of_matched_text =
+ (int) (yy_cp - yytext_ptr) - 1;
+
+ /*
+ * Undo the effects of YY_DO_BEFORE_ACTION.
+ */
+ *yy_cp = yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+ if (yy_current_buffer->yy_buffer_status ==
+ YY_BUFFER_NEW)
+ {
+ /*
+ * We're scanning a new file or input source. It's
+ * possible that this happened because the user just
+ * pointed yyin at a new source and called yylex().
+ * If so, then we have to assure consistency between
+ * yy_current_buffer and our globals. Here is the
+ * right place to do so, because this is the first
+ * action (other than possibly a back-up) that will
+ * match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /*
+ * Note that here we test for yy_c_buf_p "<=" to the
+ * position of the first EOB in the buffer, since
+ * yy_c_buf_p will already have been incremented past the
+ * NUL character (since all states make transitions on EOB
+ * to the end-of-buffer state). Contrast this with the
+ * test in input().
+ */
+ if (yy_c_buf_p <=
+ &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /*
+ * Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it for us
+ * because it doesn't know how to deal with the
+ * possibility of jamming (and we don't want to build
+ * jamming into it because then it will run more
+ * slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans(yy_current_state);
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if (yy_next_state)
+ {
+ /*
+ * Consume the NUL.
+ */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if (yywrap())
+ {
+ /*
+ * Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up yy_c_buf_p so
+ * that if some total hoser (like flex
+ * itself) wants to call the scanner after
+ * we return the YY_NULL, it'll still work
+ * - another YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--no action found");
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/*
+ * yy_get_next_buffer - try to read in a new buffer Returns a code
+ * representing an action: EOB_ACT_LAST_MATCH - EOB_ACT_CONTINUE_SCAN -
+ * continue scanning from current position EOB_ACT_END_OF_FILE - end of
+ * file
+ */
+
+static int yy_get_next_buffer()
+{
+ register char *dest = yy_current_buffer->yy_ch_buf;
+ register char *source = yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if (yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1])
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--end of buffer missed");
+
+ if (yy_current_buffer->yy_fill_buffer == 0)
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if (yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1)
+ {
+ /*
+ * We matched a single character, the EOB, so treat this as a
+ * final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /*
+ * We matched some text prior to the EOB, first process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /*
+ * Try to read more data.
+ */
+
+ /*
+ * First move last chars to start of buffer.
+ */
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+ for (i = 0; i < number_to_move; ++i)
+ *(dest++) = *(source++);
+
+ if (yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING)
+ /*
+ * don't do the read, it's not guaranteed to return an EOF, just
+ * force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while (num_to_read <= 0)
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR
+ ("input buffer overflow, can't enlarge buffer because scanner uses REJECT");
+#else
+
+ /*
+ * just a shorter name for the current buffer
+ */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset = (int) (yy_c_buf_p - b->yy_ch_buf);
+
+ if (b->yy_is_our_buffer)
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if (new_size <= 0)
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /*
+ * Include room in for 2 EOB chars.
+ */
+ yy_flex_realloc((void *) b->yy_ch_buf,
+ b->yy_buf_size + 2);
+ } else
+ /*
+ * Can't grow it, we don't own it.
+ */
+ b->yy_ch_buf = 0;
+
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR
+ ("fatal error - scanner input buffer overflow");
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if (num_to_read > YY_READ_BUF_SIZE)
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /*
+ * Read in more data.
+ */
+ YY_INPUT((&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read);
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if (yy_n_chars == 0)
+ {
+ if (number_to_move == YY_MORE_ADJ)
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart(yyin);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/*
+ * yy_get_previous_state - get the state just before the EOB char was
+ * reached
+ */
+
+static yy_state_type yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for (yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp)
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 17)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/*
+ * yy_try_NUL_trans - try to make a transition on the NUL character
+ * synopsis next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state)
+#else
+static yy_state_type yy_try_NUL_trans(yy_current_state)
+ yy_state_type yy_current_state;
+#endif
+{
+ register int yy_is_jam;
+ register char *yy_cp = yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 17)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 16);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput(int c, register char *yy_bp)
+#else
+static void yyunput(c, yy_bp)
+ int c;
+ register char *yy_bp;
+#endif
+{
+ register char *yy_cp = yy_c_buf_p;
+
+ /*
+ * undo effects of setting up yytext
+ */
+ *yy_cp = yy_hold_char;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ { /* need to shift things up to make room */
+ /*
+ * +2 for EOB chars.
+ */
+ register int number_to_move = yy_n_chars + 2;
+ register char *dest =
+ &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size +
+ 2];
+ register char *source =
+ &yy_current_buffer->yy_ch_buf[number_to_move];
+
+ while (source > yy_current_buffer->yy_ch_buf)
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ yy_current_buffer->yy_n_chars =
+ yy_n_chars = yy_current_buffer->yy_buf_size;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ YY_FATAL_ERROR("flex scanner push-back overflow");
+ }
+
+ *--yy_cp = (char) c;
+
+ yytext_ptr = yy_bp;
+ yy_hold_char = *yy_cp;
+ yy_c_buf_p = yy_cp;
+}
+#endif /* ifndef YY_NO_UNPUT */
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+{
+ int c;
+
+ *yy_c_buf_p = yy_hold_char;
+
+ if (*yy_c_buf_p == YY_END_OF_BUFFER_CHAR)
+ {
+ /*
+ * yy_c_buf_p now points to the character we want to return. If
+ * this occurs *before* the EOB characters, then it's a valid NUL;
+ * if not, then we've hit the end of the buffer.
+ */
+ if (yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ /*
+ * This was really a NUL.
+ */
+ *yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yy_c_buf_p - yytext_ptr;
+ ++yy_c_buf_p;
+
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_LAST_MATCH:
+ /*
+ * This happens because yy_g_n_b() sees that we've
+ * accumulated a token and flags that we need to try
+ * matching the token before proceeding. But for input(),
+ * there's no matching to consider. So convert the
+ * EOB_ACT_LAST_MATCH to EOB_ACT_END_OF_FILE.
+ */
+
+ /*
+ * Reset buffer status.
+ */
+ yyrestart(yyin);
+
+ /*
+ * fall through
+ */
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if (yywrap())
+ return EOF;
+
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p = yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
+ *yy_c_buf_p = '\0'; /* preserve yytext */
+ yy_hold_char = *++yy_c_buf_p;
+
+ return c;
+}
+
+#ifdef YY_USE_PROTOS
+void yyrestart(FILE * input_file)
+#else
+void yyrestart(input_file)
+ FILE *input_file;
+#endif
+{
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_init_buffer(yy_current_buffer, input_file);
+ yy_load_buffer_state();
+}
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer)
+#else
+void yy_switch_to_buffer(new_buffer)
+ YY_BUFFER_STATE new_buffer;
+#endif
+{
+ if (yy_current_buffer == new_buffer)
+ return;
+
+ if (yy_current_buffer)
+ {
+ /*
+ * Flush out information for old buffer.
+ */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /*
+ * We don't actually know whether we did this switch during EOF
+ * (yywrap()) processing, but the only time this flag is looked at is
+ * after yywrap() is called, so it's safe to go ahead and always set
+ * it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state(void)
+#else
+void yy_load_buffer_state()
+#endif
+{
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+}
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer(FILE * file, int size)
+#else
+YY_BUFFER_STATE yy_create_buffer(file, size)
+ FILE *file;
+ int size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_buf_size = size;
+
+ /*
+ * yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yy_flex_alloc(b->yy_buf_size + 2);
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer(b, file);
+
+ return b;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer(YY_BUFFER_STATE b)
+#else
+void yy_delete_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+{
+ if (!b)
+ return;
+
+ if (b == yy_current_buffer)
+ yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+ if (b->yy_is_our_buffer)
+ yy_flex_free((void *) b->yy_ch_buf);
+
+ yy_flex_free((void *) b);
+}
+
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO((int));
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer(YY_BUFFER_STATE b, FILE * file)
+#else
+void yy_init_buffer(b, file)
+ YY_BUFFER_STATE b;
+ FILE *file;
+#endif
+
+{
+ yy_flush_buffer(b);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = 0;
+#else
+ b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0;
+#endif
+#endif
+}
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer(YY_BUFFER_STATE b)
+#else
+void yy_flush_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+
+{
+ if (!b)
+ return;
+
+ b->yy_n_chars = 0;
+
+ /*
+ * We always need two end-of-buffer characters. The first causes a
+ * transition to the end-of-buffer state. The second causes a jam in
+ * that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if (b == yy_current_buffer)
+ yy_load_buffer_state();
+}
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size)
+#else
+YY_BUFFER_STATE yy_scan_buffer(base, size)
+ char *base;
+ yy_size_t size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ if (size < 2 ||
+ base[size - 2] != YY_END_OF_BUFFER_CHAR ||
+ base[size - 1] != YY_END_OF_BUFFER_CHAR)
+ /*
+ * They forgot to leave room for the EOB's.
+ */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()");
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer(b);
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string(yyconst char *yy_str)
+#else
+YY_BUFFER_STATE yy_scan_string(yy_str)
+ yyconst char *yy_str;
+#endif
+{
+ int len;
+ for (len = 0; yy_str[len]; ++len)
+ ;
+
+ return yy_scan_bytes(yy_str, len);
+}
+#endif
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes(yyconst char *bytes, int len)
+#else
+YY_BUFFER_STATE yy_scan_bytes(bytes, len)
+ yyconst char *bytes;
+ int len;
+#endif
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /*
+ * Get memory for full buffer, including space for trailing EOB's.
+ */
+ n = len + 2;
+ buf = (char *) yy_flex_alloc(n);
+ if (!buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()");
+
+ for (i = 0; i < len; ++i)
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer(buf, n);
+ if (!b)
+ YY_FATAL_ERROR("bad buffer in yy_scan_bytes()");
+
+ /*
+ * It's okay to grow etc. this buffer, and we should throw it away
+ * when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state(int new_state)
+#else
+static void yy_push_state(new_state)
+ int new_state;
+#endif
+{
+ if (yy_start_stack_ptr >= yy_start_stack_depth)
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof(int);
+
+ if (!yy_start_stack)
+ yy_start_stack = (int *) yy_flex_alloc(new_size);
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size);
+
+ if (!yy_start_stack)
+ YY_FATAL_ERROR
+ ("out of memory expanding start-condition stack");
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+}
+#endif
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+{
+ if (--yy_start_stack_ptr < 0)
+ YY_FATAL_ERROR("start-condition stack underflow");
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+}
+#endif
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+{
+ return yy_start_stack[yy_start_stack_ptr - 1];
+}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error(yyconst char msg[])
+#else
+static void yy_fatal_error(msg)
+ char msg[];
+#endif
+{
+ (void) fprintf(stderr, "%s\n", msg);
+ exit(YY_EXIT_FAILURE);
+}
+
+/*
+ * Redefine yyless() so it works in section 3 code.
+ */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ yytext[yyleng] = yy_hold_char; \
+ yy_c_buf_p = yytext + n; \
+ yy_hold_char = *yy_c_buf_p; \
+ *yy_c_buf_p = '\0'; \
+ yyleng = n; \
+ } \
+ while ( 0 )
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy(char *s1, yyconst char *s2, int n)
+#else
+static void yy_flex_strncpy(s1, s2, n)
+ char *s1;
+ yyconst char *s2;
+ int n;
+#endif
+{
+ register int i;
+ for (i = 0; i < n; ++i)
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen(yyconst char *s)
+#else
+static int yy_flex_strlen(s)
+ yyconst char *s;
+#endif
+{
+ register int n;
+ for (n = 0; s[n]; ++n)
+ ;
+
+ return n;
+}
+#endif
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc(yy_size_t size)
+#else
+static void *yy_flex_alloc(size)
+ yy_size_t size;
+#endif
+{
+ return (void *) malloc(size);
+}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc(void *ptr, yy_size_t size)
+#else
+static void *yy_flex_realloc(ptr, size)
+ void *ptr;
+ yy_size_t size;
+#endif
+{
+ /*
+ * The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those that use
+ * void* generic pointers. It works with the latter because both ANSI
+ * C and C++ allow castless assignment from any pointer type to void*,
+ * and deal with argument conversions as though doing an assignment.
+ */
+ return (void *) realloc((char *) ptr, size);
+}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free(void *ptr)
+#else
+static void yy_flex_free(ptr)
+ void *ptr;
+#endif
+{
+ free(ptr);
+}
+
+#if YY_MAIN
+int main()
+{
+ yylex();
+ return 0;
+}
+#endif
+#line 37 "configfile.l"
+
+#include <stdio.h>
+#include <string.h>
+#include <wintypes.h>
+
+#include "pcsclite.h"
+#include "sys_generic.h"
+#include "readerfactory.h"
+#include "debuglog.h"
+
+int evaluatetoken(char *pcToken)
+{
+
+ DWORD dwChannelId = 0;
+ int p = 0;
+ int n = 0;
+
+ if (pcPrevious == 0)
+ { /* This is the key */
+ pcPrevious = strdup(pcToken);
+ } else
+ {
+ pcCurrent = pcToken;
+ if (strcmp(pcPrevious, "FRIENDLYNAME") == 0)
+ {
+ if (pcFriendlyname == 0)
+ {
+ pcFriendlyname = (char *) malloc(strlen(pcCurrent) - 1);
+ for (n = 0; n < strlen(pcCurrent); n++)
+ {
+ if (pcCurrent[n] != '"')
+ { /* Strip off the quotes */
+ pcFriendlyname[p++] = pcCurrent[n];
+ }
+ }
+ pcFriendlyname[p++] = 0;
+ } else
+ {
+ tok_error(pcPrevious);
+ return 1;
+ }
+ } else if (strcmp(pcPrevious, "DEVICENAME") == 0)
+ {
+ if (pcDevicename == 0)
+ {
+ pcDevicename = strdup(pcCurrent);
+ } else
+ {
+ tok_error(pcPrevious);
+ return 1;
+ }
+ } else if (strcmp(pcPrevious, "LIBPATH") == 0)
+ {
+ if (pcLibpath == 0)
+ {
+ pcLibpath = strdup(pcCurrent);
+ } else
+ {
+ tok_error(pcPrevious);
+ return 1;
+ }
+ } else if (strcmp(pcPrevious, "CHANNELID") == 0)
+ {
+ if (pcChannelid == 0)
+ {
+ pcChannelid = strdup(pcCurrent);
+ } else
+ {
+ tok_error(pcPrevious);
+ return 1;
+ }
+ } else
+ {
+ tok_error(pcPrevious);
+ return 1;
+ }
+
+ free(pcPrevious);
+ pcPrevious = 0;
+ }
+
+ if (pcFriendlyname != 0 && pcDevicename != 0 &&
+ pcLibpath != 0 && pcChannelid != 0)
+ {
+
+ dwChannelId = strtoul(pcChannelid, 0, 16);
+ RFAddReader(pcFriendlyname, dwChannelId, pcLibpath, pcDevicename);
+
+ free(pcFriendlyname);
+ free(pcDevicename);
+ free(pcLibpath);
+ free(pcChannelid);
+ pcFriendlyname = 0;
+ pcDevicename = 0;
+ pcLibpath = 0;
+ pcChannelid = 0;
+ }
+
+ return 0;
+}
+
+void tok_error(char *token_error)
+{
+ log_msg(PCSC_LOG_ERROR, "%s:%d tok_error: invalid value in reader.conf",
+ __FILE__, __LINE__);
+ badError = 1;
+}
+
+int DBUpdateReaders(char *readerconf)
+{
+
+ FILE *configFile;
+ configFile = 0;
+
+ configFile = fopen(readerconf, "r");
+
+ if (configFile == 0)
+ {
+ return 1;
+ }
+
+ yyin = configFile;
+
+ do
+ {
+ yylex();
+ }
+ while (!feof(configFile));
+
+ fclose(configFile);
+
+ if (badError == 1)
+ {
+ return -1;
+ } else
+ {
+ return 0;
+ }
+} /* End of configfile.c */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/*****************************************************************
+/
+/ File : configfile.h
+/ Author : David Corcoran
+/ Date : February 12, 1999 modified 7/28/99
+/ License: Copyright (C) 1999 David Corcoran
+/ <corcoran at linuxnet.com>
+/ Purpose: Header file for reading lexical config files.
+/ See http://www.linuxnet.com for more information.
+/
+******************************************************************/
+
+#ifndef __configfile_h__
+#define __configfile_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int DBUpdateReaders(char *readerconf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __configfile_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.l
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.l (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/configfile.l 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,142 @@
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+
+%{
+int evaluatetoken( char *pcToken );
+
+static int iLinenumber = 1;
+static char *pcPrevious = 0;
+static char *pcCurrent = 0;
+static char *pcFriendlyname = 0;
+static char *pcDevicename = 0;
+static char *pcLibpath = 0;
+static char *pcChannelid = 0;
+static int badError = 0;
+
+void tok_error ( char *pcToken_error );
+
+%}
+
+%%
+
+#.* {}
+"\n" { iLinenumber++; }
+(\"[^"\n]*["\n])|(\'[^'\n]*['\n]) { evaluatetoken( yytext); }
+[ \t] {}
+([A-Z]|[a-z]|[0-9]|[\\\/\-\.\_\@])+ { evaluatetoken( yytext ); }
+. { tok_error( yytext ); }
+%%
+
+#include <stdio.h>
+#include <string.h>
+#include <wintypes.h>
+
+#include "pcsclite.h"
+#include "sys_generic.h"
+#include "readerfactory.h"
+#include "debuglog.h"
+
+int evaluatetoken( char *pcToken ) {
+
+ DWORD dwChannelId = 0;
+ int p = 0;
+ int n = 0;
+
+ if ( pcPrevious == 0 ) { /* This is the key */
+ pcPrevious = strdup( pcToken );
+ } else {
+ pcCurrent = pcToken;
+ if ( strcmp( pcPrevious, "FRIENDLYNAME" ) == 0 ) {
+ if ( pcFriendlyname == 0 ) {
+ pcFriendlyname = (char *)malloc(strlen(pcCurrent)-1);
+ for ( n = 0; n < strlen(pcCurrent); n++ ) {
+ if ( pcCurrent[n] != '"' ) { /* Strip off the quotes */
+ pcFriendlyname[p++] = pcCurrent[n];
+ }
+ }
+ pcFriendlyname[p++] = 0;
+ } else {
+ tok_error( pcPrevious ); return 1;
+ }
+ } else if ( strcmp( pcPrevious, "DEVICENAME" ) == 0 ) {
+ if ( pcDevicename == 0 ) {
+ pcDevicename = strdup( pcCurrent );
+ } else {
+ tok_error( pcPrevious ); return 1;
+ }
+ } else if ( strcmp( pcPrevious, "LIBPATH" ) == 0 ) {
+ if ( pcLibpath == 0 ) {
+ pcLibpath = strdup( pcCurrent );
+ } else {
+ tok_error( pcPrevious ); return 1;
+ }
+ } else if ( strcmp( pcPrevious, "CHANNELID" ) == 0 ) {
+ if ( pcChannelid == 0 ) {
+ pcChannelid = strdup( pcCurrent );
+ } else {
+ tok_error( pcPrevious ); return 1;
+ }
+ } else {
+ tok_error( pcPrevious ); return 1;
+ }
+
+ free( pcPrevious ); pcPrevious = 0;
+ }
+
+ if ( pcFriendlyname != 0 && pcDevicename != 0 &&
+ pcLibpath != 0 && pcChannelid != 0 ) {
+
+ dwChannelId = strtoul( pcChannelid, 0, 16 );
+ RFAddReader( pcFriendlyname, dwChannelId, pcLibpath, pcDevicename );
+
+ free( pcFriendlyname ); free( pcDevicename );
+ free( pcLibpath); free( pcChannelid );
+ pcFriendlyname = 0; pcDevicename = 0;
+ pcLibpath = 0; pcChannelid = 0;
+ }
+
+ return 0;
+}
+
+void tok_error ( char *token_error ) {
+ debug_msg("%s:%d tok_error: invalid value in reader.conf",
+ __FILE__, __LINE__);
+ badError = 1;
+}
+
+int DBUpdateReaders ( char *readerconf ) {
+
+ FILE *configFile;
+ configFile = 0;
+
+ configFile = fopen( readerconf, "r");
+
+ if (configFile == 0) {
+ return 1;
+ }
+
+ yyin = configFile;
+
+ do {
+ yylex();
+ }
+ while (!feof(configFile));
+
+ fclose(configFile);
+
+ if (badError == 1) {
+ return -1;
+ } else {
+ return 0;
+ }
+} /* End of configfile.c */
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,160 @@
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2002
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 1999-2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: debuglog.c 1953 2006-03-21 13:46:28Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles debugging for libpcsclite.
+ */
+
+#include "config.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "debug.h"
+//#include "strlcpycat.h"
+
+#define DEBUG_BUF_SIZE 2048
+
+/* default level is a bit verbose to be backward compatible */
+static char LogLevel = PCSC_LOG_ERROR;
+
+static signed char LogDoColor = 0; /* no color by default */
+void log_init(void);
+
+void log_init(void)
+{
+ char *e;
+
+#ifdef LIBPCSCLITE
+ e = getenv("PCSCLITE_DEBUG");
+#else
+ e = getenv("MUSCLECARD_DEBUG");
+#endif
+ if (e)
+ LogLevel = atoi(e);
+
+ /* no color under Windows */
+#ifndef WIN32
+ /* log to stderr and stderr is a tty? */
+ if (isatty(fileno(stderr)))
+ {
+ const char *terms[] = { "linux", "xterm", "xterm-color", "Eterm", "rxvt", "rxvt-unicode" };
+ char *term;
+
+ term = getenv("TERM");
+ if (term)
+ {
+ unsigned int i;
+
+ /* for each known color terminal */
+ for (i = 0; i < sizeof(terms) / sizeof(terms[0]); i++)
+ {
+ /* we found a supported term? */
+ if (0 == strcmp(terms[i], term))
+ {
+ LogDoColor = 1;
+ break;
+ }
+ }
+ }
+ }
+#endif
+} /* log_init */
+
+void log_msg(const int priority, const char *fmt, ...)
+{
+ char DebugBuffer[DEBUG_BUF_SIZE];
+ va_list argptr;
+ static int is_initialized = 0;
+
+ if (!is_initialized)
+ {
+ log_init();
+ is_initialized = 1;
+ }
+
+ if (priority < LogLevel) /* log priority lower than threshold? */
+ return;
+
+ va_start(argptr, fmt);
+#ifndef WIN32
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+#if HAVE_VSNPRINTF
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+ vsprintf(DebugBuffer, fmt, argptr);
+#endif
+#endif
+ va_end(argptr);
+
+#ifndef WIN32
+ {
+ if (LogDoColor)
+ {
+ const char *color_pfx = "", *color_sfx = "\33[0m";
+
+ switch (priority)
+ {
+ case PCSC_LOG_CRITICAL:
+ color_pfx = "\33[01;31m"; /* bright + Red */
+ break;
+
+ case PCSC_LOG_ERROR:
+ color_pfx = "\33[35m"; /* Magenta */
+ break;
+
+ case PCSC_LOG_INFO:
+ color_pfx = "\33[34m"; /* Blue */
+ break;
+
+ case PCSC_LOG_DEBUG:
+ color_pfx = ""; /* normal (black) */
+ color_sfx = "";
+ break;
+ }
+ fprintf(stderr, "%s%s%s\n", color_pfx, DebugBuffer, color_sfx);
+ }
+ else
+ fprintf(stderr, "%s\n", DebugBuffer);
+ }
+#else
+ fprintf(stderr, "%s\n", DebugBuffer);
+#endif
+} /* log_msg */
+
+void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
+ const int len)
+{
+ char DebugBuffer[DEBUG_BUF_SIZE];
+ int i;
+ char *c;
+ char *debug_buf_end;
+
+ if (priority < LogLevel) /* log priority lower than threshold? */
+ return;
+
+ debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
+
+ strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
+ c = DebugBuffer + strlen(DebugBuffer);
+
+ for (i = 0; (i < len) && (c < debug_buf_end); ++i)
+ {
+ sprintf(c, "%02X ", buffer[i]);
+ c += strlen(c);
+ }
+
+ fprintf(stderr, "%s\n", DebugBuffer);
+} /* log_xxd */
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debug.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,78 @@
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 1999-2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: debuglog.h 1835 2006-01-25 10:42:23Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles debugging.
+ *
+ * @note log message is sent to syslog or stderr depending on --foreground
+ * command line argument
+ *
+ * @test
+ * @code
+ * Log1(priority, "text");
+ * log "text" with priority level priority
+ * Log2(priority, "text: %d", 1234);
+ * log "text: 1234"
+ * the format string can be anything printf() can understand
+ * Log3(priority, "text: %d %d", 1234, 5678);
+ * log "text: 1234 5678"
+ * the format string can be anything printf() can understand
+ * LogXxd(priority, msg, buffer, size);
+ * log "msg" + a hex dump of size bytes of buffer[]
+ * @endcode
+ */
+
+#ifndef __debug_h__
+#define __debug_h__
+
+#ifdef PCSC
+/* use syslog, etc. if we are included from a file for pcscd */
+#include "debuglog.h"
+#else
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+enum {
+ PCSC_LOG_DEBUG = 0,
+ PCSC_LOG_INFO,
+ PCSC_LOG_ERROR,
+ PCSC_LOG_CRITICAL
+};
+
+#include <stdio.h>
+
+/* You can't do #ifndef __FUNCTION__ */
+#if !defined(__GNUC__) && !defined(__IBMC__)
+#define __FUNCTION__ ""
+#endif
+
+#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
+#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
+#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
+#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
+#define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
+
+void log_msg(const int priority, const char *fmt, ...);
+void log_xxd(const int priority, const char *msg,
+ const unsigned char *buffer, const int size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif /* __debug_h__ */
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,452 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * debuglog.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2002
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 1999-2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: debuglog.c 2302 2007-01-06 17:57:58Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles debugging for pcscd.
+ */
+
+#include "config.h"
+
+#ifndef WIN32
+#include <syslog.h>
+#endif
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <sys/types.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "debuglog.h"
+#include "sys_generic.h"
+//#include "strlcpy.h"
+
+/**
+ * Max string size when dumping a 256 bytes longs APDU
+ * Should be bigger than 256*3+30
+ */
+#define DEBUG_BUF_SIZE 2048
+
+static char LogSuppress = DEBUGLOG_LOG_ENTRIES;
+static char LogMsgType = DEBUGLOG_NO_DEBUG;
+static char LogCategory = DEBUG_CATEGORY_NOTHING;
+
+/* default level is a bit verbose to be backward compatible */
+static char LogLevel = PCSC_LOG_INFO;
+
+static signed char LogDoColor = 0; /* no color by default */
+
+void log_msg(const int priority, const char *fmt, ...)
+{
+ char DebugBuffer[DEBUG_BUF_SIZE];
+ va_list argptr;
+
+ if ((LogSuppress != DEBUGLOG_LOG_ENTRIES)
+ || (priority < LogLevel) /* log priority lower than threshold? */
+ || (DEBUGLOG_NO_DEBUG == LogMsgType))
+ return;
+
+ va_start(argptr, fmt);
+#ifndef WIN32
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+#if HAVE_VSNPRINTF
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+ vsprintf(DebugBuffer, fmt, argptr);
+#endif
+#endif
+ va_end(argptr);
+
+#ifndef WIN32
+ if (DEBUGLOG_SYSLOG_DEBUG == LogMsgType)
+ syslog(LOG_INFO, "%s", DebugBuffer);
+ else
+ {
+ if (LogDoColor)
+ {
+ const char *color_pfx = "", *color_sfx = "\33[0m";
+
+ switch (priority)
+ {
+ case PCSC_LOG_CRITICAL:
+ color_pfx = "\33[01;31m"; /* bright + Red */
+ break;
+
+ case PCSC_LOG_ERROR:
+ color_pfx = "\33[35m"; /* Magenta */
+ break;
+
+ case PCSC_LOG_INFO:
+ color_pfx = "\33[34m"; /* Blue */
+ break;
+
+ case PCSC_LOG_DEBUG:
+ color_pfx = ""; /* normal (black) */
+ color_sfx = "";
+ break;
+ }
+ fprintf(stderr, "%s%s%s\n", color_pfx, DebugBuffer, color_sfx);
+ }
+ else
+ fprintf(stderr, "%s\n", DebugBuffer);
+ }
+#else
+ fprintf(stderr, "%s\n", DebugBuffer);
+#endif
+} /* log_msg */
+
+void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
+ const int len)
+{
+ char DebugBuffer[DEBUG_BUF_SIZE];
+ int i;
+ char *c;
+ char *debug_buf_end;
+
+ if ((LogSuppress != DEBUGLOG_LOG_ENTRIES)
+ || (priority < LogLevel) /* log priority lower than threshold? */
+ || (DEBUGLOG_NO_DEBUG == LogMsgType))
+ return;
+
+ debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
+
+ strlcpy(DebugBuffer, msg, sizeof(DebugBuffer));
+ c = DebugBuffer + strlen(DebugBuffer);
+
+ for (i = 0; (i < len) && (c < debug_buf_end); ++i)
+ {
+ sprintf(c, "%02X ", buffer[i]);
+ c += 3;
+ }
+
+ /* the buffer is too small so end it with "..." */
+ if ((c >= debug_buf_end) && (i < len))
+ c[-3] = c[-2] = c[-1] = '.';
+
+#ifndef WIN32
+ if (DEBUGLOG_SYSLOG_DEBUG == LogMsgType)
+ syslog(LOG_INFO, "%s", DebugBuffer);
+ else
+#endif
+ fprintf(stderr, "%s\n", DebugBuffer);
+} /* log_xxd */
+
+#ifdef PCSCD
+void DebugLogSuppress(const int lSType)
+{
+ LogSuppress = lSType;
+}
+#endif
+
+void DebugLogSetLogType(const int dbgtype)
+{
+ switch (dbgtype)
+ {
+ case DEBUGLOG_NO_DEBUG:
+ case DEBUGLOG_SYSLOG_DEBUG:
+ case DEBUGLOG_STDERR_DEBUG:
+ LogMsgType = dbgtype;
+ break;
+ default:
+ Log2(PCSC_LOG_CRITICAL, "unknown log type (%d), using stderr",
+ dbgtype);
+ LogMsgType = DEBUGLOG_STDERR_DEBUG;
+ }
+
+ /* no color under Windows */
+#ifndef WIN32
+ /* log to stderr and stderr is a tty? */
+ if (DEBUGLOG_STDERR_DEBUG == LogMsgType && isatty(fileno(stderr)))
+ {
+ const char *terms[] = { "linux", "xterm", "xterm-color", "Eterm", "rxvt", "rxvt-unicode" };
+ char *term;
+
+ term = getenv("TERM");
+ if (term)
+ {
+ unsigned int i;
+
+ /* for each known color terminal */
+ for (i = 0; i < sizeof(terms) / sizeof(terms[0]); i++)
+ {
+ /* we found a supported term? */
+ if (0 == strcmp(terms[i], term))
+ {
+ LogDoColor = 1;
+ break;
+ }
+ }
+ }
+ }
+#endif
+}
+
+void DebugLogSetLevel(const int level)
+{
+ LogLevel = level;
+ switch (level)
+ {
+ case PCSC_LOG_CRITICAL:
+ case PCSC_LOG_ERROR:
+ /* do not log anything */
+ break;
+
+ case PCSC_LOG_INFO:
+ Log1(PCSC_LOG_INFO, "debug level=notice");
+ break;
+
+ case PCSC_LOG_DEBUG:
+ Log1(PCSC_LOG_DEBUG, "debug level=debug");
+ break;
+
+ default:
+ LogLevel = PCSC_LOG_INFO;
+ Log2(PCSC_LOG_CRITICAL, "unknown level (%d), using level=notice",
+ level);
+ }
+}
+
+INTERNAL int DebugLogSetCategory(const int dbginfo)
+{
+#define DEBUG_INFO_LENGTH 80
+ char text[DEBUG_INFO_LENGTH];
+
+ /* use a negative number to UNset
+ * typically use ~DEBUG_CATEGORY_APDU
+ */
+ if (dbginfo < 0)
+ LogCategory &= dbginfo;
+ else
+ LogCategory |= dbginfo;
+
+ /* set to empty string */
+ text[0] = '\0';
+
+ if (LogCategory & DEBUG_CATEGORY_APDU)
+ strlcat(text, " APDU", sizeof(text));
+
+ Log2(PCSC_LOG_INFO, "Debug options:%s", text);
+
+ return LogCategory;
+}
+
+INTERNAL void DebugLogCategory(const int category, const unsigned char *buffer,
+ const int len)
+{
+ if ((category & DEBUG_CATEGORY_APDU)
+ && (LogCategory & DEBUG_CATEGORY_APDU))
+ log_xxd(PCSC_LOG_INFO, "APDU: ", (const unsigned char *)buffer, len);
+
+ if ((category & DEBUG_CATEGORY_SW)
+ && (LogCategory & DEBUG_CATEGORY_APDU))
+ log_xxd(PCSC_LOG_INFO, "SW: ", (const unsigned char *)buffer, len);
+}
+
+/*
+ * old function supported for backward object code compatibility
+ * defined only for pcscd
+ */
+#ifdef PCSCD
+void debug_msg(const char *fmt, ...)
+{
+ char DebugBuffer[DEBUG_BUF_SIZE];
+ va_list argptr;
+
+ if ((LogSuppress != DEBUGLOG_LOG_ENTRIES)
+ || (DEBUGLOG_NO_DEBUG == LogMsgType))
+ return;
+
+ va_start(argptr, fmt);
+#ifndef WIN32
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+#if HAVE_VSNPRINTF
+ vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
+#else
+ vsprintf(DebugBuffer, fmt, argptr);
+#endif
+#endif
+ va_end(argptr);
+
+#ifndef WIN32
+ if (DEBUGLOG_SYSLOG_DEBUG == LogMsgType)
+ syslog(LOG_INFO, "%s", DebugBuffer);
+ else
+#endif
+ fprintf(stderr, "%s\n", DebugBuffer);
+} /* debug_msg */
+
+void debug_xxd(const char *msg, const unsigned char *buffer, const int len)
+{
+ log_xxd(PCSC_LOG_ERROR, msg, buffer, len);
+} /* debug_xxd */
+#endif
+
+char *pcsc_stringify_error(const int32_t Error)
+{
+
+ static char strError[75];
+
+ switch (Error)
+ {
+ case SCARD_S_SUCCESS:
+ strcpy(strError, "Command successful.");
+ break;
+ case SCARD_E_CANCELLED:
+ strcpy(strError, "Command cancelled.");
+ break;
+ case SCARD_E_CANT_DISPOSE:
+ strcpy(strError, "Cannot dispose handle.");
+ break;
+ case SCARD_E_INSUFFICIENT_BUFFER:
+ strcpy(strError, "Insufficient buffer.");
+ break;
+ case SCARD_E_INVALID_ATR:
+ strcpy(strError, "Invalid ATR.");
+ break;
+ case SCARD_E_INVALID_HANDLE:
+ strcpy(strError, "Invalid handle.");
+ break;
+ case SCARD_E_INVALID_PARAMETER:
+ strcpy(strError, "Invalid parameter given.");
+ break;
+ case SCARD_E_INVALID_TARGET:
+ strcpy(strError, "Invalid target given.");
+ break;
+ case SCARD_E_INVALID_VALUE:
+ strcpy(strError, "Invalid value given.");
+ break;
+ case SCARD_E_NO_MEMORY:
+ strcpy(strError, "Not enough memory.");
+ break;
+ case SCARD_F_COMM_ERROR:
+ strcpy(strError, "RPC transport error.");
+ break;
+ case SCARD_F_INTERNAL_ERROR:
+ strcpy(strError, "Unknown internal error.");
+ break;
+ case SCARD_F_UNKNOWN_ERROR:
+ strcpy(strError, "Unknown internal error.");
+ break;
+ case SCARD_F_WAITED_TOO_LONG:
+ strcpy(strError, "Waited too long.");
+ break;
+ case SCARD_E_UNKNOWN_READER:
+ strcpy(strError, "Unknown reader specified.");
+ break;
+ case SCARD_E_TIMEOUT:
+ strcpy(strError, "Command timeout.");
+ break;
+ case SCARD_E_SHARING_VIOLATION:
+ strcpy(strError, "Sharing violation.");
+ break;
+ case SCARD_E_NO_SMARTCARD:
+ strcpy(strError, "No smartcard inserted.");
+ break;
+ case SCARD_E_UNKNOWN_CARD:
+ strcpy(strError, "Unknown card.");
+ break;
+ case SCARD_E_PROTO_MISMATCH:
+ strcpy(strError, "Card protocol mismatch.");
+ break;
+ case SCARD_E_NOT_READY:
+ strcpy(strError, "Subsystem not ready.");
+ break;
+ case SCARD_E_SYSTEM_CANCELLED:
+ strcpy(strError, "System cancelled.");
+ break;
+ case SCARD_E_NOT_TRANSACTED:
+ strcpy(strError, "Transaction failed.");
+ break;
+ case SCARD_E_READER_UNAVAILABLE:
+ strcpy(strError, "Reader/s is unavailable.");
+ break;
+ case SCARD_W_UNSUPPORTED_CARD:
+ strcpy(strError, "Card is not supported.");
+ break;
+ case SCARD_W_UNRESPONSIVE_CARD:
+ strcpy(strError, "Card is unresponsive.");
+ break;
+ case SCARD_W_UNPOWERED_CARD:
+ strcpy(strError, "Card is unpowered.");
+ break;
+ case SCARD_W_RESET_CARD:
+ strcpy(strError, "Card was reset.");
+ break;
+ case SCARD_W_REMOVED_CARD:
+ strcpy(strError, "Card was removed.");
+ break;
+ case SCARD_W_INSERTED_CARD:
+ strcpy(strError, "Card was inserted.");
+ break;
+ case SCARD_E_UNSUPPORTED_FEATURE:
+ strcpy(strError, "Feature not supported.");
+ break;
+ case SCARD_E_PCI_TOO_SMALL:
+ strcpy(strError, "PCI struct too small.");
+ break;
+ case SCARD_E_READER_UNSUPPORTED:
+ strcpy(strError, "Reader is unsupported.");
+ break;
+ case SCARD_E_DUPLICATE_READER:
+ strcpy(strError, "Reader already exists.");
+ break;
+ case SCARD_E_CARD_UNSUPPORTED:
+ strcpy(strError, "Card is unsupported.");
+ break;
+ case SCARD_E_NO_SERVICE:
+ strcpy(strError, "Service not available.");
+ break;
+ case SCARD_E_SERVICE_STOPPED:
+ strcpy(strError, "Service was stopped.");
+ break;
+ default:
+ sprintf(strError, "Unknown PCSC error: %d [0x%08X]", Error, Error);
+ break;
+
+ };
+
+ return strError;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/debuglog.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * debuglog.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 1999-2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: debuglog.h 2151 2006-09-06 20:02:47Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles debugging.
+ *
+ * @note log message is sent to syslog or stderr depending on --foreground
+ * command line argument
+ *
+ * @test
+ * @code
+ * Log1(priority, "text");
+ * log "text" with priority level priority
+ * Log2(priority, "text: %d", 1234);
+ * log "text: 1234"
+ * the format string can be anything printf() can understand
+ * Log3(priority, "text: %d %d", 1234, 5678);
+ * log "text: 1234 5678"
+ * the format string can be anything printf() can understand
+ * LogXxd(priority, msg, buffer, size);
+ * log "msg" + a hex dump of size bytes of buffer[]
+ * @endcode
+ */
+
+#ifndef __debuglog_h__
+#define __debuglog_h__
+
+#include "pcscexport.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define DEBUGLOG_LOG_ENTRIES 1
+#define DEBUGLOG_IGNORE_ENTRIES 2
+
+enum {
+ DEBUGLOG_NO_DEBUG = 0,
+ DEBUGLOG_SYSLOG_DEBUG,
+ DEBUGLOG_STDERR_DEBUG
+};
+
+#define DEBUG_CATEGORY_NOTHING 0
+#define DEBUG_CATEGORY_APDU 1
+#define DEBUG_CATEGORY_SW 2
+
+enum {
+ PCSC_LOG_DEBUG = 0,
+ PCSC_LOG_INFO,
+ PCSC_LOG_ERROR,
+ PCSC_LOG_CRITICAL
+};
+
+/* You can't do #ifndef __FUNCTION__ */
+#if !defined(__GNUC__) && !defined(__IBMC__)
+#define __FUNCTION__ ""
+#endif
+
+#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
+#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
+#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
+#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
+#define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
+#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8)
+#define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
+
+#define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
+#define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
+#define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
+
+PCSC_API void log_msg(const int priority, const char *fmt, ...);
+PCSC_API void log_xxd(const int priority, const char *msg,
+ const unsigned char *buffer, const int size);
+
+void DebugLogSuppress(const int);
+void DebugLogSetLogType(const int);
+int DebugLogSetCategory(const int);
+void DebugLogCategory(const int, const unsigned char *, const int);
+PCSC_API void DebugLogSetLevel(const int level);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __debuglog_h__ */
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1735 @@
+#define yy_create_buffer bp_create_buffer
+#define yy_delete_buffer bp_delete_buffer
+#define yy_scan_buffer bp_scan_buffer
+#define yy_scan_string bp_scan_string
+#define yy_scan_bytes bp_scan_bytes
+#define yy_flex_debug bp_flex_debug
+#define yy_init_buffer bp_init_buffer
+#define yy_flush_buffer bp_flush_buffer
+#define yy_load_buffer_state bp_load_buffer_state
+#define yy_switch_to_buffer bp_switch_to_buffer
+#define yyin bpin
+#define yyleng bpleng
+#define yylex bplex
+#define yyout bpout
+#define yyrestart bprestart
+#define yytext bptext
+#define yywrap bpwrap
+
+/*
+ * A lexical scanner generated by flex
+ */
+
+/*
+ * Scanner skeleton version: $Header:
+ * /home/cvsroot/muscle/PCSC/src/driverparser.c,v 1.1.1.1 2002/03/30
+ * 18:15:03 corcoran Exp $
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+
+/*
+ * cfront 1.2 defines "c_plusplus" instead of "__cplusplus"
+ */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * Use prototypes in function declarations.
+ */
+#define YY_USE_PROTOS
+
+/*
+ * The "const" storage-class-modifier is valid.
+ */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef __TURBOC__
+#pragma warn -rch
+#pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/*
+ * Returned upon end-of-file.
+ */
+#define YY_NULL 0
+
+/*
+ * Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative, we
+ * want to instead treat it as an 8-bit unsigned char, hence the double
+ * cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/*
+ * Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/*
+ * Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/*
+ * Action number for EOF rule of a given start state.
+ */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/*
+ * Special action meaning "start processing a new file".
+ */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/*
+ * Size of default input buffer.
+ */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/*
+ * The funky do-while in the following #define is used to turn the
+ * definition int a single C statement (which needs a semi-colon
+ * terminator). This avoids problems with code like: if (
+ * condition_holds ) yyless( 5 ); else do_something_else(); Prior to
+ * using the do-while the compiler would get upset at the "else" because
+ * it interpreted the "if" statement as being all done when it reached the
+ * ';' after the yyless() call.
+ */
+
+/*
+ * Return all but the first 'n' matched characters back to the input
+ * stream.
+ */
+
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ *yy_cp = yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/*
+ * The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+struct yy_buffer_state
+{
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /*
+ * Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /*
+ * Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /*
+ * Whether we "own" the buffer - i.e., we know we created it, and can
+ * realloc() it to grow it, and should free() it to delete it.
+ */
+ int yy_is_our_buffer;
+
+ /*
+ * Whether this is an "interactive" input source; if so, and if we're
+ * using stdio for input, then we want to use getc() instead of
+ * fread(), to make sure we stop fetching input after each newline.
+ */
+ int yy_is_interactive;
+
+ /*
+ * Whether we're considered to be at the beginning of a line. If so,
+ * '^' rules will be active on the next match, otherwise not.
+ */
+ int yy_at_bol;
+
+ /*
+ * Whether to try to fill the input buffer when we reach the end of
+ * it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /*
+ * When an EOF's been seen but there's still some text to process then
+ * we mark the buffer as YY_EOF_PENDING, to indicate that we shouldn't
+ * try reading from the input source any more. We might still have a
+ * bunch of tokens to match, though, because of possible backing-up.
+ * When we actually see the EOF, we change the status to "new" (via
+ * yyrestart()), so that the user can continue scanning by just
+ * pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/*
+ * We provide macros for accessing buffer states in case in the future we
+ * want to put the buffer states in a more general "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+/*
+ * yy_hold_char holds the character lost when yytext is formed.
+ */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into
+ * yy_ch_buf */
+
+int yyleng;
+
+/*
+ * Points to current character in buffer.
+ */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/*
+ * Flag which is used to allow yywrap()'s to do buffer switches instead of
+ * setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO((FILE * input_file));
+
+void yy_switch_to_buffer YY_PROTO((YY_BUFFER_STATE new_buffer));
+void yy_load_buffer_state YY_PROTO((void));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO((FILE * file, int size));
+void yy_delete_buffer YY_PROTO((YY_BUFFER_STATE b));
+void yy_init_buffer YY_PROTO((YY_BUFFER_STATE b, FILE * file));
+void yy_flush_buffer YY_PROTO((YY_BUFFER_STATE b));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO((char *base, yy_size_t size));
+YY_BUFFER_STATE yy_scan_string YY_PROTO((yyconst char *yy_str));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO((yyconst char *bytes, int len));
+
+static void *yy_flex_alloc YY_PROTO((yy_size_t));
+static void *yy_flex_realloc YY_PROTO((void *, yy_size_t));
+static void yy_flex_free YY_PROTO((void *));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO((void));
+static yy_state_type yy_try_NUL_trans YY_PROTO((yy_state_type
+ current_state));
+static int yy_get_next_buffer YY_PROTO((void));
+static void yy_fatal_error YY_PROTO((yyconst char msg[]));
+
+/*
+ * Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 7
+#define YY_END_OF_BUFFER 8
+static yyconst short int yy_accept[39] = { 0,
+ 0, 0, 8, 6, 4, 2, 1, 6, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
+ 0, 0, 0, 0, 0, 0, 5, 0
+};
+
+static yyconst int yy_ec[256] = { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 4, 4, 5, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 6, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 4, 1, 8,
+ 4, 9, 4, 4, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 1, 1, 1, 4, 4, 1, 11, 11, 11, 11,
+
+ 12, 11, 13, 11, 14, 11, 15, 11, 11, 16,
+ 11, 11, 11, 17, 18, 19, 11, 11, 11, 11,
+ 20, 11, 1, 1, 1, 4, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+};
+
+static yyconst int yy_meta[21] = { 0,
+ 1, 2, 3, 4, 4, 4, 2, 1, 1, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
+};
+
+static yyconst short int yy_base[43] = { 0,
+ 0, 7, 49, 50, 50, 50, 0, 1, 0, 36,
+ 28, 26, 28, 35, 29, 0, 26, 33, 27, 33,
+ 29, 22, 0, 24, 27, 14, 27, 23, 13, 50,
+ 10, 9, 4, 1, 0, 2, 50, 50, 19, 23,
+ 2, 26
+};
+
+static yyconst short int yy_def[43] = { 0,
+ 39, 39, 38, 38, 38, 38, 40, 38, 40, 38,
+ 38, 38, 38, 38, 38, 41, 38, 41, 38, 38,
+ 38, 38, 42, 38, 42, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 0, 38, 38,
+ 38, 38
+};
+
+static yyconst short int yy_nxt[71] = { 0,
+ 38, 5, 6, 18, 7, 38, 38, 8, 5, 6,
+ 37, 7, 36, 38, 8, 10, 35, 34, 11, 4,
+ 4, 4, 4, 9, 9, 33, 9, 25, 32, 25,
+ 31, 30, 29, 28, 27, 26, 24, 23, 22, 21,
+ 20, 19, 17, 16, 15, 14, 13, 12, 38, 3,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38
+};
+
+static yyconst short int yy_chk[71] = { 0,
+ 0, 1, 1, 41, 1, 0, 0, 1, 2, 2,
+ 36, 2, 35, 0, 2, 8, 34, 33, 8, 39,
+ 39, 39, 39, 40, 40, 32, 40, 42, 31, 42,
+ 29, 28, 27, 26, 25, 24, 22, 21, 20, 19,
+ 18, 17, 15, 14, 13, 12, 11, 10, 3, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38
+};
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/*
+ * The intent behind this definition is that it'll catch any uses of
+ * REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "bundleparser.l"
+#define INITIAL 0
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+#line 14 "bundleparser.l"
+
+void evalToken(char *pcToken, int tokType);
+
+static char *pcDesiredKey = 0;
+static char pcKey[200];
+static char pcValue[200];
+static char pcFinValue[200];
+
+void errorCheck(char *pcToken_error);
+
+#line 427 "lex.bp.c"
+
+/*
+ * Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO((void));
+#else
+extern int yywrap YY_PROTO((void));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO((int c, char *buf_ptr));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO((char *, yyconst char *, int));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO((yyconst char *));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO((void));
+#else
+static int input YY_PROTO((void));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO((int new_state));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO((void));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO((void));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/*
+ * Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/*
+ * Amount of stuff to slurp up with each read.
+ */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/*
+ * Copy whatever the last rule matched to the standard output.
+ */
+
+#ifndef ECHO
+/*
+ * This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/*
+ * Gets input and stuffs it into "buf". number of characters read, or
+ * YY_NULL, is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+ && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/*
+ * No semi-colon after return; correct usage is to write "yyterminate();"
+ * - we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/*
+ * Number of entries by which start-condition stack grows.
+ */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/*
+ * Report a fatal error.
+ */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/*
+ * Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/*
+ * Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/*
+ * Code executed at the end of each rule.
+ */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 26 "bundleparser.l"
+
+#line 581 "lex.bp.c"
+
+ if (yy_init)
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if (!yy_start)
+ yy_start = 1; /* first start state */
+
+ if (!yyin)
+ yyin = stdin;
+
+ if (!yyout)
+ yyout = stdout;
+
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_load_buffer_state();
+ }
+
+ while (1) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /*
+ * Support of yytext.
+ */
+ *yy_cp = yy_hold_char;
+
+ /*
+ * yy_bp points to the position in yy_ch_buf of the start of the
+ * current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+ yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while (yy_base[yy_current_state] != 50);
+
+ yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if (yy_act == 0)
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+ do_action: /* This label is used only to access EOF actions. */
+
+ switch (yy_act)
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /*
+ * undo the effects of YY_DO_BEFORE_ACTION
+ */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+ case 1:
+ YY_RULE_SETUP
+#line 28 "bundleparser.l"
+ {
+ }
+ YY_BREAK case 2:
+ YY_RULE_SETUP
+#line 29 "bundleparser.l"
+ {
+ }
+ YY_BREAK case 3:
+ YY_RULE_SETUP
+#line 30 "bundleparser.l"
+ {
+ evalToken(bptext, 1);
+ }
+ YY_BREAK case 4:
+ YY_RULE_SETUP
+#line 31 "bundleparser.l"
+ {
+ }
+ YY_BREAK case 5:
+ YY_RULE_SETUP
+#line 32 "bundleparser.l"
+ {
+ evalToken(bptext, 2);
+ }
+ YY_BREAK case 6:
+ YY_RULE_SETUP
+#line 33 "bundleparser.l"
+ {
+ errorCheck(bptext);
+ }
+ YY_BREAK case 7:
+ YY_RULE_SETUP
+#line 34 "bundleparser.l"
+ ECHO;
+ YY_BREAK
+#line 699 "lex.bp.c"
+ case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /*
+ * Amount of text matched not including the EOB char.
+ */
+ int yy_amount_of_matched_text =
+ (int) (yy_cp - yytext_ptr) - 1;
+
+ /*
+ * Undo the effects of YY_DO_BEFORE_ACTION.
+ */
+ *yy_cp = yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+ if (yy_current_buffer->yy_buffer_status ==
+ YY_BUFFER_NEW)
+ {
+ /*
+ * We're scanning a new file or input source. It's
+ * possible that this happened because the user just
+ * pointed yyin at a new source and called yylex().
+ * If so, then we have to assure consistency between
+ * yy_current_buffer and our globals. Here is the
+ * right place to do so, because this is the first
+ * action (other than possibly a back-up) that will
+ * match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /*
+ * Note that here we test for yy_c_buf_p "<=" to the
+ * position of the first EOB in the buffer, since
+ * yy_c_buf_p will already have been incremented past the
+ * NUL character (since all states make transitions on EOB
+ * to the end-of-buffer state). Contrast this with the
+ * test in input().
+ */
+ if (yy_c_buf_p <=
+ &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /*
+ * Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it for us
+ * because it doesn't know how to deal with the
+ * possibility of jamming (and we don't want to build
+ * jamming into it because then it will run more
+ * slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans(yy_current_state);
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if (yy_next_state)
+ {
+ /*
+ * Consume the NUL.
+ */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if (yywrap())
+ {
+ /*
+ * Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up yy_c_buf_p so
+ * that if some total hoser (like flex
+ * itself) wants to call the scanner after
+ * we return the YY_NULL, it'll still work
+ * - another YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--no action found");
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/*
+ * yy_get_next_buffer - try to read in a new buffer Returns a code
+ * representing an action: EOB_ACT_LAST_MATCH - EOB_ACT_CONTINUE_SCAN -
+ * continue scanning from current position EOB_ACT_END_OF_FILE - end of
+ * file
+ */
+
+static int yy_get_next_buffer()
+{
+ register char *dest = yy_current_buffer->yy_ch_buf;
+ register char *source = yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if (yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1])
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--end of buffer missed");
+
+ if (yy_current_buffer->yy_fill_buffer == 0)
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if (yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1)
+ {
+ /*
+ * We matched a single character, the EOB, so treat this as a
+ * final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /*
+ * We matched some text prior to the EOB, first process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /*
+ * Try to read more data.
+ */
+
+ /*
+ * First move last chars to start of buffer.
+ */
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+ for (i = 0; i < number_to_move; ++i)
+ *(dest++) = *(source++);
+
+ if (yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING)
+ /*
+ * don't do the read, it's not guaranteed to return an EOF, just
+ * force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while (num_to_read <= 0)
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR
+ ("input buffer overflow, can't enlarge buffer because scanner uses REJECT");
+#else
+
+ /*
+ * just a shorter name for the current buffer
+ */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset = (int) (yy_c_buf_p - b->yy_ch_buf);
+
+ if (b->yy_is_our_buffer)
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if (new_size <= 0)
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /*
+ * Include room in for 2 EOB chars.
+ */
+ yy_flex_realloc((void *) b->yy_ch_buf,
+ b->yy_buf_size + 2);
+ } else
+ /*
+ * Can't grow it, we don't own it.
+ */
+ b->yy_ch_buf = 0;
+
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR
+ ("fatal error - scanner input buffer overflow");
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if (num_to_read > YY_READ_BUF_SIZE)
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /*
+ * Read in more data.
+ */
+ YY_INPUT((&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read);
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if (yy_n_chars == 0)
+ {
+ if (number_to_move == YY_MORE_ADJ)
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart(yyin);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/*
+ * yy_get_previous_state - get the state just before the EOB char was
+ * reached
+ */
+
+static yy_state_type yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for (yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp)
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/*
+ * yy_try_NUL_trans - try to make a transition on the NUL character
+ * synopsis next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state)
+#else
+static yy_state_type yy_try_NUL_trans(yy_current_state)
+ yy_state_type yy_current_state;
+#endif
+{
+ register int yy_is_jam;
+ register char *yy_cp = yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 38);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput(int c, register char *yy_bp)
+#else
+static void yyunput(c, yy_bp)
+ int c;
+ register char *yy_bp;
+#endif
+{
+ register char *yy_cp = yy_c_buf_p;
+
+ /*
+ * undo effects of setting up yytext
+ */
+ *yy_cp = yy_hold_char;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ { /* need to shift things up to make room */
+ /*
+ * +2 for EOB chars.
+ */
+ register int number_to_move = yy_n_chars + 2;
+ register char *dest =
+ &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size +
+ 2];
+ register char *source =
+ &yy_current_buffer->yy_ch_buf[number_to_move];
+
+ while (source > yy_current_buffer->yy_ch_buf)
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ yy_current_buffer->yy_n_chars =
+ yy_n_chars = yy_current_buffer->yy_buf_size;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ YY_FATAL_ERROR("flex scanner push-back overflow");
+ }
+
+ *--yy_cp = (char) c;
+
+ yytext_ptr = yy_bp;
+ yy_hold_char = *yy_cp;
+ yy_c_buf_p = yy_cp;
+}
+#endif /* ifndef YY_NO_UNPUT */
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+{
+ int c;
+
+ *yy_c_buf_p = yy_hold_char;
+
+ if (*yy_c_buf_p == YY_END_OF_BUFFER_CHAR)
+ {
+ /*
+ * yy_c_buf_p now points to the character we want to return. If
+ * this occurs *before* the EOB characters, then it's a valid NUL;
+ * if not, then we've hit the end of the buffer.
+ */
+ if (yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ /*
+ * This was really a NUL.
+ */
+ *yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yy_c_buf_p - yytext_ptr;
+ ++yy_c_buf_p;
+
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_LAST_MATCH:
+ /*
+ * This happens because yy_g_n_b() sees that we've
+ * accumulated a token and flags that we need to try
+ * matching the token before proceeding. But for input(),
+ * there's no matching to consider. So convert the
+ * EOB_ACT_LAST_MATCH to EOB_ACT_END_OF_FILE.
+ */
+
+ /*
+ * Reset buffer status.
+ */
+ yyrestart(yyin);
+
+ /*
+ * fall through
+ */
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if (yywrap())
+ return EOF;
+
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p = yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
+ *yy_c_buf_p = '\0'; /* preserve yytext */
+ yy_hold_char = *++yy_c_buf_p;
+
+ return c;
+}
+
+#ifdef YY_USE_PROTOS
+void yyrestart(FILE * input_file)
+#else
+void yyrestart(input_file)
+ FILE *input_file;
+#endif
+{
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_init_buffer(yy_current_buffer, input_file);
+ yy_load_buffer_state();
+}
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer)
+#else
+void yy_switch_to_buffer(new_buffer)
+ YY_BUFFER_STATE new_buffer;
+#endif
+{
+ if (yy_current_buffer == new_buffer)
+ return;
+
+ if (yy_current_buffer)
+ {
+ /*
+ * Flush out information for old buffer.
+ */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /*
+ * We don't actually know whether we did this switch during EOF
+ * (yywrap()) processing, but the only time this flag is looked at is
+ * after yywrap() is called, so it's safe to go ahead and always set
+ * it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state(void)
+#else
+void yy_load_buffer_state()
+#endif
+{
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+}
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer(FILE * file, int size)
+#else
+YY_BUFFER_STATE yy_create_buffer(file, size)
+ FILE *file;
+ int size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_buf_size = size;
+
+ /*
+ * yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yy_flex_alloc(b->yy_buf_size + 2);
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer(b, file);
+
+ return b;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer(YY_BUFFER_STATE b)
+#else
+void yy_delete_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+{
+ if (!b)
+ return;
+
+ if (b == yy_current_buffer)
+ yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+ if (b->yy_is_our_buffer)
+ yy_flex_free((void *) b->yy_ch_buf);
+
+ yy_flex_free((void *) b);
+}
+
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO((int));
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer(YY_BUFFER_STATE b, FILE * file)
+#else
+void yy_init_buffer(b, file)
+ YY_BUFFER_STATE b;
+ FILE *file;
+#endif
+
+{
+ yy_flush_buffer(b);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = 0;
+#else
+ b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0;
+#endif
+#endif
+}
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer(YY_BUFFER_STATE b)
+#else
+void yy_flush_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+
+{
+ if (!b)
+ return;
+
+ b->yy_n_chars = 0;
+
+ /*
+ * We always need two end-of-buffer characters. The first causes a
+ * transition to the end-of-buffer state. The second causes a jam in
+ * that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if (b == yy_current_buffer)
+ yy_load_buffer_state();
+}
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size)
+#else
+YY_BUFFER_STATE yy_scan_buffer(base, size)
+ char *base;
+ yy_size_t size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ if (size < 2 ||
+ base[size - 2] != YY_END_OF_BUFFER_CHAR ||
+ base[size - 1] != YY_END_OF_BUFFER_CHAR)
+ /*
+ * They forgot to leave room for the EOB's.
+ */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()");
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer(b);
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string(yyconst char *yy_str)
+#else
+YY_BUFFER_STATE yy_scan_string(yy_str)
+ yyconst char *yy_str;
+#endif
+{
+ int len;
+ for (len = 0; yy_str[len]; ++len)
+ ;
+
+ return yy_scan_bytes(yy_str, len);
+}
+#endif
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes(yyconst char *bytes, int len)
+#else
+YY_BUFFER_STATE yy_scan_bytes(bytes, len)
+ yyconst char *bytes;
+ int len;
+#endif
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /*
+ * Get memory for full buffer, including space for trailing EOB's.
+ */
+ n = len + 2;
+ buf = (char *) yy_flex_alloc(n);
+ if (!buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()");
+
+ for (i = 0; i < len; ++i)
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer(buf, n);
+ if (!b)
+ YY_FATAL_ERROR("bad buffer in yy_scan_bytes()");
+
+ /*
+ * It's okay to grow etc. this buffer, and we should throw it away
+ * when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state(int new_state)
+#else
+static void yy_push_state(new_state)
+ int new_state;
+#endif
+{
+ if (yy_start_stack_ptr >= yy_start_stack_depth)
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof(int);
+
+ if (!yy_start_stack)
+ yy_start_stack = (int *) yy_flex_alloc(new_size);
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size);
+
+ if (!yy_start_stack)
+ YY_FATAL_ERROR
+ ("out of memory expanding start-condition stack");
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+}
+#endif
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+{
+ if (--yy_start_stack_ptr < 0)
+ YY_FATAL_ERROR("start-condition stack underflow");
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+}
+#endif
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+{
+ return yy_start_stack[yy_start_stack_ptr - 1];
+}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error(yyconst char msg[])
+#else
+static void yy_fatal_error(msg)
+ char msg[];
+#endif
+{
+ (void) fprintf(stderr, "%s\n", msg);
+ exit(YY_EXIT_FAILURE);
+}
+
+/*
+ * Redefine yyless() so it works in section 3 code.
+ */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ yytext[yyleng] = yy_hold_char; \
+ yy_c_buf_p = yytext + n; \
+ yy_hold_char = *yy_c_buf_p; \
+ *yy_c_buf_p = '\0'; \
+ yyleng = n; \
+ } \
+ while ( 0 )
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy(char *s1, yyconst char *s2, int n)
+#else
+static void yy_flex_strncpy(s1, s2, n)
+ char *s1;
+ yyconst char *s2;
+ int n;
+#endif
+{
+ register int i;
+ for (i = 0; i < n; ++i)
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen(yyconst char *s)
+#else
+static int yy_flex_strlen(s)
+ yyconst char *s;
+#endif
+{
+ register int n;
+ for (n = 0; s[n]; ++n)
+ ;
+
+ return n;
+}
+#endif
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc(yy_size_t size)
+#else
+static void *yy_flex_alloc(size)
+ yy_size_t size;
+#endif
+{
+ return (void *) malloc(size);
+}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc(void *ptr, yy_size_t size)
+#else
+static void *yy_flex_realloc(ptr, size)
+ void *ptr;
+ yy_size_t size;
+#endif
+{
+ /*
+ * The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those that use
+ * void* generic pointers. It works with the latter because both ANSI
+ * C and C++ allow castless assignment from any pointer type to void*,
+ * and deal with argument conversions as though doing an assignment.
+ */
+ return (void *) realloc((char *) ptr, size);
+}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free(void *ptr)
+#else
+static void yy_flex_free(ptr)
+ void *ptr;
+#endif
+{
+ free(ptr);
+}
+
+#if YY_MAIN
+int main()
+{
+ yylex();
+ return 0;
+}
+#endif
+#line 34 "bundleparser.l"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "wintypes.h"
+#include "debuglog.h"
+
+int bpwrap()
+{
+ return 1;
+}
+
+void evalToken(char *pcToken, int tokType)
+{
+
+ int len;
+ len = 0;
+
+ if (tokType == 1)
+ {
+ for (len = 5; pcToken[len] != '<'; len++) ;
+ strncpy(pcKey, &pcToken[5], len - 5);
+ pcKey[len - 5] = 0;
+ }
+
+ if (tokType == 2)
+ {
+ for (len = 8; pcToken[len] != '<'; len++) ;
+ strncpy(pcValue, &pcToken[8], len - 8);
+ pcValue[len - 8] = 0;
+ if (strcmp(pcKey, pcDesiredKey) == 0)
+ {
+ strcpy(pcFinValue, pcValue);
+ }
+ }
+
+}
+
+void errorCheck(char *token_error)
+{
+}
+
+int LCFBundleFindValueWithKey(char *fileName, char *tokenKey,
+ char *tokenValue)
+{
+
+ FILE *file;
+ file = 0;
+
+ pcDesiredKey = tokenKey;
+ pcFinValue[0] = 0;
+
+ file = fopen(fileName, "r");
+
+ if (!file)
+ {
+ DebugLogB("Could not open bundle file : %s", fileName);
+ return 1;
+ }
+
+ bpin = file;
+
+ do
+ {
+ bplex();
+ }
+ while (!feof(file));
+
+ if (pcFinValue[0] == 0)
+ {
+ DebugLogB("Value/Key not defined for: %s", tokenKey);
+ fclose(file);
+ return -1;
+ } else
+ {
+ strcpy(tokenValue, pcFinValue);
+ fclose(file);
+ return 0;
+ }
+
+ fclose(file);
+ return 0;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.l
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.l (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/driverparser.l 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,108 @@
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+
+%{
+
+void evalToken( char *pcToken, int tokType );
+
+static char *pcDesiredKey = 0;
+static char pcKey[200];
+static char pcValue[200];
+static char pcFinValue[200];
+
+void errorCheck ( char *pcToken_error );
+
+%}
+
+%%
+
+#.* {}
+"\n" {}
+\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { evalToken(bptext, 1); }
+[ \t] {}
+\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> { evalToken(bptext, 2); }
+. { errorCheck( bptext ); }
+%%
+
+#include <stdio.h>
+#include <string.h>
+
+#include "wintypes.h"
+#include "debuglog.h"
+
+int bpwrap() {
+ return 1;
+}
+
+
+void evalToken( char *pcToken, int tokType ) {
+
+ int len;
+ len = 0;
+
+ if ( tokType == 1 ) {
+ for (len=5; pcToken[len] != '<'; len++);
+ strncpy(pcKey, &pcToken[5], len - 5);
+ pcKey[len-5] = 0;
+ }
+
+ if ( tokType == 2 ) {
+ for (len=8; pcToken[len] != '<'; len++);
+ strncpy(pcValue, &pcToken[8], len - 8);
+ pcValue[len-8] = 0;
+ if ( strcmp(pcKey, pcDesiredKey) == 0 ) {
+ strcpy(pcFinValue, pcValue);
+ }
+ }
+
+
+}
+
+void errorCheck ( char *token_error ) { }
+
+int LCFBundleFindValueWithKey(char *fileName, char *tokenKey,
+ char *tokenValue ) {
+
+ FILE *file;
+ file = 0;
+
+ pcDesiredKey = tokenKey;
+ pcFinValue[0] = 0;
+
+ file = fopen(fileName, "r");
+
+ if (!file) {
+ DebugLogB( "Could not open bundle file : %s", fileName );
+ return 1;
+ }
+
+ bpin = file;
+
+ do {
+ bplex();
+ }
+ while (!feof(file));
+
+ if ( pcFinValue[0] == 0 ) {
+ DebugLogB( "Value/Key not defined for: %s", tokenKey );
+ fclose(file);
+ return -1;
+ } else {
+ strcpy(tokenValue, pcFinValue);
+ fclose(file);
+ return 0;
+ }
+
+ fclose(file);
+ return 0;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_generic.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_generic.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_generic.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : dyn_generic.h
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 8/12/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This abstracts dynamic library loading
+ functions.
+
+********************************************************************/
+
+#ifndef __dyn_generic_h__
+#define __dyn_generic_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ int DYN_LoadLibrary(void **, char *);
+ int DYN_CloseLibrary(void **);
+ int DYN_GetAddress(void *, void **, char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_macosx.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_macosx.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/dyn_macosx.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : dyn_macosx.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 3/15/00
+ License: Copyright (C) 2000 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This abstracts dynamic library loading
+ functions and timing.
+
+********************************************************************/
+
+#include <CoreFoundation/CFBundle.h>
+#include <CoreFoundation/CFString.h>
+#include <CoreFoundation/CFURL.h>
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "dyn_generic.h"
+#include "debuglog.h"
+
+/*
+ * / Load a module (if needed)
+ */
+int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
+{
+
+ CFStringRef bundlePath;
+ CFURLRef bundleURL;
+ CFBundleRef bundle;
+
+ *pvLHandle = 0;
+
+ /*
+ * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
+ */
+
+ bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
+ kCFStringEncodingMacRoman);
+ if (bundlePath == NULL)
+ {
+ return SCARD_E_NO_MEMORY;
+
+ } else
+ {
+ }
+
+ bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
+ kCFURLPOSIXPathStyle, TRUE);
+ CFRelease(bundlePath);
+ if (bundleURL == NULL)
+ {
+ return SCARD_E_NO_MEMORY;
+ } else
+ {
+ }
+
+ bundle = CFBundleCreate(NULL, bundleURL);
+ CFRelease(bundleURL);
+ if (bundle == NULL)
+ {
+ return SCARD_F_UNKNOWN_ERROR;
+ } else
+ {
+ }
+
+ if (!CFBundleLoadExecutable(bundle))
+ {
+ CFRelease(bundle);
+ return SCARD_F_UNKNOWN_ERROR;
+ } else
+ {
+ }
+
+ *pvLHandle = (void *) bundle;
+
+ return SCARD_S_SUCCESS;
+}
+
+int DYN_CloseLibrary(void **pvLHandle)
+{
+
+ CFBundleRef bundle = (CFBundleRef) * pvLHandle;
+
+ if (CFBundleIsExecutableLoaded(bundle) == TRUE)
+ {
+ CFBundleUnloadExecutable(bundle);
+ CFRelease(bundle);
+ } else
+ {
+ DebugLogA("DYN_CloseLibrary: Cannot unload library.");
+ }
+
+ *pvLHandle = 0;
+ return SCARD_S_SUCCESS;
+}
+
+int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
+{
+
+ CFBundleRef bundle = (CFBundleRef) pvLHandle;
+ CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
+ kCFStringEncodingMacRoman);
+ if (cfName == NULL)
+ return SCARD_E_NO_MEMORY;
+
+ *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
+ CFRelease(cfName);
+ if (*pvFHandle == NULL)
+ return SCARD_F_UNKNOWN_ERROR;
+
+ return SCARD_S_SUCCESS;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,550 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : eventhandler.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 3/13/00
+ License: Copyright (C) 2000 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This keeps track of card insertion/removal events
+ and updates ATR, protocol, and status information.
+
+********************************************************************/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "thread_generic.h"
+#include "readerfactory.h"
+#include "eventhandler.h"
+#include "dyn_generic.h"
+#include "sys_generic.h"
+#include "ifdhandler.h"
+#include "ifdwrapper.h"
+#include "debuglog.h"
+#include "prothandler.h"
+
+#include <security_utilities/debugging.h>
+
+static PREADER_STATES readerStates[PCSCLITE_MAX_CONTEXTS];
+
+void EHStatusHandlerThread(PREADER_CONTEXT);
+
+LONG EHInitializeEventStructures()
+{
+
+ int fd, i, pageSize;
+
+ fd = 0;
+ i = 0;
+ pageSize = 0;
+
+ SYS_RemoveFile(PCSCLITE_PUBSHM_FILE);
+
+ fd = SYS_OpenFile(PCSCLITE_PUBSHM_FILE, O_RDWR | O_CREAT, 00644);
+ if (fd < 0)
+ {
+ DebugLogA("Error: Cannot open public shared file");
+ exit(1);
+ }
+
+ SYS_Chmod(PCSCLITE_PUBSHM_FILE,
+ S_IRGRP | S_IREAD | S_IWRITE | S_IROTH);
+
+ pageSize = SYS_GetPageSize();
+
+ /*
+ * Jump to end of file space and allocate zero's
+ */
+ SYS_SeekFile(fd, pageSize * PCSCLITE_MAX_CONTEXTS);
+ SYS_WriteFile(fd, "", 1);
+
+ /*
+ * Allocate each reader structure
+ */
+ for (i = 0; i < PCSCLITE_MAX_CONTEXTS; i++)
+ {
+ readerStates[i] = (PREADER_STATES)
+ SYS_MemoryMap(sizeof(READER_STATES), fd, (i * pageSize));
+ if (readerStates[i] == 0)
+ {
+ DebugLogA("Error: Cannot public memory map");
+ exit(1);
+ }
+
+ /*
+ * Zero out each value in the struct
+ */
+ memset((readerStates[i])->readerName, 0, MAX_READERNAME);
+ memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
+ (readerStates[i])->readerID = 0;
+ (readerStates[i])->readerState = 0;
+ (readerStates[i])->lockState = 0;
+ (readerStates[i])->readerSharing = 0;
+ (readerStates[i])->cardAtrLength = 0;
+ (readerStates[i])->cardProtocol = 0;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG EHDestroyEventHandler(PREADER_CONTEXT rContext)
+{
+
+ LONG rv;
+ int i;
+
+ i = 0;
+ rv = 0;
+
+
+ i = rContext->dwPublicID;
+ if ((readerStates[i])->readerName[0] == 0)
+ {
+ DebugLogA("EHDestroyEventHandler: Thread already stomped.");
+ return SCARD_S_SUCCESS;
+ }
+
+ /*
+ * Set the thread to 0 to exit thread
+ */
+ rContext->dwLockId = 0xFFFF;
+
+ DebugLogA("EHDestroyEventHandler: Stomping thread.");
+
+ do
+ {
+ /*
+ * Wait 0.05 seconds for the child to respond
+ */
+ SYS_USleep(50000);
+ }
+ while (rContext->dwLockId == 0xFFFF);
+
+ /*
+ * Zero out the public status struct to allow it to be recycled and
+ * used again
+ */
+
+ memset((readerStates[i])->readerName, 0, MAX_READERNAME);
+ memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
+ (readerStates[i])->readerID = 0;
+ (readerStates[i])->readerState = 0;
+ (readerStates[i])->lockState = 0;
+ (readerStates[i])->readerSharing = 0;
+ (readerStates[i])->cardAtrLength = 0;
+ (readerStates[i])->cardProtocol = 0;
+
+ SYS_MMapSynchronize((void *) readerStates[i], SYS_GetPageSize());
+
+ /* Zero the thread */
+ rContext->pthThread = 0;
+
+ DebugLogA("EHDestroyEventHandler: Thread stomped.");
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG EHSpawnEventHandler(PREADER_CONTEXT rContext)
+{
+ LONG rv;
+ LPCSTR lpcReader;
+ DWORD dwStatus, dwProtocol;
+ int i;
+
+ /*
+ * Zero out everything
+ */
+ rv = 0;
+ lpcReader = 0;
+ dwStatus = 0;
+ dwProtocol = 0;
+ i = 0;
+
+ lpcReader = rContext->lpcReader;
+
+ rv = IFDStatusICC(rContext, &dwStatus,
+ &dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ DebugLogB("EHSpawnEventHandler: Initial Check Failed on %s",
+ lpcReader);
+ return SCARD_F_UNKNOWN_ERROR;
+ }
+
+ /*
+ * Find an empty reader slot and insert the new reader
+ */
+ for (i = 0; i < PCSCLITE_MAX_CONTEXTS; i++)
+ {
+ if ((readerStates[i])->readerID == 0)
+ {
+ break;
+ }
+ }
+
+ if (i == PCSCLITE_MAX_CONTEXTS)
+ {
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ /*
+ * Set all the attributes to this reader
+ */
+ strcpy((readerStates[i])->readerName, rContext->lpcReader);
+ memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
+ rContext->dwAtrLen);
+ (readerStates[i])->readerID = htonl(i + 100);
+ (readerStates[i])->readerState = htonl(rContext->dwStatus);
+ (readerStates[i])->readerSharing = htonl(rContext->dwContexts);
+ (readerStates[i])->cardAtrLength = htonl(rContext->dwAtrLen);
+ (readerStates[i])->cardProtocol = htonl(rContext->dwProtocol);
+ /*
+ * So the thread can access this array indice
+ */
+ rContext->dwPublicID = i;
+
+ rv = SYS_ThreadCreate(&rContext->pthThread, NULL,
+ (LPVOID) EHStatusHandlerThread, (LPVOID) rContext);
+ secdebug("pcscd", "EHSpawnEventHandler after thread create: %d [%04X]", rv, rv);
+ if (rv == 1)
+ {
+ return SCARD_S_SUCCESS;
+ } else
+ {
+ return SCARD_E_NO_MEMORY;
+ }
+
+}
+
+void EHStatusHandlerThread(PREADER_CONTEXT rContext)
+{
+
+ LONG rv;
+ LPCSTR lpcReader;
+ DWORD dwStatus, dwProtocol, dwReaderSharing;
+ DWORD dwErrorCount, dwCurrentState;
+ int i, pageSize;
+
+ /*
+ * Zero out everything
+ */
+ rv = 0;
+ lpcReader = 0;
+ dwStatus = 0;
+ dwProtocol = 0;
+ dwReaderSharing = 0;
+ dwCurrentState = 0;
+ dwErrorCount = 0;
+ i = 0;
+ pageSize = 0;
+
+ lpcReader = rContext->lpcReader;
+ i = rContext->dwPublicID;
+
+ pageSize = SYS_GetPageSize();
+
+ rv = IFDStatusICC(rContext, &dwStatus,
+ &dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
+ secdebug("pcscd", "EHStatusHandlerThread: initial call to IFDStatusICC: %d [%04X]", rv, rv);
+
+ if (dwStatus & SCARD_PRESENT)
+ {
+ rv = IFDPowerICC(rContext, IFD_POWER_UP,
+ rContext->ucAtr, &rContext->dwAtrLen);
+ secdebug("pcscd", "EHStatusHandlerThread: initial call to IFDPowerICC: %d [%04X]", rv, rv);
+
+ if (rv == IFD_SUCCESS)
+ {
+ rContext->dwProtocol = PHGetDefaultProtocol(rContext->ucAtr,
+ rContext->dwAtrLen);
+ rContext->dwStatus |= SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_ABSENT;
+ rContext->dwStatus |= SCARD_POWERED;
+ rContext->dwStatus |= SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_SWALLOWED;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ } else
+ {
+ rContext->dwStatus |= SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_ABSENT;
+ rContext->dwStatus |= SCARD_SWALLOWED;
+ rContext->dwStatus &= ~SCARD_POWERED;
+ rContext->dwStatus &= ~SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ rContext->dwProtocol = 0;
+ rContext->dwAtrLen = 0;
+ }
+
+ dwCurrentState = SCARD_PRESENT;
+
+ } else
+ {
+ dwCurrentState = SCARD_ABSENT;
+ rContext->dwStatus |= SCARD_ABSENT;
+ rContext->dwStatus &= ~SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_POWERED;
+ rContext->dwStatus &= ~SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_SWALLOWED;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ rContext->dwAtrLen = 0;
+ rContext->dwProtocol = 0;
+ }
+
+ /*
+ * Set all the public attributes to this reader
+ */
+ (readerStates[i])->readerState = htonl(rContext->dwStatus);
+ (readerStates[i])->cardAtrLength = htonl(rContext->dwAtrLen);
+ (readerStates[i])->cardProtocol = htonl(rContext->dwProtocol);
+ dwReaderSharing = rContext->dwContexts;
+ (readerStates[i])->readerSharing = htonl(dwReaderSharing);
+ memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
+ rContext->dwAtrLen);
+
+ SYS_MMapSynchronize((void *) readerStates[i], pageSize);
+
+ while (1)
+ {
+
+ dwStatus = 0;
+
+ rv = IFDStatusICC(rContext, &dwStatus,
+ &dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
+// secdebug("pcscd", "EHStatusHandlerThread: loop call to IFDStatusICC: %d [%04X]", rv, rv);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ DebugLogB("EHSpawnEventHandler: Error communicating to: %s",
+ lpcReader);
+
+ /*
+ * Set error status on this reader while errors occur
+ */
+
+ rContext->dwStatus &= ~SCARD_ABSENT;
+ rContext->dwStatus &= ~SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_POWERED;
+ rContext->dwStatus &= ~SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_SWALLOWED;
+ rContext->dwStatus |= SCARD_UNKNOWN;
+ rContext->dwAtrLen = 0;
+ rContext->dwProtocol = 0;
+
+ dwCurrentState = SCARD_UNKNOWN;
+
+ /*
+ * Set all the public attributes to this reader
+ */
+ (readerStates[i])->readerState = htonl(rContext->dwStatus);
+ (readerStates[i])->cardAtrLength = htonl(rContext->dwAtrLen);
+ (readerStates[i])->cardProtocol = htonl(rContext->dwProtocol);
+ memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
+ rContext->dwAtrLen);
+ SYS_MMapSynchronize((void *) readerStates[i], pageSize);
+
+ /*
+ * This code causes race conditions on G4's with USB
+ * insertion
+ */
+ /*
+ * dwErrorCount += 1; SYS_Sleep(1);
+ */
+ /*
+ * After 10 seconds of errors, try to reinitialize the reader
+ * This sometimes helps bring readers out of *crazy* states.
+ */
+ /*
+ * if ( dwErrorCount == 10 ) { RFUnInitializeReader( rContext
+ * ); RFInitializeReader( rContext ); dwErrorCount = 0; }
+ */
+
+ /*
+ * End of race condition code block
+ */
+
+ }
+
+ if (dwStatus & SCARD_ABSENT)
+ {
+ if (dwCurrentState == SCARD_PRESENT ||
+ dwCurrentState == SCARD_UNKNOWN)
+ {
+
+ /*
+ * Change the status structure
+ */
+ DebugLogB("EHSpawnEventHandler: Card Removed From %s",
+ lpcReader);
+ /*
+ * Notify the card has been removed
+ */
+ RFSetReaderEventState(rContext, SCARD_REMOVED);
+
+ rContext->dwAtrLen = 0;
+ rContext->dwProtocol = 0;
+ rContext->dwStatus |= SCARD_ABSENT;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ rContext->dwStatus &= ~SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_POWERED;
+ rContext->dwStatus &= ~SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SWALLOWED;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ dwCurrentState = SCARD_ABSENT;
+
+ /*
+ * Set all the public attributes to this reader
+ */
+ (readerStates[i])->readerState = htonl(rContext->dwStatus);
+ (readerStates[i])->cardAtrLength = htonl(rContext->dwAtrLen);
+ (readerStates[i])->cardProtocol = htonl(rContext->dwProtocol);
+ memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
+ rContext->dwAtrLen);
+
+ SYS_MMapSynchronize((void *) readerStates[i], pageSize);
+ }
+
+ } else if (dwStatus & SCARD_PRESENT)
+ {
+ if (dwCurrentState == SCARD_ABSENT ||
+ dwCurrentState == SCARD_UNKNOWN)
+ {
+
+ /*
+ * Power and reset the card
+ */
+ SYS_USleep(PCSCLITE_STATUS_WAIT);
+ rv = IFDPowerICC(rContext, IFD_POWER_UP,
+ rContext->ucAtr, &rContext->dwAtrLen);
+ secdebug("pcscd", "EHStatusHandlerThread: power-and-reset call to IFDPowerICC: %d [%04X]", rv, rv);
+
+ if (rv == IFD_SUCCESS)
+ {
+ rContext->dwProtocol =
+ PHGetDefaultProtocol(rContext->ucAtr,
+ rContext->dwAtrLen);
+ rContext->dwStatus |= SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_ABSENT;
+ rContext->dwStatus |= SCARD_POWERED;
+ rContext->dwStatus |= SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ rContext->dwStatus &= ~SCARD_SWALLOWED;
+
+ /*
+ * Notify the card has been reset
+ */
+ /*
+ * RFSetReaderEventState( rContext, SCARD_RESET );
+ */
+ } else
+ {
+ rContext->dwStatus |= SCARD_PRESENT;
+ rContext->dwStatus &= ~SCARD_ABSENT;
+ rContext->dwStatus |= SCARD_SWALLOWED;
+ rContext->dwStatus &= ~SCARD_POWERED;
+ rContext->dwStatus &= ~SCARD_NEGOTIABLE;
+ rContext->dwStatus &= ~SCARD_SPECIFIC;
+ rContext->dwStatus &= ~SCARD_UNKNOWN;
+ rContext->dwAtrLen = 0;
+ rContext->dwProtocol = 0;
+ }
+
+ dwCurrentState = SCARD_PRESENT;
+
+ /*
+ * Set all the public attributes to this reader
+ */
+ (readerStates[i])->readerState = htonl(rContext->dwStatus);
+ (readerStates[i])->cardAtrLength = htonl(rContext->dwAtrLen);
+ (readerStates[i])->cardProtocol = htonl(rContext->dwProtocol);
+ memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
+ rContext->dwAtrLen);
+
+ SYS_MMapSynchronize((void *) readerStates[i], pageSize);
+
+ DebugLogB("EHSpawnEventHandler: Card inserted into %s",
+ lpcReader);
+
+ if (rv == IFD_SUCCESS)
+ {
+ if (rContext->dwAtrLen > 0)
+ {
+ DebugXxd("EHSpawnEventHandler: Card ATR: ",
+ rContext->ucAtr, rContext->dwAtrLen);
+ } else
+ {
+ DebugLogA("EHSpawnEventHandler: Card ATR: (NULL)");
+ }
+
+ } else
+ {
+ DebugLogA
+ ("EHSpawnEventHandler: Error powering up card.");
+ }
+ }
+ }
+
+ if (rContext->dwLockId == 0xFFFF)
+ {
+ /*
+ * Exit and notify the caller
+ */
+ secdebug("pcscd", "EHStatusHandlerThread: lockid is -1?? - exiting");
+ rContext->dwLockId = 0;
+ SYS_ThreadDetach(rContext->pthThread);
+ SYS_ThreadExit(0);
+ }
+
+ /*
+ * Sharing may change w/o an event pass it on
+ */
+
+ if (dwReaderSharing != rContext->dwContexts)
+ {
+ dwReaderSharing = rContext->dwContexts;
+ (readerStates[i])->readerSharing = htonl(dwReaderSharing);
+ SYS_MMapSynchronize((void *) readerStates[i], pageSize);
+ }
+
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE);
+ }
+}
+
+void EHSetSharingEvent(PREADER_CONTEXT rContext, DWORD dwValue)
+{
+
+ (readerStates[rContext->dwPublicID])->lockState = htonl(dwValue);
+
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,533 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * eventhandler.cpp
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2000
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 2004
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: eventhandler.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This keeps track of card insertion/removal events
+ * and updates ATR, protocol, and status information.
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "ifdhandler.h"
+#include "debuglog.h"
+#include "thread_generic.h"
+#include "readerfactory.h"
+#include "eventhandler.h"
+#include "dyn_generic.h"
+#include "sys_generic.h"
+#include "ifdwrapper.h"
+#include "prothandler.h"
+#include "readerstate.h"
+
+#include <security_utilities/debugging.h>
+
+static PREADER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS];
+
+void EHStatusHandlerThread(PREADER_CONTEXT);
+
+LONG EHInitializeEventStructures(void)
+{
+ int fd, i, pageSize;
+
+ fd = 0;
+ i = 0;
+ pageSize = 0;
+
+ /*
+ Do not truncate to avoid possible SIGSEG on clients
+ Do not remove the file to allow long-term clients such as securityd to
+ stay connected to the same file
+ */
+ fd = SYS_OpenFile(PCSCLITE_PUBSHM_FILE, O_RDWR | O_CREAT , 00644);
+ if (fd < 0)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Cannot create public shared file %s: %s",
+ PCSCLITE_PUBSHM_FILE, strerror(errno));
+ exit(1);
+ }
+
+ SYS_Chmod(PCSCLITE_PUBSHM_FILE,
+ S_IRGRP | S_IREAD | S_IWRITE | S_IROTH);
+
+ pageSize = SYS_GetPageSize();
+
+ int rx = ftruncate(fd, pageSize * PCSCLITE_MAX_READERS_CONTEXTS);
+ if (rx)
+ Log3(PCSC_LOG_CRITICAL, "Cannot truncate public shared file %d: %s",
+ errno, strerror(errno));
+ /*
+ * Jump to end of file space and allocate zero's
+ */
+ SYS_SeekFile(fd, pageSize * PCSCLITE_MAX_READERS_CONTEXTS);
+ SYS_WriteFile(fd, "", 1);
+
+ /*
+ * Allocate each reader structure
+ */
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ readerStates[i] = (PREADER_STATE)
+ SYS_MemoryMap(sizeof(READER_STATE), fd, (i * pageSize));
+ if (readerStates[i] == MAP_FAILED)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Cannot memory map public shared file %s: %s",
+ PCSCLITE_PUBSHM_FILE, strerror(errno));
+ exit(1);
+ }
+
+ /*
+ * Zero out each value in the struct
+ */
+ memset((readerStates[i])->readerName, 0, MAX_READERNAME);
+ memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
+ (readerStates[i])->readerID = 0;
+ (readerStates[i])->readerState = 0;
+ (readerStates[i])->lockState = 0;
+ (readerStates[i])->readerSharing = 0;
+ (readerStates[i])->cardAtrLength = 0;
+ (readerStates[i])->cardProtocol = SCARD_PROTOCOL_UNSET; // ok since this is 0
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG EHDestroyEventHandler(PREADER_CONTEXT rContext)
+{
+ if (NULL == rContext->readerState)
+ {
+ Log1(PCSC_LOG_ERROR, "Thread never started (reader init failed?)");
+ return SCARD_S_SUCCESS;
+ }
+
+ PCSCD::SharedReaderState *rs = PCSCD::SharedReaderState::overlay(rContext->readerState);
+ if ((rContext->pthThread == 0) || !rs || (rs->readerNameLength() == 0))
+ {
+ Log1(PCSC_LOG_INFO, "Thread already stomped.");
+ return SCARD_S_SUCCESS;
+ }
+
+ secdebug("pcscd", "EHDestroyEventHandler: pthThread: %p, reader name len: %ld",
+ rContext->pthThread, rs->readerNameLength());
+
+ /*
+ * Zero out the public status struct to allow it to be recycled and
+ * used again
+ */
+
+ rs->xreaderNameClear();
+ rs->xcardAtrClear();
+ rs->xreaderID(0);
+ rs->xreaderState(0);
+ rs->xlockState(0);
+ rs->sharing(0);
+ rs->xcardAtrLength(0);
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET); // we only set this one to write to memory cache
+
+ /*
+ * Set the thread to 0 to exit thread
+ */
+ ReaderContextLock(rContext);
+
+ Log1(PCSC_LOG_INFO, "Stomping thread.");
+
+ int ix;
+ for (ix = 0; (ix < 100) && ReaderContextIsLocked(rContext); ++ix)
+ {
+ /*
+ * Wait 0.05 seconds for the child to respond
+ */
+ SYS_USleep(50000);
+ }
+
+ secdebug("pcscd", "EHDestroyEventHandler: post-stop dwLockId: %d", rContext->dwLockId);
+
+
+ /* Zero the thread */
+ rContext->pthThread = 0;
+
+ Log1(PCSC_LOG_INFO, "Thread stomped.");
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG EHSpawnEventHandler(PREADER_CONTEXT rContext)
+{
+ LONG rv;
+ DWORD dwStatus = 0;
+ int i;
+ UCHAR ucAtr[MAX_ATR_SIZE];
+ DWORD dwAtrLen = 0;
+
+ secdebug("pcscd", "EHSpawnEventHandler: rContext: %p", rContext);
+ rv = IFDStatusICC(rContext, &dwStatus, ucAtr, &dwAtrLen);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "Initial Check Failed on %s", rContext->lpcReader);
+ return SCARD_F_UNKNOWN_ERROR;
+ }
+
+ /*
+ * Find an empty reader slot and insert the new reader
+ */
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ PCSCD::SharedReaderState *rstmp = PCSCD::SharedReaderState::overlay(readerStates[i]);
+ if (rstmp->xreaderID() == 0)
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ return SCARD_F_INTERNAL_ERROR;
+
+ /*
+ * Set all the attributes to this reader
+ */
+ PCSCD::SharedReaderState *rs = PCSCD::SharedReaderState::overlay(readerStates[i]);
+ rContext->readerState = readerStates[i];
+ rs->xreaderName(rContext->lpcReader);
+ rs->xcardAtr(ucAtr, dwAtrLen); // also sets cardAtrLength
+
+ rs->xreaderID(i + 100);
+ rs->xreaderState(dwStatus);
+ rs->sharing(rContext->dwContexts);
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+
+ rv = SYS_ThreadCreate(&rContext->pthThread, THREAD_ATTR_DETACHED,
+ (PCSCLITE_THREAD_FUNCTION( ))EHStatusHandlerThread, (LPVOID) rContext);
+ secdebug("pcscd", "EHSpawnEventHandler after thread create: %d [%04X]", rv, rv);
+ if (rv == 1)
+ return SCARD_S_SUCCESS;
+ else
+ return SCARD_E_NO_MEMORY;
+}
+
+void EHStatusHandlerThread(PREADER_CONTEXT rContext)
+{
+ LONG rv;
+ LPCSTR lpcReader;
+ DWORD dwStatus, dwReaderSharing;
+ DWORD dwCurrentState;
+ int pageSize = SYS_GetPageSize();
+
+ /*
+ * Zero out everything
+ */
+ dwStatus = 0;
+ dwReaderSharing = 0;
+ dwCurrentState = 0;
+
+ secdebug("pcscd", "EHStatusHandlerThread: rContext: %p", rContext);
+ lpcReader = rContext->lpcReader;
+
+ PCSCD::SharedReaderState *rs = PCSCD::SharedReaderState::overlay(rContext->readerState);
+
+ DWORD tmpCardAtrLength = MAX_ATR_SIZE;
+ rv = IFDStatusICC(rContext, &dwStatus, rs->xcardAtr(), &tmpCardAtrLength);
+ secdebug("pcscd", "EHStatusHandlerThread: initial call to IFDStatusICC: %d [%04X]", rv, rv);
+
+ if (dwStatus & SCARD_PRESENT)
+ {
+ tmpCardAtrLength = MAX_ATR_SIZE;
+ rv = IFDPowerICC(rContext, IFD_POWER_UP, rs->xcardAtr(), &tmpCardAtrLength);
+
+ /* the protocol is unset after a power on */
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+
+ secdebug("pcscd", "EHStatusHandlerThread: initial call to IFDPowerICC: %d [%04X]", rv, rv);
+
+ if (rv == IFD_SUCCESS)
+ {
+ rs->xcardAtrLength(tmpCardAtrLength);
+
+ dwStatus |= SCARD_PRESENT;
+ dwStatus &= ~SCARD_ABSENT;
+ dwStatus |= SCARD_POWERED;
+ dwStatus |= SCARD_NEGOTIABLE;
+ dwStatus &= ~SCARD_SPECIFIC;
+ dwStatus &= ~SCARD_SWALLOWED;
+ dwStatus &= ~SCARD_UNKNOWN;
+
+ if (rs->xcardAtrLength() > 0)
+ {
+ LogXxd(PCSC_LOG_INFO, "Card ATR: ",
+ rs->xcardAtr(),
+ rs->xcardAtrLength());
+ }
+ else
+ Log1(PCSC_LOG_INFO, "Card ATR: (NULL)");
+ }
+ else
+ {
+ dwStatus |= SCARD_PRESENT;
+ dwStatus &= ~SCARD_ABSENT;
+ dwStatus |= SCARD_SWALLOWED;
+ dwStatus &= ~SCARD_POWERED;
+ dwStatus &= ~SCARD_NEGOTIABLE;
+ dwStatus &= ~SCARD_SPECIFIC;
+ dwStatus &= ~SCARD_UNKNOWN;
+ Log3(PCSC_LOG_ERROR, "Error powering up card: %d 0x%04X", rv, rv);
+ }
+
+ dwCurrentState = SCARD_PRESENT;
+ }
+ else
+ {
+ dwStatus |= SCARD_ABSENT;
+ dwStatus &= ~SCARD_PRESENT;
+ dwStatus &= ~SCARD_POWERED;
+ dwStatus &= ~SCARD_NEGOTIABLE;
+ dwStatus &= ~SCARD_SPECIFIC;
+ dwStatus &= ~SCARD_SWALLOWED;
+ dwStatus &= ~SCARD_UNKNOWN;
+ rs->xcardAtrLength(0);
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+
+ dwCurrentState = SCARD_ABSENT;
+ }
+
+ /*
+ * Set all the public attributes to this reader
+ */
+ rs->xreaderState(dwStatus);
+ dwReaderSharing = rContext->dwContexts;
+ rs->sharing(dwReaderSharing);
+
+ SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+
+ while (1)
+ {
+ dwStatus = 0;
+
+ // Defensive measure
+ if (!rContext->vHandle)
+ {
+ // Exit and notify the caller
+ secdebug("pcscd", "EHStatusHandlerThread: lost dynamic callbacks ??");
+ ReaderContextUnlock(rContext);
+ SYS_ThreadDetach(rContext->pthThread);
+ SYS_ThreadExit(0);
+ }
+
+ DWORD tmpCardAtrLength = MAX_ATR_SIZE;
+ rv = IFDStatusICC(rContext, &dwStatus, rs->xcardAtr(), &tmpCardAtrLength);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "Error communicating to: %s", lpcReader);
+
+ /*
+ * Set error status on this reader while errors occur
+ */
+
+ DWORD readerStateTmp = rs->xreaderState();
+ readerStateTmp &= ~SCARD_ABSENT;
+ readerStateTmp &= ~SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_POWERED;
+ readerStateTmp &= ~SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ readerStateTmp &= ~SCARD_SWALLOWED;
+ readerStateTmp |= SCARD_UNKNOWN;
+ rs->xcardAtrLength(0);
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+ rs->xreaderState(readerStateTmp);
+
+ dwCurrentState = SCARD_UNKNOWN;
+
+ SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+
+ /*
+ * This code causes race conditions on G4's with USB
+ * insertion
+ */
+ /*
+ * dwErrorCount += 1; SYS_Sleep(1);
+ */
+ /*
+ * After 10 seconds of errors, try to reinitialize the reader
+ * This sometimes helps bring readers out of *crazy* states.
+ */
+ /*
+ * if ( dwErrorCount == 10 ) { RFUnInitializeReader( rContext
+ * ); RFInitializeReader( rContext ); dwErrorCount = 0; }
+ */
+
+ /*
+ * End of race condition code block
+ */
+ }
+
+ if (dwStatus & SCARD_ABSENT)
+ {
+ if (dwCurrentState == SCARD_PRESENT ||
+ dwCurrentState == SCARD_UNKNOWN)
+ {
+ /*
+ * Change the status structure
+ */
+ Log2(PCSC_LOG_INFO, "Card Removed From %s", lpcReader);
+ /*
+ * Notify the card has been removed
+ */
+ RFSetReaderEventState(rContext, SCARD_REMOVED);
+
+ rs->xcardAtrLength(0);
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+ DWORD readerStateTmp = rs->xreaderState();
+ readerStateTmp |= SCARD_ABSENT;
+ readerStateTmp &= ~SCARD_UNKNOWN;
+ readerStateTmp &= ~SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_POWERED;
+ readerStateTmp &= ~SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SWALLOWED;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ rs->xreaderState(readerStateTmp);
+ dwCurrentState = SCARD_ABSENT;
+
+ SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ }
+
+ }
+ else if (dwStatus & SCARD_PRESENT)
+ {
+ if (dwCurrentState == SCARD_ABSENT ||
+ dwCurrentState == SCARD_UNKNOWN)
+ {
+ /*
+ * Power and reset the card
+ */
+ SYS_USleep(PCSCLITE_STATUS_WAIT);
+ DWORD tmpCardAtrLength = MAX_ATR_SIZE;
+ rv = IFDPowerICC(rContext, IFD_POWER_UP, rs->xcardAtr(), &tmpCardAtrLength);
+
+ /* the protocol is unset after a power on */
+ rs->xcardProtocol(SCARD_PROTOCOL_UNSET);
+
+ secdebug("pcscd", "EHStatusHandlerThread: power-and-reset call to IFDPowerICC: %d [%04X]", rv, rv);
+
+ DWORD readerStateTmp = rs->xreaderState();
+ if (rv == IFD_SUCCESS)
+ {
+ rs->xcardAtrLength(tmpCardAtrLength);
+
+ readerStateTmp |= SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_ABSENT;
+ readerStateTmp |= SCARD_POWERED;
+ readerStateTmp |= SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ readerStateTmp &= ~SCARD_UNKNOWN;
+ readerStateTmp &= ~SCARD_SWALLOWED;
+ rs->xreaderState(readerStateTmp);
+
+ /*
+ * Notify the card has been reset
+ */
+ RFSetReaderEventState(rContext, SCARD_RESET);
+ }
+ else
+ {
+ readerStateTmp |= SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_ABSENT;
+ readerStateTmp |= SCARD_SWALLOWED;
+ readerStateTmp &= ~SCARD_POWERED;
+ readerStateTmp &= ~SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ readerStateTmp &= ~SCARD_UNKNOWN;
+ rs->xreaderState(readerStateTmp);
+ rs->xcardAtrLength(0);
+ }
+
+ dwCurrentState = SCARD_PRESENT;
+
+ SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+
+ Log2(PCSC_LOG_INFO, "Card inserted into %s", lpcReader);
+
+ if (rv == IFD_SUCCESS)
+ {
+ if (rs->xcardAtrLength() > 0)
+ LogXxd(PCSC_LOG_INFO, "Card ATR: ", rs->xcardAtr(), rs->xcardAtrLength());
+ else
+ Log1(PCSC_LOG_INFO, "Card ATR: (NULL)");
+ }
+ else
+ Log1(PCSC_LOG_ERROR,"Error powering up card.");
+ }
+ }
+
+ if (ReaderContextIsLocked(rContext))
+ {
+ /*
+ * Exit and notify the caller
+ */
+ secdebug("pcscd", "EHStatusHandlerThread: parent requested shutdown");
+ ReaderContextUnlock(rContext);
+ SYS_ThreadDetach(rContext->pthThread);
+ SYS_ThreadExit(0);
+ }
+
+ /*
+ * Sharing may change w/o an event pass it on
+ */
+
+ if (dwReaderSharing != (uint32_t)rContext->dwContexts)
+ {
+ dwReaderSharing = rContext->dwContexts;
+ rs->sharing(dwReaderSharing);
+ SYS_MMapSynchronize((void *) rContext->readerState, pageSize);
+ }
+
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE);
+ }
+}
+
+void EHSetSharingEvent(PREADER_CONTEXT rContext, DWORD dwValue)
+{
+ PCSCD::SharedReaderState *rs = PCSCD::SharedReaderState::overlay(rContext->readerState);
+ rs->xlockState(dwValue);
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/eventhandler.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * eventhandler.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 2004
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: eventhandler.h 2151 2006-09-06 20:02:47Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles card insertion/removal events, updates ATR,
+ * protocol, and status information.
+ */
+
+#ifndef __eventhandler_h__
+#define __eventhandler_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * Define an exported public reader state structure so each
+ * application gets instant notification of changes in state.
+ */
+ typedef struct pubReaderStatesList
+ {
+ LONG readerID;
+ char readerName[MAX_READERNAME];
+ DWORD readerState;
+ LONG readerSharing;
+ DWORD lockState;
+
+ UCHAR cardAtr[MAX_ATR_SIZE];
+ DWORD cardAtrLength;
+ DWORD cardProtocol;
+ }
+ READER_STATE, *PREADER_STATE;
+
+ LONG EHInitializeEventStructures(void);
+ LONG EHSpawnEventHandler(PREADER_CONTEXT);
+ LONG EHDestroyEventHandler(PREADER_CONTEXT);
+ void EHSetSharingEvent(PREADER_CONTEXT, DWORD);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __eventhandler_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * hotplug.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2000-2003
+ * David Corcoran <corcoran at linuxnet.com>
+ *
+ * $Id: hotplug.h 2310 2007-01-06 21:14:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This provides a search API for hot pluggble devices.
+ */
+
+#ifndef __hotplug_h__
+#define __hotplug_h__
+
+#include "pthread.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define PCSCLITE_HP_BASE_PORT 0x200000
+
+ LONG HPSearchHotPluggables();
+ LONG HPRegisterForHotplugEvents();
+ LONG HPStopHotPluggables(void);
+ void HPReCheckSerialReaders(void);
+ int SendHotplugSignal(void);
+ LONG HPCancelHotPluggables(void);
+ LONG HPJoinHotPluggables(void);
+
+ LONG HPRegisterForHotplugEventsT(pthread_t *wthread);
+
+ void systemAwakeAndReadyCheck();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,869 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : hotplug_macosx.c
+ Package: pcsc lite
+ Author : Stephen M. Webb <stephenw at cryptocard.com>
+ Date : 03 Dec 2002
+ License: Copyright (C) 2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This provides a search API for hot pluggble
+ devices.
+
+********************************************************************/
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <IOKit/IOCFPlugIn.h>
+#include <IOKit/IOKitLib.h>
+#include <IOKit/usb/IOUSBLib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "debuglog.h"
+#include "hotplug.h"
+#include "readerfactory.h"
+#include "thread_generic.h"
+
+#define PCSCLITE_HP_DROPDIR "/usr/libexec/SmartCardServices/drivers/"
+#define PCSCLITE_HP_MANUKEY_NAME "ifdVendorID"
+#define PCSCLITE_HP_PRODKEY_NAME "ifdProductID"
+#define PCSCLITE_HP_NAMEKEY_NAME "ifdFriendlyName"
+#define PCSCLITE_HP_IFACECLASSKEY_NAME "ifdInterfaceClass"
+#define PCSCLITE_HP_IFACESUBCLASSKEY_NAME "ifdInterfaceSubClass"
+#define PCSCLITE_HP_IFACEPROTOCOLKEY_NAME "ifdInterfaceProtocol"
+#define PCSCLITE_HP_BASE_PORT 0x200000
+
+
+/*
+ * Defines the type of driver in the driver vector
+ */
+typedef enum
+{
+ PCSCLITE_HP_Proprietary = 0,
+ PCSCLITE_HP_InterfaceClass = 1,
+ // * Could accomodate more types */
+} HPDriverType;
+
+
+
+/*
+ * An aggregation of useful information on a driver bundle in the
+ * drop directory.
+ */
+typedef struct HPDriver
+{
+ UInt8 m_NotEOV; /* set to 1 for any driver before the end */
+ UInt8 m_initialized; /* set to 1 on successful intialization */
+ HPDriverType m_type; /* type of the driver in this element */
+ UInt32 m_vendorId; /* unique vendor's manufacturer code */
+ UInt32 m_productId; /* manufacturer's unique product code */
+ UInt8 m_class; /* class of a non product specific driver */
+ UInt8 m_subClass; /* subClass of a non product specific driver */
+ UInt8 m_protocol; /* protocol of a non product specific driver */
+ char* m_friendlyName; /* bundle friendly name */
+ char* m_libPath; /* bundle's plugin library location */
+} HPDriver, *HPDriverVector;
+
+/*
+ * An aggregation on information on currently active reader drivers.
+ */
+typedef struct HPDevice
+{
+ HPDriver* m_driver; /* driver bundle information */
+ UInt32 m_address; /* unique system address of device */
+ struct HPDevice* m_next; /* next device in list */
+} HPDevice, *HPDeviceList;
+
+/*
+ * Pointer to a list of (currently) known hotplug reader devices (and their
+ * drivers).
+ */
+static HPDeviceList sDeviceList = NULL;
+static IONotificationPortRef sNotificationPort = NULL;
+static io_iterator_t sUSBAppearedIter = NULL;
+static io_iterator_t sUSBRemovedIter = NULL;
+static io_iterator_t sPCCardAppearedIter = NULL;
+static io_iterator_t sPCCardRemovedIter = NULL;
+
+/*
+ * A callback to handle the asynchronous appearance of new devices that are
+ * candidates for PCSC readers.
+ */
+static void
+HPDeviceAppeared(void* refCon, io_iterator_t iterator)
+{
+ kern_return_t kret;
+ io_service_t obj;
+ while ((obj = IOIteratorNext(iterator)))
+ {
+ kret = IOObjectRelease(obj);
+ }
+
+ HPSearchHotPluggables();
+}
+
+/*
+ * A callback to handle the asynchronous disappearance of devices that are
+ * possibly PCSC readers.
+ */
+static void
+HPDeviceDisappeared(void* refCon, io_iterator_t iterator)
+{
+ kern_return_t kret;
+ io_service_t obj;
+ while ((obj = IOIteratorNext(iterator)))
+ {
+ kret = IOObjectRelease(obj);
+ }
+ HPSearchHotPluggables();
+}
+
+
+/*
+ * Creates a vector of driver bundle info structures from the hot-plug driver
+ * directory.
+ *
+ * Returns NULL on error and a pointer to an allocated HPDriver vector on
+ * success. The caller must free the HPDriver with a call to
+ * HPDriversRelease().
+ */
+static HPDriverVector
+HPDriversGetFromDirectory(const char* driverBundlePath)
+{
+ HPDriverVector bundleVector = NULL;
+ CFArrayRef bundleArray;
+ CFStringRef driverBundlePathString;
+ driverBundlePathString = CFStringCreateWithCString(kCFAllocatorDefault,
+ driverBundlePath,
+ kCFStringEncodingMacRoman);
+ CFURLRef pluginUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ driverBundlePathString,
+ kCFURLPOSIXPathStyle, TRUE);
+ CFRelease(driverBundlePathString);
+ if (!pluginUrl)
+ {
+ DebugLogA("error getting plugin directory URL");
+ return bundleVector;
+ }
+ bundleArray = CFBundleCreateBundlesFromDirectory(kCFAllocatorDefault,
+ pluginUrl,
+ NULL);
+ if (!bundleArray)
+ {
+ DebugLogA("error getting plugin directory bundles");
+ return bundleVector;
+ }
+ CFRelease(pluginUrl);
+
+ size_t bundleArraySize = CFArrayGetCount(bundleArray);
+ // bundleArraySize + 1 <- because the last vector element is
+ // blank and is used to determine the length (m_NotEOV == 0)
+ bundleVector = (HPDriver*)calloc(bundleArraySize + 1, sizeof(HPDriver));
+ if (!bundleVector)
+ {
+ DebugLogA("memory allocation failure");
+ return bundleVector;
+ }
+
+ int i = 0;
+ for (; i < bundleArraySize; ++i)
+ {
+ HPDriver* driverBundle = bundleVector + i;
+ // This is not the last
+ driverBundle->m_NotEOV = 1;
+ CFBundleRef currBundle = (CFBundleRef)CFArrayGetValueAtIndex(bundleArray, i);
+ CFDictionaryRef dict = CFBundleGetInfoDictionary(currBundle);
+
+ CFURLRef bundleUrl = CFBundleCopyBundleURL(currBundle);
+ CFStringRef bundlePath = CFURLCopyPath(bundleUrl);
+ driverBundle->m_libPath = strdup(CFStringGetCStringPtr(bundlePath,
+ CFStringGetSystemEncoding()));
+ if (driverBundle->m_libPath == NULL)
+ {
+ DebugLogA("memory allocation failure");
+ return bundleVector;
+ }
+ UInt32 vendorId = 0;
+ UInt8 gotVendorId = 0;
+ UInt32 productId = 0;
+ UInt8 gotProductId = 0;
+
+ CFStringRef strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_MANUKEY_NAME));
+ if (strValue)
+ {
+ gotVendorId = 1;
+ vendorId = strtoul(CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding()),
+ NULL, 16);
+
+ strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_PRODKEY_NAME));
+ if (strValue)
+ {
+ gotProductId = 1;
+ productId = strtoul(CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding()),
+ NULL, 16);
+ }
+ }
+ if (gotVendorId && gotProductId)
+ {
+ /* This is a product-specific driver */
+ driverBundle->m_productId = productId;
+ driverBundle->m_vendorId = vendorId;
+ driverBundle->m_type = PCSCLITE_HP_Proprietary;
+ }
+ else
+ {
+ /* If not a product-specific driver, it must be */
+ /* an interface class-specifc driver */
+ UInt8 class;
+ UInt8 subClass;
+ UInt8 protocol;
+
+ strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_IFACECLASSKEY_NAME));
+ if (strValue)
+ {
+ class = (UInt8) strtoul(CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding()),
+ NULL, 16);
+ driverBundle->m_class = class;
+ }
+ else
+ {
+ DebugLogB("Malformed bundle (class absent) in driver folder: %s. Will be ignored",
+ driverBundle->m_libPath);
+ free(driverBundle->m_libPath);
+ driverBundle->m_libPath = NULL;
+ continue;
+ }
+ strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_IFACESUBCLASSKEY_NAME));
+ if (strValue)
+ {
+ subClass = (UInt8) strtoul(CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding()),
+ NULL, 16);
+ driverBundle->m_subClass = subClass;
+ }
+ else
+ {
+ DebugLogB("Malformed bundle (subClass absent) in driver folder: %s. Will be ignored",
+ driverBundle->m_libPath);
+ free(driverBundle->m_libPath);
+ driverBundle->m_libPath = NULL;
+ continue;
+ }
+ strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_IFACEPROTOCOLKEY_NAME));
+ if (strValue)
+ {
+ protocol = (UInt8) strtoul(CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding()),
+ NULL, 16);
+ driverBundle->m_protocol = protocol;
+ }
+ else
+ {
+ DebugLogB("Malformed bundle (protocol absent) in driver folder: %s. Will be ignored",
+ driverBundle->m_libPath);
+ free(driverBundle->m_libPath);
+ driverBundle->m_libPath = NULL;
+ continue;
+ }
+ driverBundle->m_type = PCSCLITE_HP_InterfaceClass;
+ }
+ strValue = (CFStringRef)CFDictionaryGetValue(dict,
+ CFSTR(PCSCLITE_HP_NAMEKEY_NAME));
+ if (!strValue)
+ {
+ DebugLogB("Product friendly name absent in driver folder: %s.",
+ driverBundle->m_libPath);
+ driverBundle->m_friendlyName = strdup("unnamed device");
+ }
+ else
+ {
+ const char* cstr = CFStringGetCStringPtr(strValue,
+ CFStringGetSystemEncoding());
+ driverBundle->m_friendlyName = strdup(cstr);
+ }
+ driverBundle->m_initialized = 1;
+ }
+ CFRelease(bundleArray);
+ return bundleVector;
+}
+
+/*
+ * Copies a driver bundle instance.
+ */
+static HPDriver*
+HPDriverCopy(HPDriver* rhs)
+{
+ if (!rhs)
+ {
+ return NULL;
+ }
+ HPDriver* newDriverBundle = (HPDriver*)calloc(1, sizeof(HPDriver));
+ if (!newDriverBundle)
+ {
+ return NULL;
+ }
+
+ newDriverBundle->m_initialized = rhs->m_initialized;
+ newDriverBundle->m_type = rhs->m_type;
+ newDriverBundle->m_vendorId = rhs->m_vendorId;
+ newDriverBundle->m_productId = rhs->m_productId;
+
+ newDriverBundle->m_class = rhs->m_class;
+ newDriverBundle->m_subClass = rhs->m_subClass;
+ newDriverBundle->m_friendlyName = strdup(rhs->m_friendlyName);
+ newDriverBundle->m_libPath = strdup(rhs->m_libPath);
+ if (newDriverBundle->m_friendlyName == NULL)
+ {
+ if (newDriverBundle->m_libPath != NULL)
+ {
+ free(newDriverBundle->m_libPath);
+ }
+ free(newDriverBundle);
+ return NULL;
+ }
+
+ if (newDriverBundle->m_libPath == NULL)
+ {
+ if (newDriverBundle->m_friendlyName != NULL)
+ {
+ free(newDriverBundle->m_friendlyName);
+ }
+ free(newDriverBundle);
+ return NULL;
+ }
+ return newDriverBundle;
+}
+
+/*
+ * Releases resources allocated to a driver bundle vector.
+ */
+static void
+HPDriverRelease(HPDriver* driverBundle)
+{
+ if (driverBundle)
+ {
+ free(driverBundle->m_friendlyName);
+ free(driverBundle->m_libPath);
+ }
+}
+
+/*
+ * Releases resources allocated to a driver bundle vector.
+ */
+static void
+HPDriverVectorRelease(HPDriverVector driverBundleVector)
+{
+ if (driverBundleVector)
+ {
+ HPDriver* b = driverBundleVector;
+ for (; b->m_initialized; ++b)
+ {
+ HPDriverRelease(b);
+ }
+ free(driverBundleVector);
+ }
+}
+
+/*
+ * Inserts a new reader device in the list.
+ */
+static HPDeviceList
+HPDeviceListInsert(HPDeviceList list, HPDriver* bundle, UInt32 address)
+{
+ HPDevice* newReader = (HPDevice*)calloc(1, sizeof(HPDevice));
+ if (!newReader)
+ {
+ DebugLogA("memory allocation failure");
+ return list;
+ }
+ newReader->m_driver = HPDriverCopy(bundle);
+ newReader->m_address = address;
+ newReader->m_next = list;
+ return newReader;
+}
+
+/*
+ * Frees resources allocated to a HPDeviceList.
+ */
+static void
+HPDeviceListRelease(HPDeviceList list)
+{
+ HPDevice* p = list;
+ for (; p; p = p->m_next)
+ {
+ HPDriverRelease(p->m_driver);
+ }
+}
+
+/*
+ * Compares two driver bundle instances for equality.
+ */
+static int
+HPDeviceEquals(HPDevice* a, HPDevice* b)
+{
+ int res;
+ if (a->m_driver->m_type == b->m_driver->m_type)
+ {
+ if (a->m_driver->m_type == PCSCLITE_HP_Proprietary)
+ {
+ // a and b have same vendor and product id
+ res = (a->m_driver->m_vendorId == b->m_driver->m_vendorId)
+ && (a->m_driver->m_productId == b->m_driver->m_productId);
+ }
+ else
+ {
+ // a and b have same class
+ res = (a->m_driver->m_subClass == b->m_driver->m_subClass)
+ && (a->m_driver->m_class == b->m_driver->m_class);
+ }
+ // AND have the same address
+ res = res && (a->m_address == b->m_address);
+
+ return res;
+ }
+ return 0;
+}
+
+/*
+ * Finds USB devices currently registered in the system that match any of
+ * the drivers detected in the driver bundle vector.
+ */
+static int
+HPDriversMatchUSBDevices(HPDriverVector driverBundle, HPDeviceList* readerList)
+{
+ CFDictionaryRef usbMatch = IOServiceMatching("IOUSBDevice");
+ if (0 == usbMatch)
+ {
+ DebugLogA("error getting USB match from IOServiceMatching()");
+ return 1;
+ }
+
+ io_iterator_t usbIter;
+ kern_return_t kret = IOServiceGetMatchingServices(kIOMasterPortDefault,
+ usbMatch,
+ &usbIter);
+ if (kret != 0)
+ {
+ DebugLogA("error getting iterator from IOServiceGetMatchingServices()");
+ return 1;
+ }
+
+ io_object_t usbDevice = 0;
+ while ((usbDevice = IOIteratorNext(usbIter)))
+ {
+ IOCFPlugInInterface** iodev;
+ SInt32 score;
+ kret = IOCreatePlugInInterfaceForService(usbDevice,
+ kIOUSBDeviceUserClientTypeID,
+ kIOCFPlugInInterfaceID,
+ &iodev,
+ &score);
+ IOObjectRelease(usbDevice);
+ if (kret != 0)
+ {
+ DebugLogA("error getting plugin interface from IOCreatePlugInInterfaceForService()");
+ continue;
+ }
+
+ IOUSBDeviceInterface245** usbdev;
+ HRESULT hres = (*iodev)->QueryInterface(iodev,
+ CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID245),
+ (LPVOID*)&usbdev);
+ if (hres)
+ {
+ DebugLogA("error querying interface in QueryInterface()");
+ IODestroyPlugInInterface ( iodev );
+ continue;
+ }
+
+ else
+ {
+
+ UInt16 vendorId = 0;
+ UInt16 productId = 0;
+ UInt32 usbAddress = 0;
+ kret = (*usbdev)->GetDeviceVendor(usbdev, &vendorId);
+ kret = (*usbdev)->GetDeviceProduct(usbdev, &productId);
+ kret = (*usbdev)->GetLocationID(usbdev, &usbAddress);
+
+ HPDriver* driver = driverBundle;
+ int match = 0;
+ for (; driver->m_NotEOV; ++driver)
+ {
+ if (!driver->m_initialized)
+ {
+ // Malformed driver, skip
+ continue;
+ }
+ if ( (driver->m_type == PCSCLITE_HP_Proprietary)
+ && (driver->m_vendorId == vendorId)
+ && (driver->m_productId == productId))
+ {
+ *readerList = HPDeviceListInsert(*readerList, driver, usbAddress);
+ match = 1;
+ }
+ }
+ if (!match)
+ {
+ // Now try to locate Interfaces with supported classes
+ // We create an interface iterator for each of the
+ // classes supported by drivers of PCSCLITE_HP_InterfaceClass
+ // type.
+
+ // Using IOServiceMatching(kIOUSBInterfaceClassName)
+ // does not seem feasible as there does not seem to be a
+ // way to limit the search to the device we are currently
+ // analysing
+
+ // Another option would be to iterate on all interfaces
+ // and get the class of each of them. This is probably
+ // not interesting as the list of PCSCLITE_HP_InterfaceClass
+ // type of readers should only have one element (CCID)
+
+ // Restart scan at the begining of the array
+ driver = driverBundle;
+ // Iterate on PCSCLITE_HP_InterfaceClass driver types
+ for (; driver->m_NotEOV; ++driver)
+ {
+ if (!driver->m_initialized)
+ {
+ // Malformed driver, skip
+ continue;
+ }
+ if ( driver->m_type == PCSCLITE_HP_InterfaceClass)
+ {
+ // Iterate on interfaces of the current device
+ IOUSBFindInterfaceRequest interfaceClassRequest;
+ io_iterator_t interfaceIterator;
+ io_service_t interface;
+
+ interfaceClassRequest.bInterfaceClass = driver->m_class;
+ interfaceClassRequest.bInterfaceSubClass = driver->m_subClass;
+ interfaceClassRequest.bInterfaceProtocol = driver->m_protocol;
+ interfaceClassRequest.bAlternateSetting = kIOUSBFindInterfaceDontCare;
+ hres = (*usbdev)->CreateInterfaceIterator(usbdev,
+ &interfaceClassRequest,
+ &interfaceIterator);
+ if (hres)
+ {
+ // Continue to next driver class
+ continue;
+ }
+
+ while ( (interface = IOIteratorNext(interfaceIterator)) )
+ {
+ // Found a matching device
+ *readerList = HPDeviceListInsert(*readerList, driver, usbAddress);
+ match = 1;
+ IOObjectRelease ( interface );
+ }
+
+ IOObjectRelease ( interfaceIterator );
+
+ }
+ }
+ // Add another if (!match) for other driver types
+ }
+ (*usbdev)->Release(usbdev);
+ IODestroyPlugInInterface ( iodev );
+ }
+ }
+
+ IOObjectRelease(usbIter);
+ return 0;
+}
+
+/*
+ * Finds PC Card devices currently registered in the system that match any of
+ * the drivers detected in the driver bundle vector.
+ */
+static int
+HPDriversMatchPCCardDevices(HPDriver* driverBundle, HPDeviceList* readerList)
+{
+ CFDictionaryRef pccMatch = IOServiceMatching("IOPCCard16Device");
+ if (0 == pccMatch)
+ {
+ DebugLogA("error getting PCCard match from IOServiceMatching()");
+ return 1;
+ }
+
+ io_iterator_t pccIter;
+ kern_return_t kret = IOServiceGetMatchingServices(kIOMasterPortDefault, pccMatch, &pccIter);
+ if (kret != 0)
+ {
+ DebugLogA("error getting iterator from IOServiceGetMatchingServices()");
+ return 1;
+ }
+
+ io_object_t pccDevice = 0;
+ while ((pccDevice = IOIteratorNext(pccIter)))
+ {
+
+ UInt32 vendorId = 0;
+ UInt32 productId = 0;
+ UInt32 pccAddress = 0;
+ CFTypeRef valueRef = IORegistryEntryCreateCFProperty(pccDevice, CFSTR("VendorID"),
+ kCFAllocatorDefault, 0);
+ if (!valueRef)
+ {
+ DebugLogA("error getting vendor");
+ }
+ else
+ {
+ CFNumberGetValue((CFNumberRef)valueRef, kCFNumberSInt32Type, &vendorId);
+ CFRelease ( valueRef );
+ }
+ valueRef = IORegistryEntryCreateCFProperty(pccDevice, CFSTR("DeviceID"),
+ kCFAllocatorDefault, 0);
+ if (!valueRef)
+ {
+ DebugLogA("error getting device");
+ }
+ else
+ {
+ CFNumberGetValue((CFNumberRef)valueRef, kCFNumberSInt32Type, &productId);
+ CFRelease ( valueRef );
+ }
+ valueRef = IORegistryEntryCreateCFProperty(pccDevice, CFSTR("SocketNumber"),
+ kCFAllocatorDefault, 0);
+ if (!valueRef)
+ {
+ DebugLogA("error getting PC Card socket");
+ }
+ else
+ {
+ CFNumberGetValue((CFNumberRef)valueRef, kCFNumberSInt32Type, &pccAddress);
+ CFRelease ( valueRef );
+ }
+ HPDriver* driver = driverBundle;
+ for (; driver->m_vendorId; ++driver)
+ {
+ if ((driver->m_vendorId == vendorId)
+ && (driver->m_productId == productId))
+ {
+ *readerList = HPDeviceListInsert(*readerList, driver, pccAddress);
+ }
+ }
+
+ IOObjectRelease ( pccDevice );
+
+ }
+ IOObjectRelease(pccIter);
+ return 0;
+}
+
+
+static void
+HPEstablishUSBNotification()
+{
+
+ CFMutableDictionaryRef matchingDictionary;
+ IOReturn kret;
+
+ if ( sNotificationPort == NULL )
+ sNotificationPort = IONotificationPortCreate(kIOMasterPortDefault);
+
+ CFRunLoopAddSource(CFRunLoopGetCurrent(),
+ IONotificationPortGetRunLoopSource(sNotificationPort),
+ kCFRunLoopDefaultMode);
+
+ matchingDictionary = IOServiceMatching("IOUSBDevice");
+ if (!matchingDictionary)
+ {
+ DebugLogB("IOServiceMatching() failed", 0);
+ }
+ matchingDictionary = (CFMutableDictionaryRef)CFRetain(matchingDictionary);
+
+ kret = IOServiceAddMatchingNotification(sNotificationPort,
+ kIOMatchedNotification,
+ matchingDictionary,
+ HPDeviceAppeared, NULL,
+ &sUSBAppearedIter);
+ if (kret)
+ {
+ DebugLogB("IOServiceAddMatchingNotification()-1 failed with code %d", kret);
+ }
+
+ HPDeviceAppeared(NULL, sUSBAppearedIter);
+
+ kret = IOServiceAddMatchingNotification(sNotificationPort,
+ kIOTerminatedNotification,
+ matchingDictionary,
+ HPDeviceDisappeared, NULL,
+ &sUSBRemovedIter);
+ if (kret)
+ {
+ DebugLogB("IOServiceAddMatchingNotification()-2 failed with code %d", kret);
+ }
+ HPDeviceDisappeared(NULL, sUSBRemovedIter);
+}
+
+static void
+HPEstablishPCCardNotification()
+{
+
+ CFMutableDictionaryRef matchingDictionary;
+ IOReturn kret;
+
+ if ( sNotificationPort == NULL )
+ sNotificationPort = IONotificationPortCreate(kIOMasterPortDefault);
+
+ CFRunLoopAddSource(CFRunLoopGetCurrent(),
+ IONotificationPortGetRunLoopSource(sNotificationPort),
+ kCFRunLoopDefaultMode);
+
+ matchingDictionary = IOServiceMatching("IOPCCard16Device");
+ if (!matchingDictionary)
+ {
+ DebugLogB("IOServiceMatching() failed", 0);
+ }
+ matchingDictionary = (CFMutableDictionaryRef)CFRetain(matchingDictionary);
+
+ kret = IOServiceAddMatchingNotification(sNotificationPort,
+ kIOMatchedNotification,
+ matchingDictionary,
+ HPDeviceAppeared, NULL,
+ &sPCCardAppearedIter);
+ if (kret)
+ {
+ DebugLogB("IOServiceAddMatchingNotification()-1 failed with code %d", kret);
+ }
+ HPDeviceAppeared(NULL, sPCCardAppearedIter);
+
+ kret = IOServiceAddMatchingNotification(sNotificationPort,
+ kIOTerminatedNotification,
+ matchingDictionary,
+ HPDeviceDisappeared, NULL,
+ &sPCCardRemovedIter);
+ if (kret)
+ {
+ DebugLogB("IOServiceAddMatchingNotification()-2 failed with code %d", kret);
+ }
+ HPDeviceDisappeared(NULL, sPCCardRemovedIter);
+}
+
+/*
+ * Thread runner (does not return).
+ */
+static void
+HPDeviceNotificationThread()
+{
+ HPEstablishUSBNotification();
+ HPEstablishPCCardNotification();
+ CFRunLoopRun();
+}
+
+/*
+ * Scans the hotplug driver directory and looks in the system for matching devices.
+ * Adds or removes matching readers as necessary.
+ */
+LONG
+HPSearchHotPluggables()
+{
+ HPDriver* drivers = HPDriversGetFromDirectory(PCSCLITE_HP_DROPDIR);
+ if (!drivers) return 1;
+
+ HPDeviceList devices = NULL;
+ int istat;
+ istat = HPDriversMatchUSBDevices(drivers, &devices);
+ if (istat)
+ {
+ return -1;
+ }
+ istat = HPDriversMatchPCCardDevices(drivers, &devices);
+ if (istat)
+ {
+ return -1;
+ }
+
+ HPDevice* a = devices;
+ for (; a; a = a->m_next)
+ {
+ int found = 0;
+ HPDevice* b = sDeviceList;
+ for (; b; b = b->m_next)
+ {
+ if (HPDeviceEquals(a, b))
+ {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ {
+ RFAddReader(a->m_driver->m_friendlyName,
+ PCSCLITE_HP_BASE_PORT + a->m_address,
+ a->m_driver->m_libPath);
+ }
+ }
+
+ a = sDeviceList;
+ for (; a; a = a->m_next)
+ {
+ int found = 0;
+ HPDevice* b = devices;
+ for (; b; b = b->m_next)
+ {
+ if (HPDeviceEquals(a, b))
+ {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ {
+ RFRemoveReader(a->m_driver->m_friendlyName,
+ PCSCLITE_HP_BASE_PORT + a->m_address);
+ }
+ }
+
+ HPDeviceListRelease(sDeviceList);
+ sDeviceList = devices;
+ HPDriverVectorRelease(drivers);
+ return 0;
+}
+
+
+PCSCLITE_THREAD_T sHotplugWatcherThread;
+
+/*
+ * Sets up callbacks for device hotplug events.
+ */
+LONG
+HPRegisterForHotplugEvents()
+{
+ LONG sstat;
+ sstat = SYS_ThreadCreate(&sHotplugWatcherThread,
+ NULL,
+ (LPVOID)HPDeviceNotificationThread,
+ NULL);
+ return 0;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/hotplug_macosx.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : hotplug_macosx.c
+ Package: pcsc lite
+ Author : Stephen M. Webb <stephenw at cryptocard.com>
+ Date : 03 Dec 2002
+ License: Copyright (C) 2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This provides a search API for hot pluggble
+ devices.
+
+********************************************************************/
+
+#include "wintypes.h"
+
+#include "hotplug.h"
+#include "pthread.h"
+#include "PCSCDriverBundles.h"
+#include "pcscdserver.h"
+#include "pcscdmonitor.h"
+#include <security_utilities/debugging.h>
+
+const uint32_t kPCSCLITE_HP_BASE_PORT = 0x200000;
+PCSCDMonitor *gPCSCDMonitor = NULL;
+static Security::MachPlusPlus::Port gMainServerPort;
+
+#ifndef HOTPLUGTEST
+ #include "readerfactory.h"
+#else
+LONG RFAddReader(LPSTR, DWORD, LPSTR)
+{
+ return 0;
+}
+
+LONG RFRemoveReader(LPSTR, DWORD)
+{
+ return 0;
+}
+#endif
+
+// See PCSCDMonitor::addDevice for where this is actually called
+
+int32_t WrapRFAddReader(const char *name, uint32_t address, const char *pathLibrary, const char *deviceName)
+{
+ secdebug("device", "RFAddReader: name: %s, address: %04X, pathLibrary: %s, pathDevice: %s", name, address, pathLibrary, deviceName);
+ return RFAddReader(const_cast<char *>(name), kPCSCLITE_HP_BASE_PORT+address, const_cast<char *>(pathLibrary), const_cast<char *>(deviceName));
+}
+
+int32_t WrapRFRemoveReader(const char *name, uint32_t address)
+{
+ secdebug("device", "RFRemoveReader: name: %s, address: %04X", name, address);
+ return RFRemoveReader(const_cast<char *>(name), kPCSCLITE_HP_BASE_PORT+address);
+}
+
+int32_t WrapRFAwakeAllReaders()
+{
+ secdebug("device", "RFAwakeAllReaders");
+ RFAwakeAllReaders();
+ return 0;
+}
+
+int32_t WrapRFSuspendAllReaders()
+{
+ secdebug("device", "RFSuspendAllReaders");
+ RFSuspendAllReaders();
+ return 0;
+}
+
+static void *HPDeviceNotificationThread(void *foo)
+{
+ try
+ {
+ // Thread runner (does not return)
+ PCSCD::DriverBundles bdls;
+ PCSCD::Server myserv("hotplug");
+ PCSCDMonitor xmon(myserv,bdls);
+ gPCSCDMonitor = &xmon;
+ gMainServerPort = myserv.primaryServicePort();
+ xmon.setCallbacks(WrapRFAddReader, WrapRFRemoveReader, WrapRFSuspendAllReaders, WrapRFAwakeAllReaders);
+ bdls.update();
+ myserv.run();
+ }
+ catch (Security::MachPlusPlus::Error e)
+ {
+ char *perr = (char *)mach_error_string(e.error);
+ if (perr)
+ secdebug("device", "Caught error in xx: %s, error: %04lX", perr, e.osStatus());
+ else
+ secdebug("device", "Caught error in xx: %04X", e.error);
+ }
+ catch (...)
+ {
+ }
+ exit(0);
+ return NULL; // never gets here
+}
+
+void systemAwakeAndReadyCheck()
+{
+ gPCSCDMonitor->systemAwakeAndReadyCheck();
+}
+
+/*
+ * Scans the hotplug driver directory and looks in the system for matching devices.
+ * Adds or removes matching readers as necessary.
+ */
+int32_t HPSearchHotPluggables()
+{
+ // this function is a no-op now
+ return 0;
+}
+
+static pthread_t sHotplugWatcherThread;
+
+int32_t HPRegisterForHotplugEvents()
+{
+ return HPRegisterForHotplugEventsT(&sHotplugWatcherThread);
+}
+
+int32_t HPRegisterForHotplugEventsT(pthread_t *wthread)
+{
+ // Sets up callbacks for device hotplug events
+ int rx = pthread_create(wthread, NULL, HPDeviceNotificationThread, NULL);
+ return rx;
+}
+
+LONG HPStopHotPluggables(void)
+{
+ int rx = pthread_detach(sHotplugWatcherThread);
+ return rx;
+}
+
+void HPReCheckSerialReaders(void)
+{
+}
+
+LONG HPCancelHotPluggables(void)
+{
+ int rx = pthread_cancel(sHotplugWatcherThread);
+ return rx;
+}
+
+LONG HPJoinHotPluggables(void)
+{
+ char *value_ptr;
+ int rx = pthread_join(sHotplugWatcherThread, (void **)&value_ptr);
+ return rx;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdhandler.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdhandler.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdhandler.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,240 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * ifdhandler.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ *
+ * $Id: ifdhandler.h 2348 2007-01-20 15:12:19Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This provides reader specific low-level calls.
+ */
+
+#ifndef _ifd_handler_h_
+#define _ifd_handler_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /*
+ * List of data structures available to ifdhandler
+ */
+
+ typedef struct _DEVICE_CAPABILITIES
+ {
+ LPSTR Vendor_Name; /* Tag 0x0100 */
+ LPSTR IFD_Type; /* Tag 0x0101 */
+ DWORD IFD_Version; /* Tag 0x0102 */
+ LPSTR IFD_Serial; /* Tag 0x0103 */
+ DWORD IFD_Channel_ID; /* Tag 0x0110 */
+
+ DWORD Asynch_Supported; /* Tag 0x0120 */
+ DWORD Default_Clock; /* Tag 0x0121 */
+ DWORD Max_Clock; /* Tag 0x0122 */
+ DWORD Default_Data_Rate; /* Tag 0x0123 */
+ DWORD Max_Data_Rate; /* Tag 0x0124 */
+ DWORD Max_IFSD; /* Tag 0x0125 */
+ DWORD Synch_Supported; /* Tag 0x0126 */
+ DWORD Power_Mgmt; /* Tag 0x0131 */
+ DWORD Card_Auth_Devices; /* Tag 0x0140 */
+ DWORD User_Auth_Device; /* Tag 0x0142 */
+ DWORD Mechanics_Supported; /* Tag 0x0150 */
+ DWORD Vendor_Features; /* Tag 0x0180 - 0x01F0 User Defined. */
+ }
+ DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
+
+ typedef struct _ICC_STATE
+ {
+ UCHAR ICC_Presence; /* Tag 0x0300 */
+ UCHAR ICC_Interface_Status; /* Tag 0x0301 */
+ UCHAR ATR[MAX_ATR_SIZE]; /* Tag 0x0303 */
+ UCHAR ICC_Type; /* Tag 0x0304 */
+ }
+ ICC_STATE, *PICC_STATE;
+
+ typedef struct _PROTOCOL_OPTIONS
+ {
+ DWORD Protocol_Type; /* Tag 0x0201 */
+ DWORD Current_Clock; /* Tag 0x0202 */
+ DWORD Current_F; /* Tag 0x0203 */
+ DWORD Current_D; /* Tag 0x0204 */
+ DWORD Current_N; /* Tag 0x0205 */
+ DWORD Current_W; /* Tag 0x0206 */
+ DWORD Current_IFSC; /* Tag 0x0207 */
+ DWORD Current_IFSD; /* Tag 0x0208 */
+ DWORD Current_BWT; /* Tag 0x0209 */
+ DWORD Current_CWT; /* Tag 0x020A */
+ DWORD Current_EBC; /* Tag 0x020B */
+ }
+ PROTOCOL_OPTIONS, *PPROTOCOL_OPTIONS;
+
+ typedef struct _SCARD_IO_HEADER
+ {
+ DWORD Protocol;
+ DWORD Length;
+ }
+ SCARD_IO_HEADER, *PSCARD_IO_HEADER;
+
+ /*
+ * End of structure list
+ */
+
+ /*
+ * The list of tags should be alot more but this is all I use in the
+ * meantime
+ */
+
+#define TAG_IFD_ATR 0x0303
+#define TAG_IFD_SLOTNUM 0x0180
+#define TAG_IFD_SLOT_THREAD_SAFE 0x0FAC
+#define TAG_IFD_THREAD_SAFE 0x0FAD
+#define TAG_IFD_SLOTS_NUMBER 0x0FAE
+#define TAG_IFD_SIMULTANEOUS_ACCESS 0x0FAF
+
+ /*
+ * End of tag list
+ */
+
+ /*
+ * IFD Handler version number enummerations
+ */
+#define IFD_HVERSION_1_0 0x00010000
+#define IFD_HVERSION_2_0 0x00020000
+#define IFD_HVERSION_3_0 0x00030000
+ /*
+ * End of version number enummerations
+ */
+
+ /*
+ * List of defines available to ifdhandler
+ */
+
+#define IFD_POWER_UP 500
+#define IFD_POWER_DOWN 501
+#define IFD_RESET 502
+
+#define IFD_NEGOTIATE_PTS1 1
+#define IFD_NEGOTIATE_PTS2 2
+#define IFD_NEGOTIATE_PTS3 4
+
+#define IFD_SUCCESS 0
+#define IFD_ERROR_TAG 600
+#define IFD_ERROR_SET_FAILURE 601
+#define IFD_ERROR_VALUE_READ_ONLY 602
+#define IFD_ERROR_PTS_FAILURE 605
+#define IFD_ERROR_NOT_SUPPORTED 606
+#define IFD_PROTOCOL_NOT_SUPPORTED 607
+#define IFD_ERROR_POWER_ACTION 608
+#define IFD_ERROR_SWALLOW 609
+#define IFD_ERROR_EJECT 610
+#define IFD_ERROR_CONFISCATE 611
+#define IFD_COMMUNICATION_ERROR 612
+#define IFD_RESPONSE_TIMEOUT 613
+#define IFD_NOT_SUPPORTED 614
+#define IFD_ICC_PRESENT 615
+#define IFD_ICC_NOT_PRESENT 616
+#define IFD_NO_SUCH_DEVICE 617
+
+// typedef long RESPONSECODE;
+
+ /*
+ * If you want to compile a V2.0 IFDHandler, define IFDHANDLERv2 before you
+ * include this file.
+ *
+ * By default it is setup for for most recent version of the API (V3.0)
+ */
+
+#ifndef IFDHANDLERv2
+
+ /*
+ * List of Defined Functions Available to IFD_Handler 3.0
+ *
+ * All the functions of IFD_Handler 2.0 are available
+ * IFDHCreateChannelByName() is new
+ * IFDHControl() API changed
+ */
+
+ RESPONSECODE IFDHCreateChannelByName(DWORD, LPSTR);
+ RESPONSECODE IFDHControl(DWORD, DWORD, PUCHAR, DWORD, PUCHAR,
+ DWORD, LPDWORD);
+#else
+
+ /*
+ * List of Defined Functions Available to IFD_Handler 2.0
+ */
+
+ RESPONSECODE IFDHControl(DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
+
+#endif
+
+ /*
+ * common functions in IFD_Handler 2.0 and 3.0
+ */
+ RESPONSECODE IFDHCreateChannel(DWORD, DWORD);
+ RESPONSECODE IFDHCloseChannel(DWORD);
+ RESPONSECODE IFDHGetCapabilities(DWORD, DWORD, PDWORD, PUCHAR);
+ RESPONSECODE IFDHSetCapabilities(DWORD, DWORD, DWORD, PUCHAR);
+ RESPONSECODE IFDHSetProtocolParameters(DWORD, DWORD, UCHAR,
+ UCHAR, UCHAR, UCHAR);
+ RESPONSECODE IFDHPowerICC(DWORD, DWORD, PUCHAR, PDWORD);
+ RESPONSECODE IFDHTransmitToICC(DWORD, SCARD_IO_HEADER, PUCHAR,
+ DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ RESPONSECODE IFDHICCPresence(DWORD);
+
+ /*
+ * List of Defined Functions Available to IFD_Handler 1.0
+ */
+
+ RESPONSECODE IO_Create_Channel(DWORD);
+ RESPONSECODE IO_Close_Channel();
+ RESPONSECODE IFD_Get_Capabilities(DWORD, PUCHAR);
+ RESPONSECODE IFD_Set_Capabilities(DWORD, PUCHAR);
+ RESPONSECODE IFD_Set_Protocol_Parameters(DWORD, UCHAR, UCHAR,
+ UCHAR, UCHAR);
+ RESPONSECODE IFD_Power_ICC(DWORD);
+ RESPONSECODE IFD_Swallow_ICC();
+ RESPONSECODE IFD_Eject_ICC();
+ RESPONSECODE IFD_Confiscate_ICC();
+ RESPONSECODE IFD_Transmit_to_ICC(SCARD_IO_HEADER, PUCHAR, DWORD,
+ PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ RESPONSECODE IFD_Is_ICC_Present();
+ RESPONSECODE IFD_Is_ICC_Absent();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,804 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * ifdwrapper.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: ifdwrapper.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This wraps the dynamic ifdhandler functions.
+ */
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "ifdhandler.h"
+#include "debuglog.h"
+#include "readerfactory.h"
+#include "ifdwrapper.h"
+#include "atrhandler.h"
+#include "dyn_generic.h"
+#include "sys_generic.h"
+
+#include <security_utilities/debugging.h>
+
+#undef PCSCLITE_STATIC_DRIVER
+
+/*
+ * Function: IFDSetPTS Purpose : To set the protocol type selection (PTS).
+ * This function sets the appropriate protocol to be used on the card.
+ */
+
+LONG IFDSetPTS(PREADER_CONTEXT rContext, DWORD dwProtocol, UCHAR ucFlags,
+ UCHAR ucPTS1, UCHAR ucPTS2, UCHAR ucPTS3)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+ UCHAR ucValue[1];
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_set_protocol_parameters) (DWORD, UCHAR, UCHAR,
+ UCHAR, UCHAR) = NULL;
+ RESPONSECODE(*IFDH_set_protocol_parameters) (DWORD, DWORD, UCHAR,
+ UCHAR, UCHAR, UCHAR) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ IFD_set_protocol_parameters = (RESPONSECODE(*)(DWORD, UCHAR, UCHAR,
+ UCHAR, UCHAR)) rContext->psFunctions.psFunctions_v1.pvfSetProtocolParameters;
+
+ if (NULL == IFD_set_protocol_parameters)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+ }
+ else
+ {
+ IFDH_set_protocol_parameters = (RESPONSECODE(*)(DWORD, DWORD, UCHAR,
+ UCHAR, UCHAR, UCHAR))
+ rContext->psFunctions.psFunctions_v2.pvfSetProtocolParameters;
+
+ if (NULL == IFDH_set_protocol_parameters)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+ }
+#endif
+
+ /*
+ * Locking is done in winscard.c SCardConnect() and SCardReconnect()
+ *
+ * This avoids renegotiating the protocol and confusing the card
+ * Error returned by CCID driver is: CCID_Receive Procedure byte conflict
+ */
+
+ ucValue[0] = rContext->dwSlot;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = (*IFD_set_protocol_parameters) (dwProtocol,
+ ucFlags, ucPTS1, ucPTS2, ucPTS3);
+ }
+ else
+ {
+ rv = (*IFDH_set_protocol_parameters) (rContext->dwSlot,
+ dwProtocol,
+ ucFlags, ucPTS1,
+ ucPTS2, ucPTS3);
+ }
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = IFD_Set_Protocol_Parameters(dwProtocol, ucFlags, ucPTS1,
+ ucPTS2, ucPTS3);
+ }
+ else
+ {
+ rv = IFDHSetProtocolParameters(rContext->dwSlot, dwProtocol,
+ ucFlags, ucPTS1, ucPTS2, ucPTS3);
+ }
+#endif
+
+ return rv;
+}
+
+/*
+ * Function: IFDOpenIFD Purpose : This function opens a communication
+ * channel to the IFD.
+ */
+
+LONG IFDOpenIFD(PREADER_CONTEXT rContext)
+{
+ RESPONSECODE rv = 0;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IO_create_channel) (DWORD) = NULL;
+ RESPONSECODE(*IFDH_create_channel) (DWORD, DWORD) = NULL;
+ RESPONSECODE(*IFDH_create_channel_by_name) (DWORD, LPSTR) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IO_create_channel =
+ rContext->psFunctions.psFunctions_v1.pvfCreateChannel;
+ else
+ if (rContext->dwVersion == IFD_HVERSION_2_0)
+ IFDH_create_channel =
+ rContext->psFunctions.psFunctions_v2.pvfCreateChannel;
+ else
+ {
+ IFDH_create_channel =
+ rContext->psFunctions.psFunctions_v3.pvfCreateChannel;
+ IFDH_create_channel_by_name =
+ rContext->psFunctions.psFunctions_v3.pvfCreateChannelByName;
+ }
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ rv = (*IO_create_channel) (rContext->dwPort);
+ } else if (rContext->dwVersion == IFD_HVERSION_2_0)
+ {
+ rv = (*IFDH_create_channel) (rContext->dwSlot, rContext->dwPort);
+ } else
+ {
+ /* use device name only if defined */
+ if (rContext->lpcDevice[0] != '\0')
+ rv = (*IFDH_create_channel_by_name) (rContext->dwSlot, rContext->lpcDevice);
+ else
+ rv = (*IFDH_create_channel) (rContext->dwSlot, rContext->dwPort);
+ }
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ rv = IO_Create_Channel(rContext->dwPort);
+ } else if (rContext->dwVersion == IFD_HVERSION_2_0)
+ {
+ rv = IFDHCreateChannel(rContext->dwSlot, rContext->dwPort);
+ } else
+ {
+ /* Use device name only if defined */
+ if (rContext->lpcDevice[0] != '\0')
+ rv = IFDHCreateChannelByName(rContext->dwSlot, rContext->lpcDevice);
+ else
+ rv = IFDHCreateChannel(rContext->dwSlot, rContext->dwPort);
+ }
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ return rv;
+}
+
+/*
+ * Function: IFDCloseIFD Purpose : This function closes a communication
+ * channel to the IFD.
+ */
+
+LONG IFDCloseIFD(PREADER_CONTEXT rContext)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IO_close_channel) () = NULL;
+ RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IO_close_channel = rContext->psFunctions.psFunctions_v1.pvfCloseChannel;
+ else
+ IFDH_close_channel = rContext->psFunctions.psFunctions_v2.pvfCloseChannel;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+
+ rv = (*IO_close_channel) ();
+ else
+ rv = (*IFDH_close_channel) (rContext->dwSlot);
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ rv = IO_Close_Channel();
+ else
+ rv = IFDHCloseChannel(rContext->dwSlot);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ return rv;
+}
+
+/*
+ * Function: IFDSetCapabilites Purpose : This function set's capabilities
+ * in the reader.
+ */
+
+LONG IFDSetCapabilities(PREADER_CONTEXT rContext, DWORD dwTag,
+ DWORD dwLength, PUCHAR pucValue)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_set_capabilities) (DWORD, PUCHAR) = NULL;
+ RESPONSECODE(*IFDH_set_capabilities) (DWORD, DWORD, DWORD, PUCHAR) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IFD_set_capabilities = rContext->psFunctions.psFunctions_v1.pvfSetCapabilities;
+ else
+ IFDH_set_capabilities = rContext->psFunctions.psFunctions_v2.pvfSetCapabilities;
+#endif
+
+ /*
+ * Let the calling function lock this otherwise a deadlock will
+ * result
+ */
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ rv = (*IFD_set_capabilities) (dwTag, pucValue);
+ else
+ rv = (*IFDH_set_capabilities) (rContext->dwSlot, dwTag,
+ dwLength, pucValue);
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ rv = IFD_Set_Capabilities(dwTag, pucValue);
+ else
+ rv = IFDHSetCapabilities(rContext->dwSlot, dwTag, dwLength,
+ pucValue);
+#endif
+
+ return rv;
+}
+
+/*
+ * Function: IFDGetCapabilites Purpose : This function get's capabilities
+ * in the reader. Other functions int this file will call the driver
+ * directly to not cause a deadlock.
+ */
+
+LONG IFDGetCapabilities(PREADER_CONTEXT rContext, DWORD dwTag,
+ PDWORD pdwLength, PUCHAR pucValue)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_get_capabilities) (DWORD, PUCHAR) = NULL;
+ RESPONSECODE(*IFDH_get_capabilities) (DWORD, DWORD, PDWORD, PUCHAR) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IFD_get_capabilities =
+ rContext->psFunctions.psFunctions_v1.pvfGetCapabilities;
+ else
+ IFDH_get_capabilities =
+ rContext->psFunctions.psFunctions_v2.pvfGetCapabilities;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ rv = (*IFD_get_capabilities) (dwTag, pucValue);
+ else
+ rv = (*IFDH_get_capabilities) (rContext->dwSlot, dwTag,
+ pdwLength, pucValue);
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ rv = IFD_Get_Capabilities(dwTag, pucValue);
+ else
+ rv = IFDHGetCapabilities(rContext->dwSlot, dwTag, pdwLength,
+ pucValue);
+#endif
+
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ return rv;
+}
+
+/*
+ * Function: IFDPowerICC Purpose : This function powers up/down or reset's
+ * an ICC located in the IFD.
+ */
+
+LONG IFDPowerICC(PREADER_CONTEXT rContext, DWORD dwAction,
+ const unsigned char *pucAtr, PDWORD pdwAtrLen)
+{
+ RESPONSECODE rv;
+ short ret;
+ SMARTCARD_EXTENSION sSmartCard;
+ DWORD dwStatus;
+ UCHAR ucValue[1];
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_power_icc) (DWORD) = NULL;
+ RESPONSECODE(*IFDH_power_icc) (DWORD, DWORD, PUCHAR, PDWORD) = NULL;
+#endif
+
+ /*
+ * Zero out everything
+ */
+ rv = IFD_SUCCESS;
+ dwStatus = 0;
+ ucValue[0] = 0;
+
+ /*
+ * Check that the card is inserted first
+ */
+ IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
+
+ if (dwStatus & SCARD_ABSENT)
+ return SCARD_W_REMOVED_CARD;
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IFD_power_icc = rContext->psFunctions.psFunctions_v1.pvfPowerICC;
+ else
+ IFDH_power_icc = rContext->psFunctions.psFunctions_v2.pvfPowerICC;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = (*IFD_power_icc) (dwAction);
+ }
+ else
+ {
+ rv = (*IFDH_power_icc) (rContext->dwSlot, dwAction,
+ (unsigned char *)pucAtr, pdwAtrLen);
+
+ ret = ATRDecodeAtr(&sSmartCard, pucAtr, *pdwAtrLen);
+ }
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = IFD_Power_ICC(dwAction);
+ }
+ else
+ rv = IFDHPowerICC(rContext->dwSlot, dwAction, pucAtr, pdwAtrLen);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ /* use clean values in case of error */
+ if (rv != IFD_SUCCESS)
+ {
+ *pdwAtrLen = 0;
+// pucAtr[0] = '\0';
+
+ if (rv == IFD_NO_SUCH_DEVICE)
+ {
+ // SendHotplugSignal();
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ return SCARD_E_NOT_TRANSACTED;
+ }
+
+ /*
+ * Get the ATR and it's length
+ */
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IFDStatusICC(rContext, &dwStatus, pucAtr, pdwAtrLen);
+
+ return rv;
+}
+
+/*
+ * Function: IFDStatusICC Purpose : This function provides statistical
+ * information about the IFD and ICC including insertions, atr, powering
+ * status/etc.
+ */
+
+LONG IFDStatusICC(PREADER_CONTEXT rContext, PDWORD pdwStatus,
+ const unsigned char *pucAtr, PDWORD pdwAtrLen)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+ DWORD dwTag = 0, dwCardStatus = 0;
+ SMARTCARD_EXTENSION sSmartCard;
+ UCHAR ucValue[1] = "\x00";
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_is_icc_present) () = NULL;
+ RESPONSECODE(*IFDH_icc_presence) (DWORD) = NULL;
+ RESPONSECODE(*IFD_get_capabilities) (DWORD, PUCHAR) = NULL;
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ IFD_is_icc_present =
+ rContext->psFunctions.psFunctions_v1.pvfICCPresence;
+ IFD_get_capabilities =
+ rContext->psFunctions.psFunctions_v1.pvfGetCapabilities;
+ }
+ else
+ {
+ IFDH_icc_presence = rContext->psFunctions.psFunctions_v2.pvfICCPresence;
+ // Defensive measure
+ if (!IFDH_icc_presence)
+ return SCARD_E_SYSTEM_CANCELLED;
+ }
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = (*IFD_is_icc_present) ();
+ }
+ else
+ rv = (*IFDH_icc_presence) (rContext->dwSlot);
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = IFD_Is_ICC_Present();
+ }
+ else
+ rv = IFDHICCPresence(rContext->dwSlot);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ if (rv == IFD_SUCCESS || rv == IFD_ICC_PRESENT)
+ dwCardStatus |= SCARD_PRESENT;
+ else
+ if (rv == IFD_ICC_NOT_PRESENT)
+ dwCardStatus |= SCARD_ABSENT;
+ else
+ {
+ Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+ *pdwStatus = SCARD_UNKNOWN;
+
+ if (rv == IFD_NO_SUCH_DEVICE)
+ {
+ // SendHotplugSignal();
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ return SCARD_E_NOT_TRANSACTED;
+ }
+
+ /*
+ * Now lets get the ATR and process it if IFD Handler version 1.0.
+ * IFD Handler version 2.0 does this immediately after reset/power up
+ * to conserve resources
+ */
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ if (rv == IFD_SUCCESS || rv == IFD_ICC_PRESENT)
+ {
+ short ret;
+
+ dwTag = TAG_IFD_ATR;
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ rv = (*IFD_get_capabilities) (dwTag, (unsigned char *)pucAtr);
+#else
+ rv = IFD_Get_Capabilities(dwTag, pucAtr);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ /*
+ * FIX :: This is a temporary way to return the correct size
+ * of the ATR since most of the drivers return MAX_ATR_SIZE
+ */
+
+ ret = ATRDecodeAtr(&sSmartCard, pucAtr, MAX_ATR_SIZE);
+
+ /*
+ * Might be a memory card without an ATR
+ */
+ if (ret == 0)
+ *pdwAtrLen = 0;
+ else
+ *pdwAtrLen = sSmartCard.ATR.Length;
+ }
+ else
+ {
+ /*
+ * No card is inserted - Atr length is 0
+ */
+ *pdwAtrLen = 0;
+ }
+ /*
+ * End of FIX
+ */
+ }
+
+ *pdwStatus = dwCardStatus;
+
+ return SCARD_S_SUCCESS;
+}
+
+/*
+ * Function: IFDControl Purpose : This function provides a means for
+ * toggling a specific action on the reader such as swallow, eject,
+ * biometric.
+ */
+
+/*
+ * Valid only for IFDHandler version 2.0
+ */
+
+LONG IFDControl_v2(PREADER_CONTEXT rContext, PUCHAR TxBuffer,
+ DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFDH_control_v2) (DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
+#endif
+
+ if (rContext->dwVersion != IFD_HVERSION_2_0)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ IFDH_control_v2 = rContext->psFunctions.psFunctions_v2.pvfControl;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+ SYS_MutexLock(rContext->mMutex);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ rv = (*IFDH_control_v2) (rContext->dwSlot, TxBuffer, TxLength,
+ RxBuffer, RxLength);
+#else
+ rv = IFDHControl_v2(rContext->dwSlot, TxBuffer, TxLength,
+ RxBuffer, RxLength);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+ /*
+ * END OF LOCKED REGION
+ */
+
+ if (rv == IFD_SUCCESS)
+ return SCARD_S_SUCCESS;
+ else
+ {
+ Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+ return SCARD_E_NOT_TRANSACTED;
+ }
+}
+
+/*
+ * Function: IFDControl Purpose : This function provides a means for
+ * toggling a specific action on the reader such as swallow, eject,
+ * biometric.
+ */
+
+/*
+ * Valid only for IFDHandler version 3.0 and up
+ */
+
+LONG IFDControl(PREADER_CONTEXT rContext, DWORD ControlCode,
+ LPCVOID TxBuffer, DWORD TxLength, LPVOID RxBuffer, DWORD RxLength,
+ LPDWORD BytesReturned)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFDH_control) (DWORD, DWORD, LPCVOID, DWORD, LPVOID, DWORD, LPDWORD);
+#endif
+
+ if (rContext->dwVersion < IFD_HVERSION_3_0)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ IFDH_control = rContext->psFunctions.psFunctions_v3.pvfControl;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ rv = (*IFDH_control) (rContext->dwSlot, ControlCode, TxBuffer,
+ TxLength, RxBuffer, RxLength, BytesReturned);
+#else
+ rv = IFDHControl(rContext->dwSlot, ControlCode, TxBuffer,
+ TxLength, RxBuffer, RxLength, BytesReturned);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ if (rv == IFD_SUCCESS)
+ return SCARD_S_SUCCESS;
+ else
+ {
+ Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+
+ if (rv == IFD_NO_SUCH_DEVICE)
+ {
+// SendHotplugSignal();
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ return SCARD_E_NOT_TRANSACTED;
+ }
+}
+
+/*
+ * Function: IFDTransmit Purpose : This function transmits an APDU to the
+ * ICC.
+ */
+
+LONG IFDTransmit(PREADER_CONTEXT rContext, SCARD_IO_HEADER pioTxPci,
+ PUCHAR pucTxBuffer, DWORD dwTxLength, PUCHAR pucRxBuffer,
+ PDWORD pdwRxLength, PSCARD_IO_HEADER pioRxPci)
+{
+ RESPONSECODE rv = IFD_SUCCESS;
+ UCHAR ucValue[1] = "\x00";
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ RESPONSECODE(*IFD_transmit_to_icc) (SCARD_IO_HEADER, PUCHAR, DWORD,
+ PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
+ RESPONSECODE(*IFDH_transmit_to_icc) (DWORD, SCARD_IO_HEADER, PUCHAR,
+ DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
+#endif
+
+ /* log the APDU */
+ DebugLogCategory(DEBUG_CATEGORY_APDU, pucTxBuffer, dwTxLength);
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ IFD_transmit_to_icc =
+ rContext->psFunctions.psFunctions_v1.pvfTransmitToICC;
+ else
+ IFDH_transmit_to_icc =
+ rContext->psFunctions.psFunctions_v2.pvfTransmitToICC;
+#endif
+
+ /*
+ * LOCK THIS CODE REGION
+ */
+
+ SYS_MutexLock(rContext->mMutex);
+
+
+#ifndef PCSCLITE_STATIC_DRIVER
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = (*IFD_transmit_to_icc) (pioTxPci, (LPBYTE) pucTxBuffer,
+ dwTxLength, pucRxBuffer, pdwRxLength, pioRxPci);
+ }
+ else
+ rv = (*IFDH_transmit_to_icc) (rContext->dwSlot, pioTxPci,
+ (LPBYTE) pucTxBuffer, dwTxLength,
+ pucRxBuffer, pdwRxLength, pioRxPci);
+#else
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ ucValue[0] = rContext->dwSlot;
+ IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
+ rv = IFD_Transmit_to_ICC(pioTxPci, (LPBYTE) pucTxBuffer,
+ dwTxLength, pucRxBuffer, pdwRxLength, pioRxPci);
+ }
+ else
+ rv = IFDHTransmitToICC(rContext->dwSlot, pioTxPci,
+ (LPBYTE) pucTxBuffer, dwTxLength,
+ pucRxBuffer, pdwRxLength, pioRxPci);
+#endif
+ SYS_MutexUnLock(rContext->mMutex);
+
+ /*
+ * END OF LOCKED REGION
+ */
+
+ /* log the returned status word */
+ DebugLogCategory(DEBUG_CATEGORY_SW, pucRxBuffer, *pdwRxLength);
+
+ if (rv == IFD_SUCCESS)
+ return SCARD_S_SUCCESS;
+ else
+ {
+ Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
+
+ if (rv == IFD_NO_SUCH_DEVICE)
+ {
+ // SendHotplugSignal();
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ return SCARD_E_NOT_TRANSACTED;
+ }
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/ifdwrapper.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * ifdwrapper.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Ludovic Rousseau <ludovic.rouseau at free.fr>
+ *
+ * $Id: ifdwrapper.h 2151 2006-09-06 20:02:47Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This wraps the dynamic ifdhandler functions. The abstraction will
+ * eventually allow multiple card slots in the same terminal.
+ */
+
+#ifndef __ifdwrapper_h__
+#define __ifdwrapper_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ LONG IFDOpenIFD(PREADER_CONTEXT);
+ LONG IFDCloseIFD(PREADER_CONTEXT);
+ LONG IFDPowerICC(PREADER_CONTEXT, DWORD, const unsigned char *, PDWORD);
+ LONG IFDStatusICC(PREADER_CONTEXT, PDWORD, const unsigned char *, PDWORD);
+ LONG IFDControl_v2(PREADER_CONTEXT, PUCHAR, DWORD, PUCHAR, PDWORD);
+ LONG IFDControl(PREADER_CONTEXT, DWORD, LPCVOID, DWORD, LPVOID,
+ DWORD, LPDWORD);
+ LONG IFDTransmit(PREADER_CONTEXT, SCARD_IO_HEADER,
+ PUCHAR, DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ LONG IFDSetPTS(PREADER_CONTEXT, DWORD, UCHAR, UCHAR, UCHAR, UCHAR);
+ LONG IFDSetCapabilities(PREADER_CONTEXT, DWORD, DWORD, PUCHAR);
+ LONG IFDGetCapabilities(PREADER_CONTEXT, DWORD, PDWORD, PUCHAR);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ifdwrapper_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/mscdefines.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/mscdefines.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/mscdefines.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : mscdefines.h
+ Package: MuscleCard Framework
+ Author : David Corcoran
+ Date : 10/02/01
+ License: Copyright (C) 2001-2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This provides high level definitions for
+ data types, structures.
+
+ You may not remove this header from this file
+ without prior permission from the author.
+
+********************************************************************/
+
+#ifndef __mscdefines_h__
+#define __mscdefines_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef WIN32
+#include "../win32/win32_pcsclite.h"
+#else
+#include "pcsclite.h"
+#endif
+
+#ifndef __APPLE__
+#include <winscard.h>
+#else
+#include <PCSC/winscard.h>
+#endif
+
+#include <stdint.h>
+
+#ifdef MSC_ARCH_WIN32
+#define MAX_BUFFER_SIZE 265
+#endif
+
+ /*
+ * Some type defines used in MuscleCard
+ */
+
+ typedef uint32_t MSC_RV;
+ typedef char MSCChar8;
+ typedef uint8_t *MSCPUChar8;
+ typedef const uint8_t *MSCPCUChar8;
+ typedef uint8_t MSCUChar8;
+ typedef uint16_t *MSCPUShort16;
+ typedef uint16_t MSCUShort16;
+ typedef int16_t *MSCPShort16;
+ typedef int16_t MSCShort16;
+ typedef uint32_t *MSCPULong32;
+ typedef uint32_t MSCULong32;
+ typedef int32_t *MSCPLong32;
+ typedef int32_t MSCLong32;
+ typedef const void *MSCPCVoid32;
+ typedef void *MSCPVoid32;
+ typedef const char *MSCCString;
+ typedef char *MSCString;
+
+ typedef struct
+ {
+ MSCPVoid32 pvfWriteFramework;
+ MSCPVoid32 pvfInitializePlugin;
+ MSCPVoid32 pvfIdentifyToken;
+ MSCPVoid32 pvfFinalizePlugin;
+ MSCPVoid32 pvfGetStatus;
+ MSCPVoid32 pvfGetCapabilities;
+ MSCPVoid32 pvfExtendedFeature;
+ MSCPVoid32 pvfGenerateKeys;
+ MSCPVoid32 pvfImportKey;
+ MSCPVoid32 pvfExportKey;
+ MSCPVoid32 pvfComputeCrypt;
+ MSCPVoid32 pvfExtAuthenticate;
+ MSCPVoid32 pvfListKeys;
+ MSCPVoid32 pvfCreatePIN;
+ MSCPVoid32 pvfVerifyPIN;
+ MSCPVoid32 pvfChangePIN;
+ MSCPVoid32 pvfUnblockPIN;
+ MSCPVoid32 pvfListPINs;
+ MSCPVoid32 pvfCreateObject;
+ MSCPVoid32 pvfDeleteObject;
+ MSCPVoid32 pvfWriteObject;
+ MSCPVoid32 pvfReadObject;
+ MSCPVoid32 pvfListObjects;
+ MSCPVoid32 pvfLogoutAll;
+ MSCPVoid32 pvfGetChallenge;
+
+ }
+ CFDyLibPointers, *LPCFDyLibPointers;
+
+#define MSC_MAXSIZE_TOKENAME 150
+#define MSC_MAXSIZE_SVCPROV 200
+#define MSC_MAXSIZE_OBJID 16
+#define MSC_MAXSIZE_AID 64
+#define MSC_MAXSIZE_MAC 128
+#define MSC_MAXSIZE_LABEL 32
+#define MSC_MAXSIZE_CERT_ISSUER 512
+#define MSC_MAXSIZE_CERT_SUBJECT 512
+#define MSC_MAXSIZE_CERT_SERIAL 512
+#define MSC_MAXSIZE_BUFFER MAX_BUFFER_SIZE
+
+ typedef struct
+ {
+ MSCChar8 tokenName[MSC_MAXSIZE_TOKENAME]; /* Token name */
+ MSCChar8 slotName[MAX_READERNAME]; /* Slot/reader name */
+ MSCChar8 svProvider[MSC_MAXSIZE_SVCPROV]; /* Library */
+ MSCUChar8 tokenId[MAX_ATR_SIZE]; /* Token ID (ATR) */
+ MSCUChar8 tokenApp[MSC_MAXSIZE_AID]; /* Default app ID */
+ MSCULong32 tokenAppLen; /* Default AID Length */
+ MSCULong32 tokenIdLength; /* ID Length (ATR Length) */
+ MSCULong32 tokenState; /* State (dwEventState) */
+ MSCULong32 tokenType; /* Type - RFU */
+ MSCPVoid32 addParams; /* Additional Data */
+ MSCULong32 addParamsSize; /* Size of additional data */
+ }
+ MSCTokenInfo, *MSCLPTokenInfo;
+
+ /*
+ * Callback function definitions
+ */
+
+ typedef MSCULong32(*MSCCallBack) (MSCLPTokenInfo, MSCULong32,
+ MSCPVoid32);
+
+ typedef struct
+ {
+ MSCULong32 arraySize;
+ MSCLPTokenInfo tokenArray;
+ MSCPVoid32 appData;
+ MSCCallBack callBack;
+ }
+ MSCEventWaitInfo, *MSCLPEventWaitInfo;
+
+ typedef MSC_RV(*LPRWEventCallback) (MSCPVoid32, int);
+
+ typedef struct
+ {
+ MSCLong32 hContext; /* Handle to resource manager */
+ MSCLong32 hCard; /* Handle to the connection */
+ LPSCARD_IO_REQUEST ioType; /* Type of protocol */
+ MSCUChar8 pMac[MSC_MAXSIZE_MAC]; /* MAC code */
+ MSCULong32 macSize; /* Size of the MAC code */
+ MSCPVoid32 tokenLibHandle; /* Handle to token library */
+ CFDyLibPointers libPointers; /* Function pointers */
+ MSCTokenInfo tokenInfo; /* token information */
+ MSCUChar8 loggedIDs; /* Verification bit mask */
+ MSCULong32 shareMode; /* Sharing mode for this */
+ LPRWEventCallback rwCallback; /* Registered callback */
+ }
+ MSCTokenConnection, *MSCLPTokenConnection;
+
+#define MSC_OK MSC_SUCCESS
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __mscdefines_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,2285 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : musclecard.c
+ Package: MuscleCard Framework
+ Author : David Corcoran
+ Date : 09/26/01
+ License: Copyright (C) 2001-2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This loads MuscleCard plug-ins and provides
+ functions for applications.
+
+ You may not remove this header from this file without
+ prior permission from the author.
+
+********************************************************************/
+
+#ifndef WIN32
+#include "config.h"
+#else
+#include "../win32/win32_config.h"
+#endif
+
+#include "musclecard.h"
+#include "tokenfactory.h"
+#include "debuglog.h"
+
+#ifdef USE_THREAD_SAFETY
+#ifndef WIN32
+#include "wintypes.h"
+#endif
+#include "thread_generic.h"
+#include "sys_generic.h"
+#endif
+
+#ifdef USE_THREAD_SAFETY
+static PCSCLITE_MUTEX mcardMutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static SCARDCONTEXT localHContext = 0;
+
+#ifdef USE_THREAD_SAFETY
+static PCSCLITE_THREAD_T callbackThread;
+#endif
+
+/*
+ * internal function
+ */
+MSC_RV pcscToMSC(MSCLong32);
+MSC_RV MSCReEstablishConnection(MSCLPTokenConnection);
+
+void mscLockThread()
+{
+#ifdef USE_THREAD_SAFETY
+ SYS_MutexLock(&mcardMutex);
+#endif
+}
+
+void mscUnLockThread()
+{
+#ifdef USE_THREAD_SAFETY
+ SYS_MutexUnLock(&mcardMutex);
+#endif
+}
+
+/**************** MSC Connection Functions **************************/
+
+MSC_RV MSCListTokens(MSCULong32 listScope, MSCLPTokenInfo tokenArray,
+ MSCPULong32 arrayLength)
+{
+
+ MSCLong32 rv;
+ SCARD_READERSTATE_A rgReaderStates;
+ MSCTokenInfo tokenInfo;
+ MSCLPTokenInfo currentToken;
+ MSCULong32 tokensFound;
+ MSCULong32 readerLength;
+ char *readerList;
+ int i, strLoc;
+
+ readerLength = 0;
+ tokensFound = 0;
+ readerList = 0;
+ strLoc = 0;
+ i = 0;
+
+ if (arrayLength == 0)
+ return MSC_INVALID_PARAMETER;
+ if (listScope != MSC_LIST_KNOWN &&
+ listScope != MSC_LIST_ALL && listScope != MSC_LIST_SLOTS)
+ {
+ return MSC_INVALID_PARAMETER;
+ }
+
+ mscLockThread();
+ if (localHContext == 0)
+ {
+ rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0,
+ &localHContext);
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ localHContext = 0;
+ mscUnLockThread();
+ return pcscToMSC(rv);
+ }
+ }
+ mscUnLockThread();
+
+ /*
+ * Get the reader list size
+ */
+ rv = SCardListReaders(localHContext, 0, readerList, &readerLength);
+
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ return pcscToMSC(rv);
+ }
+
+ readerList = (char *) malloc(sizeof(char) * readerLength);
+
+ if (readerList == 0)
+ {
+ return MSC_INTERNAL_ERROR;
+ }
+
+ rv = SCardListReaders(localHContext, 0, readerList, &readerLength);
+
+ /*
+ * Now that we have the readers, lets check their status
+ */
+ for (i = 0; i < readerLength - 1; i++)
+ {
+ rgReaderStates.szReader = &readerList[i];
+ rgReaderStates.dwCurrentState = SCARD_STATE_UNAWARE;
+
+ rv = SCardGetStatusChange(localHContext, INFINITE,
+ &rgReaderStates,
+ 1);
+
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ if (readerList)
+ free(readerList);
+ return pcscToMSC(rv);
+ }
+
+ /*
+ * We only care about slots with a token unless stated
+ */
+ if ((rgReaderStates.dwEventState & SCARD_STATE_PRESENT) ||
+ (listScope == MSC_LIST_SLOTS))
+ {
+
+ if (rgReaderStates.dwEventState & SCARD_STATE_PRESENT)
+ {
+ /*
+ * We only care about supported tokens
+ */
+ rv = TPSearchBundlesForAtr(rgReaderStates.rgbAtr,
+ rgReaderStates.cbAtr, &tokenInfo);
+ }
+
+ /*
+ * Success for this function
+ */
+ if ((rv == 0) || (listScope == MSC_LIST_SLOTS) ||
+ (listScope == MSC_LIST_ALL))
+ {
+
+ /*
+ * We found something interesting to the application
+ */
+ tokensFound += 1;
+
+ if ((tokensFound <= *arrayLength) && (tokenArray != 0))
+ {
+ currentToken = &tokenArray[tokensFound - 1];
+ currentToken->addParams = 0;
+ currentToken->addParamsSize = 0;
+ currentToken->tokenType = 0; /* Vinnie 1693 */
+
+ if (rgReaderStates.dwEventState & SCARD_STATE_EMPTY)
+ {
+ currentToken->tokenType |= MSC_TOKEN_TYPE_REMOVED;
+ strncpy(currentToken->tokenName,
+ MSC_TOKEN_EMPTY_STR, MSC_MAXSIZE_TOKENAME);
+ } else if (rv == 0)
+ {
+ currentToken->tokenType |= MSC_TOKEN_TYPE_KNOWN;
+ strncpy(currentToken->tokenName,
+ tokenInfo.tokenName, MSC_MAXSIZE_TOKENAME);
+ } else
+ {
+ currentToken->tokenType |= MSC_TOKEN_TYPE_UNKNOWN;
+ strncpy(currentToken->tokenName,
+ MSC_TOKEN_UNKNOWN_STR, MSC_MAXSIZE_TOKENAME);
+ }
+
+ strncpy(currentToken->slotName,
+ rgReaderStates.szReader, MAX_READERNAME);
+
+ if (rgReaderStates.dwEventState & SCARD_STATE_PRESENT)
+ {
+ memcpy(currentToken->tokenId,
+ rgReaderStates.rgbAtr, rgReaderStates.cbAtr);
+ currentToken->tokenIdLength = rgReaderStates.cbAtr;
+ }
+ else
+ {
+ memset(currentToken->tokenId, 0x00, MAX_ATR_SIZE);
+ currentToken->tokenIdLength = 0x00;
+ }
+
+ if (rv == 0)
+ {
+ memcpy(currentToken->tokenApp,
+ tokenInfo.tokenApp, tokenInfo.tokenAppLen);
+ currentToken->tokenAppLen = tokenInfo.tokenAppLen;
+
+ strncpy(currentToken->svProvider,
+ tokenInfo.svProvider, MSC_MAXSIZE_SVCPROV);
+ } else
+ {
+ memset(currentToken->tokenApp, 0x00, MSC_MAXSIZE_AID);
+ currentToken->tokenAppLen = 0x00;
+ memset(currentToken->svProvider, 0x00, MSC_MAXSIZE_SVCPROV);
+ }
+
+ currentToken->tokenState = rgReaderStates.dwEventState;
+
+ }
+ }
+ /*
+ * End of TPSearch success
+ */
+ }
+ /*
+ * End of if token present
+ */
+ while (readerList[++i] != 0) ;
+ } /* End of for .. readers */
+
+ if (readerList)
+ free(readerList);
+
+ /*
+ * Application provides null requesting length
+ */
+ if (tokenArray == 0)
+ {
+ *arrayLength = tokensFound;
+ return MSC_SUCCESS;
+ }
+
+ /*
+ * Provided length is too small
+ */
+ if (*arrayLength < tokensFound)
+ {
+ *arrayLength = tokensFound;
+ return MSC_INSUFFICIENT_BUFFER;
+ }
+
+ *arrayLength = tokensFound;
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCEstablishConnection(MSCLPTokenInfo tokenStruct,
+ MSCULong32 sharingMode,
+ MSCPUChar8 applicationName,
+ MSCULong32 nameSize,
+ MSCLPTokenConnection pConnection)
+{
+ MSCLong32 rv;
+ MSCULong32 tokenSize;
+ MSCLPTokenInfo tokenList;
+ MSCPVoid32 vInitFunction;
+ MSCPVoid32 vIdFunction;
+ MSCLong32(*libPL_MSCInitializePlugin) (MSCLPTokenConnection);
+ MSCLong32(*libPL_MSCIdentifyToken) (MSCLPTokenConnection);
+ MSCULong32 dwActiveProtocol;
+ int selectedIFD;
+ char slotName[MAX_READERNAME];
+ MSCULong32 slotNameSize, slotState, slotProtocol;
+ MSCUChar8 tokenId[MAX_ATR_SIZE];
+ MSCULong32 tokenIdLength;
+
+ tokenSize = 0;
+ tokenList = 0;
+ tokenSize = 0;
+ selectedIFD = -1;
+ tokenIdLength = sizeof(tokenId);
+ slotState = 0;
+ slotProtocol = 0;
+ slotNameSize = sizeof(slotName);
+ vIdFunction = 0;
+ vInitFunction = 0;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (tokenStruct == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (nameSize > MSC_MAXSIZE_AID)
+ return MSC_INVALID_PARAMETER;
+
+ pConnection->tokenLibHandle = 0;
+ pConnection->hContext = 0;
+ pConnection->tokenInfo.tokenIdLength = 0;
+ pConnection->shareMode = 0;
+
+ /*
+ * Check the token name strings
+ */
+ if (sharingMode != MSC_SHARE_DIRECT)
+ {
+ if (strcmp(tokenStruct->tokenName, MSC_TOKEN_EMPTY_STR) == 0)
+ {
+ return MSC_TOKEN_REMOVED;
+ } else if (strcmp(tokenStruct->tokenName,
+ MSC_TOKEN_UNKNOWN_STR) == 0)
+ {
+ return MSC_UNRECOGNIZED_TOKEN;
+ }
+ }
+
+ /*
+ * Set up the initial connection to the resource manager
+ */
+
+ mscLockThread();
+ if (localHContext == 0)
+ {
+ rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0,
+ &localHContext);
+#ifdef MSC_DEBUG
+ DebugLogB("SCardEstablishContext returns %s\n",
+ pcsc_stringify_error(rv));
+#endif
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ localHContext = 0;
+ mscUnLockThread();
+ return pcscToMSC(rv);
+ }
+
+ pConnection->hContext = localHContext;
+ } else
+ {
+ pConnection->hContext = localHContext;
+ }
+ mscUnLockThread();
+
+#ifdef WIN32
+ rv = SCardConnect(pConnection->hContext, tokenStruct->slotName,
+ SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+ &pConnection->hCard, &dwActiveProtocol);
+#else
+ rv = SCardConnect(pConnection->hContext, tokenStruct->slotName,
+ sharingMode, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+ &pConnection->hCard, &dwActiveProtocol);
+#endif
+
+#ifdef MSC_DEBUG
+ DebugLogB("SCardConnect returns %s\n", pcsc_stringify_error(rv));
+#endif
+
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ return pcscToMSC(rv);
+ }
+
+ /*
+ * Set the sendPCI value based on the ActiveProtocol
+ */
+ switch (dwActiveProtocol)
+ {
+ case SCARD_PROTOCOL_T0:
+ pConnection->ioType = SCARD_PCI_T0;
+ break;
+ case SCARD_PROTOCOL_T1:
+ pConnection->ioType = SCARD_PCI_T1;
+ break;
+ default:
+ pConnection->ioType = SCARD_PCI_RAW;
+ break;
+ }
+
+ /*
+ * Call SCardStatus, make sure the card information matches if it does
+ * not return an error. If it does, copy it
+ */
+
+ rv = SCardStatus(pConnection->hCard, slotName,
+ &slotNameSize, &slotState, &slotProtocol, tokenId, &tokenIdLength);
+
+#ifdef MSC_DEBUG
+ DebugLogB("SCardStatus returns %s\n", pcsc_stringify_error(rv));
+#endif
+
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ pConnection->hCard = 0;
+ return pcscToMSC(rv);
+ }
+
+ if ((sharingMode == MSC_SHARE_DIRECT) && (slotState & SCARD_ABSENT))
+ {
+
+ /*
+ * They asked for direct mode and no card is inserted so we are
+ * done with this
+ */
+ pConnection->shareMode = sharingMode;
+ return MSC_SUCCESS;
+ }
+
+ if ((tokenIdLength != tokenStruct->tokenIdLength) ||
+ (strcmp(slotName, tokenStruct->slotName) != 0) ||
+ (memcmp(tokenId, tokenStruct->tokenId, tokenIdLength) != 0))
+ {
+ DebugLogA("Internal inconsistent values, ID, slotName\n");
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ pConnection->hCard = 0;
+ return MSC_INCONSISTENT_STATUS;
+ }
+
+ memcpy(pConnection->tokenInfo.tokenId, tokenId, tokenIdLength);
+ pConnection->tokenInfo.tokenIdLength = tokenIdLength;
+ strncpy(pConnection->tokenInfo.slotName, tokenStruct->slotName,
+ MAX_READERNAME);
+ strncpy(pConnection->tokenInfo.tokenName, tokenStruct->tokenName,
+ MSC_MAXSIZE_TOKENAME);
+
+ /*
+ * Load the library for the token
+ */
+ rv = TPLoadToken(pConnection);
+
+#ifdef MSC_DEBUG
+ DebugLogB("TPLoadToken returns %s\n", pcsc_stringify_error(rv));
+#endif
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ pConnection->hCard = 0;
+ return pcscToMSC(rv);
+ }
+
+ /*
+ * Select the AID or initialization routine for the card
+ */
+ vInitFunction = pConnection->libPointers.pvfInitializePlugin;
+ vIdFunction = pConnection->libPointers.pvfIdentifyToken;
+
+ if (vInitFunction == 0)
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "InitializePlugin function missing");
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ pConnection->hCard = 0;
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ if (vIdFunction == 0)
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "IdentifyToken function missing");
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ pConnection->hCard = 0;
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ libPL_MSCInitializePlugin = (MSCLong32(*)(MSCLPTokenConnection))
+ vInitFunction;
+
+ libPL_MSCIdentifyToken = (MSCLong32(*)(MSCLPTokenConnection))
+ vIdFunction;
+
+ rv = (*libPL_MSCInitializePlugin) (pConnection);
+
+ if (rv != MSC_SUCCESS)
+ {
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ if (pConnection->tokenLibHandle != 0)
+ {
+ TPUnloadToken(pConnection);
+ pConnection->tokenLibHandle = 0;
+ }
+ pConnection->hCard = 0;
+ }
+
+ if (sharingMode != MSC_SHARE_DIRECT)
+ {
+
+ if ((applicationName == 0) || (nameSize == 0))
+ {
+ /*
+ * Use the default AID given by the Info.plist
+ */
+
+ rv = (*libPL_MSCIdentifyToken) (pConnection);
+ } else
+ {
+ pConnection->tokenInfo.tokenAppLen = nameSize;
+ memcpy(pConnection->tokenInfo.tokenApp,
+ applicationName, nameSize);
+ rv = (*libPL_MSCIdentifyToken) (pConnection);
+ }
+
+#ifdef MSC_DEBUG
+ DebugLogB("MSCIdentifyToken returns %s\n", msc_error(rv));
+#endif
+
+ if (rv != MSC_SUCCESS)
+ {
+ SCardDisconnect(pConnection->hCard, SCARD_LEAVE_CARD);
+ if (pConnection->tokenLibHandle != 0)
+ {
+ TPUnloadToken(pConnection);
+ pConnection->tokenLibHandle = 0;
+ }
+ pConnection->hCard = 0;
+
+ if (rv == MSC_SHARING_VIOLATION)
+ {
+ return rv;
+ } else
+ {
+ return MSC_UNRECOGNIZED_TOKEN;
+ }
+ }
+ }
+
+ pConnection->shareMode = sharingMode;
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCReleaseConnection(MSCLPTokenConnection pConnection,
+ MSCULong32 endAction)
+{
+
+ MSCLong32 rv = SCARD_S_SUCCESS;
+ MSCLong32(*libPL_MSCFinalizePlugin) (MSCLPTokenConnection);
+ MSCPVoid32 vFunction;
+
+ vFunction = 0;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (pConnection->tokenLibHandle == 0 ||
+ pConnection->hContext == 0 || pConnection->hCard == 0)
+ {
+ return MSC_INVALID_HANDLE;
+ }
+
+ /*
+ * Select finalization routine for the token plugin
+ */
+ vFunction = pConnection->libPointers.pvfFinalizePlugin;
+
+ if (vFunction == 0)
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "FinalizePlugin function missing");
+ return MSC_INTERNAL_ERROR;
+ }
+
+ libPL_MSCFinalizePlugin = (MSCLong32(*)(MSCLPTokenConnection))
+ vFunction;
+
+ /*
+ * Stop and clean up the plugin
+ */
+ rv = (*libPL_MSCFinalizePlugin) (pConnection);
+
+ /*
+ * Disconnect from the token
+ */
+ if (pConnection->hCard != 0)
+ {
+ rv = SCardDisconnect(pConnection->hCard, endAction);
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ return pcscToMSC(rv);
+ }
+ }
+
+ /*
+ * Unload the token driver
+ */
+ if (pConnection->tokenLibHandle != 0)
+ {
+ rv = TPUnloadToken(pConnection);
+ pConnection->tokenLibHandle = 0;
+ }
+
+ pConnection->tokenLibHandle = 0;
+ pConnection->hCard = 0;
+ pConnection->hContext = 0;
+ pConnection->shareMode = 0;
+
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCWaitForTokenEvent(MSCLPTokenInfo tokenArray,
+ MSCULong32 arraySize,
+ MSCULong32 timeoutValue)
+{
+
+ MSCLong32 rv, rt;
+ LPSCARD_READERSTATE_A rgReaderStates;
+ MSCTokenInfo tokenInfo;
+ int i;
+
+ rgReaderStates = 0;
+
+ /*
+ * Allocate array of SCARD_READERSTATE_A structures, set UNAWARE on
+ * all of the structures to get the current status and then send them
+ * to GetStatusChange for blocking event
+ */
+
+ if (arraySize == 0)
+ {
+ return MSC_SUCCESS;
+ } else if (arraySize > MSC_MAXSIZE_TOKENARRAY)
+ {
+ return MSC_INSUFFICIENT_BUFFER;
+ }
+
+ /*
+ * Set up the initial connection to the resource manager
+ */
+
+ mscLockThread();
+ if (localHContext == 0)
+ {
+ rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0,
+ &localHContext);
+ if (pcscToMSC(rv) != MSC_SUCCESS)
+ {
+ localHContext = 0;
+ mscUnLockThread();
+ return pcscToMSC(rv);
+ }
+ }
+ mscUnLockThread();
+
+ rgReaderStates = (LPSCARD_READERSTATE_A)
+ malloc(sizeof(SCARD_READERSTATE_A) * arraySize);
+
+ if (rgReaderStates == 0)
+ {
+ return MSC_INTERNAL_ERROR;
+ }
+
+ for (i = 0; i < arraySize; i++)
+ {
+ /*
+ * Make sure they don't pass an empty structure
+ */
+ if (strlen(tokenArray[i].slotName) == 0)
+ {
+ free(rgReaderStates);
+ return MSC_INVALID_PARAMETER;
+ }
+
+ rgReaderStates[i].szReader = tokenArray[i].slotName;
+ rgReaderStates[i].dwCurrentState = SCARD_STATE_UNAWARE;
+ rgReaderStates[i].dwEventState = 0;
+ }
+
+ rv = SCardGetStatusChange(localHContext, timeoutValue,
+ rgReaderStates, arraySize);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ free(rgReaderStates);
+ return pcscToMSC(rv);
+ }
+
+ for (i = 0; i < arraySize; i++)
+ {
+ if (tokenArray[i].tokenState == 0)
+ {
+ rgReaderStates[i].dwCurrentState =
+ rgReaderStates[i].dwEventState;
+ } else if (tokenArray[i].tokenState == MSC_STATE_UNAWARE)
+ {
+ rgReaderStates[i].dwCurrentState = SCARD_STATE_UNAWARE;
+ } else
+ {
+ rgReaderStates[i].dwCurrentState = tokenArray[i].tokenState;
+ }
+ rgReaderStates[i].dwEventState = 0;
+ }
+
+ rv = SCardGetStatusChange(localHContext, timeoutValue,
+ rgReaderStates, arraySize);
+
+ for (i = 0; i < arraySize; i++)
+ {
+ tokenArray[i].tokenState = rgReaderStates[i].dwEventState;
+
+ if (tokenArray[i].tokenState & MSC_STATE_CHANGED)
+ {
+ /*
+ * If it is removed, we need to update the names/etc
+ */
+ if (tokenArray[i].tokenState & MSC_STATE_EMPTY)
+ {
+ memset(tokenArray[i].tokenId, 0x00, MAX_ATR_SIZE);
+ tokenArray[i].tokenIdLength = 0;
+ tokenArray[i].tokenType = MSC_TOKEN_TYPE_REMOVED;
+ strncpy(tokenArray[i].tokenName, MSC_TOKEN_EMPTY_STR,
+ MSC_MAXSIZE_TOKENAME);
+ } else if (tokenArray[i].tokenState & MSC_STATE_PRESENT)
+ {
+ memcpy(tokenArray[i].tokenId, rgReaderStates[i].rgbAtr,
+ rgReaderStates[i].cbAtr);
+ tokenArray[i].tokenIdLength = rgReaderStates[i].cbAtr;
+
+ rt = TPSearchBundlesForAtr(rgReaderStates[i].rgbAtr,
+ rgReaderStates[i].cbAtr, &tokenInfo);
+ /*
+ * Successfully found
+ */
+ if (rt == 0)
+ {
+ tokenArray[i].tokenType = MSC_TOKEN_TYPE_KNOWN;
+ strncpy(tokenArray[i].tokenName, tokenInfo.tokenName,
+ MSC_MAXSIZE_TOKENAME);
+ } else
+ {
+ tokenArray[i].tokenType = MSC_TOKEN_TYPE_UNKNOWN;
+ strncpy(tokenArray[i].tokenName, MSC_TOKEN_UNKNOWN_STR,
+ MSC_MAXSIZE_TOKENAME);
+ }
+ }
+ }
+ }
+
+ free(rgReaderStates);
+ return pcscToMSC(rv);
+}
+
+MSC_RV MSCCancelEventWait(void)
+{
+
+ MSCLong32 rv;
+
+ rv = SCardCancel(localHContext);
+
+ return pcscToMSC(rv);
+}
+
+/************************ Start of Callbacks ****************************/
+#ifdef USE_THREAD_SAFETY
+void *_MSCEventThread(void *arg)
+{
+
+ MSCLong32 rv;
+ MSCLPEventWaitInfo evlist;
+ MSCLong32 curToken;
+
+ if (arg == NULL)
+ {
+ SYS_ThreadExit(NULL);
+ }
+
+ evlist = (MSCLPEventWaitInfo) arg;
+ blockingContext = MSC_BLOCKSTATUS_BLOCKING;
+
+ while (1)
+ {
+ rv = MSCWaitForTokenEvent(evlist->tokenArray,
+ evlist->arraySize,
+ MSC_NO_TIMEOUT);
+
+ if (rv == MSC_SUCCESS)
+ {
+ (evlist->callBack) (evlist->tokenArray,
+ evlist->arraySize,
+ evlist->appData);
+ } else {
+ break;
+
+ }
+
+ if (blockingContext == MSC_BLOCKSTATUS_CANCELLING)
+ {
+ break;
+ }
+ }
+
+ for (curToken = 0; curToken < evlist->arraySize; curToken++)
+ {
+ if (evlist->tokenArray[curToken].addParams)
+ {
+ free(evlist->tokenArray[curToken].addParams);
+ }
+ }
+
+
+ free(evlist);
+ blockingContext = MSC_BLOCKSTATUS_RESUME;
+ SYS_ThreadExit(&rv);
+
+ return NULL;
+}
+
+MSC_RV MSCCallbackForTokenEvent(MSCLPTokenInfo tokenArray,
+ MSCULong32 arraySize,
+ MSCCallBack callBack,
+ MSCPVoid32 appData)
+{
+ MSCLPEventWaitInfo evlist;
+ MSCULong32 curToken;
+
+ /*
+ * Create the event wait list
+ */
+ evlist = (MSCLPEventWaitInfo) malloc(sizeof(MSCEventWaitInfo));
+
+ if (evlist == NULL)
+ {
+ return MSC_INTERNAL_ERROR;
+ }
+
+ evlist->arraySize = arraySize;
+ evlist->tokenArray = malloc(sizeof(MSCTokenInfo) * arraySize);
+ evlist->appData = appData;
+ evlist->callBack = callBack;
+
+ if (evlist->tokenArray == NULL)
+ {
+ free(evlist);
+ return MSC_INTERNAL_ERROR;
+ }
+
+ mscLockThread();
+ memcpy(evlist->tokenArray, tokenArray,
+ sizeof(MSCTokenInfo) * arraySize);
+
+ /*
+ * Copy the "extra" data
+ */
+ for (curToken = 0; curToken < arraySize; curToken++)
+ {
+ if (tokenArray[curToken].addParams != NULL)
+ {
+ evlist->tokenArray[curToken].addParams =
+ malloc(evlist->tokenArray[curToken].addParamsSize);
+ memcpy((void *) (evlist->tokenArray[curToken].addParams),
+ &tokenArray[curToken],
+ evlist->tokenArray[curToken].addParamsSize);
+
+ }
+ }
+ mscUnLockThread();
+
+ if (SYS_ThreadCreate(&callbackThread, THREAD_ATTR_DEFAULT, _MSCEventThread,
+ (void *) evlist) == 0)
+ {
+ return MSC_INTERNAL_ERROR;
+ }
+
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCCallbackCancelEvent()
+{
+
+ LONG rv;
+
+ /* Release the thread and stop the GetStatusChange */
+ if (blockingContext == MSC_BLOCKSTATUS_BLOCKING)
+ {
+ blockingContext = MSC_BLOCKSTATUS_CANCELLING;
+ rv = MSCCancelEventWait();
+
+ SYS_ThreadJoin(&callbackThread, 0);
+
+ }
+
+ return MSC_SUCCESS;
+}
+
+#endif
+/************************** End of Callbacks *****************************/
+
+MSC_RV MSCBeginTransaction(MSCLPTokenConnection pConnection)
+{
+
+ MSCLong32 rv;
+ MSCLong32 ret;
+
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ while (1)
+ {
+ rv = SCardBeginTransaction(pConnection->hCard);
+ ret = pcscToMSC(rv);
+
+ if (ret == MSC_SUCCESS)
+ break;
+ if (ret == MSC_TOKEN_RESET)
+ {
+ pConnection->tokenInfo.tokenType |=
+ MSC_TOKEN_TYPE_RESET;
+ ret = MSCReEstablishConnection(pConnection);
+ if (ret != MSC_SUCCESS)
+ break;
+ continue;
+ } else if (ret == MSC_TOKEN_REMOVED)
+ {
+ pConnection->tokenInfo.tokenType =
+ MSC_TOKEN_TYPE_REMOVED;
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+MSC_RV MSCEndTransaction(MSCLPTokenConnection pConnection,
+ MSCULong32 endAction)
+{
+
+ MSCLong32 rv;
+ MSCLong32 ret;
+
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ while (1)
+ {
+ rv = SCardEndTransaction(pConnection->hCard, endAction);
+ ret = pcscToMSC(rv);
+
+ if (ret == MSC_SUCCESS)
+ break;
+ if (ret == MSC_TOKEN_RESET)
+ {
+ pConnection->tokenInfo.tokenType |=
+ MSC_TOKEN_TYPE_RESET;
+ ret = MSCReEstablishConnection(pConnection);
+ if (ret != MSC_SUCCESS)
+ break;
+ continue;
+ } else if (ret == MSC_TOKEN_REMOVED)
+ {
+ pConnection->tokenInfo.tokenType =
+ MSC_TOKEN_TYPE_REMOVED;
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+MSC_RV MSCWriteFramework(MSCLPTokenConnection pConnection,
+ MSCLPInitTokenParams pInitParams)
+{
+
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCWriteFramework) (MSCLPTokenConnection,
+ MSCLPInitTokenParams);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfWriteFramework;
+
+ if (vFunction != 0)
+ {
+ libMSCWriteFramework = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCLPInitTokenParams)) vFunction;
+ rv = (*libMSCWriteFramework) (pConnection, pInitParams);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+/*
+ * Real MSC functions
+ */
+
+MSC_RV MSCGetStatus(MSCLPTokenConnection pConnection,
+ MSCLPStatusInfo pStatusInfo)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCGetStatus) (MSCLPTokenConnection, MSCLPStatusInfo);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfGetStatus;
+
+ if (vFunction != 0)
+ {
+ libMSCGetStatus = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCLPStatusInfo)) vFunction;
+ rv = (*libMSCGetStatus) (pConnection, pStatusInfo);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCGetCapabilities(MSCLPTokenConnection pConnection, MSCULong32 Tag,
+ MSCPUChar8 Value, MSCPULong32 Length)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCGetCapabilities) (MSCLPTokenConnection, MSCULong32,
+ MSCPUChar8, MSCPULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfGetCapabilities;
+
+ if (vFunction != 0)
+ {
+ libMSCGetCapabilities =
+ (MSCLong32(*)(MSCLPTokenConnection, MSCULong32, MSCPUChar8,
+ MSCPULong32)) vFunction;
+ rv = (*libMSCGetCapabilities) (pConnection, Tag, Value, Length);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCExtendedFeature(MSCLPTokenConnection pConnection,
+ MSCULong32 extFeature, MSCPUChar8 outData,
+ MSCULong32 outLength, MSCPUChar8 inData, MSCPULong32 inLength)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCExtendedFeature) (MSCLPTokenConnection, MSCULong32,
+ MSCPUChar8, MSCULong32, MSCPUChar8, MSCPULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfExtendedFeature;
+
+ if (vFunction != 0)
+ {
+ libMSCExtendedFeature =
+ (MSCLong32(*)(MSCLPTokenConnection, MSCULong32, MSCPUChar8,
+ MSCULong32, MSCPUChar8, MSCPULong32)) vFunction;
+ rv = (*libMSCExtendedFeature) (pConnection, extFeature, outData,
+ outLength, inData, inLength);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCGenerateKeys(MSCLPTokenConnection pConnection,
+ MSCUChar8 prvKeyNum, MSCUChar8 pubKeyNum, MSCLPGenKeyParams pParams)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCGenerateKeys) (MSCLPTokenConnection, MSCUChar8,
+ MSCUChar8, MSCLPGenKeyParams);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfGenerateKeys;
+
+ if (vFunction != 0)
+ {
+ libMSCGenerateKeys = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCUChar8, MSCUChar8,
+ MSCLPGenKeyParams))
+ vFunction;
+ rv = (*libMSCGenerateKeys) (pConnection, prvKeyNum, pubKeyNum,
+ pParams);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCImportKey(MSCLPTokenConnection pConnection, MSCUChar8 keyNum,
+ MSCLPKeyACL pKeyACL, MSCPUChar8 pKeyBlob,MSCULong32 keyBlobSize,
+ MSCLPKeyPolicy keyPolicy, MSCPVoid32 pAddParams,
+ MSCUChar8 addParamsSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCImportKey) (MSCLPTokenConnection, MSCUChar8,
+ MSCLPKeyACL, MSCPUChar8,
+ MSCULong32, MSCLPKeyPolicy, MSCPVoid32,
+ MSCUChar8);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfImportKey;
+
+ if (vFunction != 0)
+ {
+ libMSCImportKey = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCUChar8,
+ MSCLPKeyACL, MSCPUChar8,
+ MSCULong32, MSCLPKeyPolicy,
+ MSCPVoid32, MSCUChar8))
+ vFunction;
+
+ rv = (*libMSCImportKey) (pConnection, keyNum,
+ pKeyACL, pKeyBlob, keyBlobSize,
+ keyPolicy, pAddParams, addParamsSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCExportKey(MSCLPTokenConnection pConnection, MSCUChar8 keyNum,
+ MSCPUChar8 pKeyBlob, MSCPULong32 keyBlobSize,
+ MSCPVoid32 pAddParams, MSCUChar8 addParamsSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCExportKey) (MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCPULong32, MSCPVoid32, MSCUChar8);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfExportKey;
+
+ if (vFunction != 0)
+ {
+ libMSCExportKey = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCUChar8, MSCPUChar8,
+ MSCPULong32, MSCPVoid32,
+ MSCUChar8)) vFunction;
+
+ rv = (*libMSCExportKey) (pConnection, keyNum, pKeyBlob,
+ keyBlobSize, pAddParams, addParamsSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCComputeCrypt(MSCLPTokenConnection pConnection,
+ MSCLPCryptInit cryptInit, MSCPUChar8 pInputData,
+ MSCULong32 inputDataSize, MSCPUChar8 pOutputData,
+ MSCPULong32 outputDataSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCComputeCrypt) (MSCLPTokenConnection, MSCLPCryptInit,
+ MSCPUChar8, MSCULong32, MSCPUChar8,
+ MSCPULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfComputeCrypt;
+
+ if (vFunction != 0)
+ {
+ libMSCComputeCrypt =
+ (MSCLong32(*)(MSCLPTokenConnection, MSCLPCryptInit,
+ MSCPUChar8, MSCULong32, MSCPUChar8,
+ MSCPULong32)) vFunction;
+ rv = (*libMSCComputeCrypt) (pConnection, cryptInit, pInputData,
+ inputDataSize, pOutputData,
+ outputDataSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCExtAuthenticate(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNum, MSCUChar8 cipherMode,
+ MSCUChar8 cipherDirection,
+ MSCPUChar8 pData, MSCULong32 dataSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCExtAuthenticate) (MSCLPTokenConnection, MSCUChar8,
+ MSCUChar8, MSCUChar8, MSCPUChar8,
+ MSCULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfExtAuthenticate;
+
+ if (vFunction != 0)
+ {
+ libMSCExtAuthenticate =
+ (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCUChar8, MSCUChar8, MSCPUChar8,
+ MSCULong32)) vFunction;
+ rv = (*libMSCExtAuthenticate) (pConnection, keyNum, cipherMode,
+ cipherDirection, pData, dataSize);
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCListKeys(MSCLPTokenConnection pConnection, MSCUChar8 seqOption,
+ MSCLPKeyInfo pKeyInfo)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCListKeys) (MSCLPTokenConnection, MSCUChar8,
+ MSCLPKeyInfo);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfListKeys;
+
+ if (vFunction != 0)
+ {
+ libMSCListKeys = (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCLPKeyInfo)) vFunction;
+ rv = (*libMSCListKeys) (pConnection, seqOption, pKeyInfo);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCCreatePIN(MSCLPTokenConnection pConnection, MSCUChar8 pinNum,
+ MSCUChar8 pinAttempts, MSCPUChar8 pPinCode,
+ MSCULong32 pinCodeSize, MSCPUChar8 pUnblockCode,
+ MSCUChar8 unblockCodeSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCCreatePIN) (MSCLPTokenConnection, MSCUChar8,
+ MSCUChar8, MSCPUChar8, MSCULong32, MSCPUChar8, MSCUChar8);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfCreatePIN;
+
+ if (vFunction != 0)
+ {
+ libMSCCreatePIN = (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCUChar8, MSCPUChar8,
+ MSCULong32, MSCPUChar8, MSCUChar8)) vFunction;
+ rv = (*libMSCCreatePIN) (pConnection, pinNum, pinAttempts,
+ pPinCode, pinCodeSize, pUnblockCode, unblockCodeSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCVerifyPIN(MSCLPTokenConnection pConnection, MSCUChar8 pinNum,
+ MSCPUChar8 pPinCode, MSCULong32 pinCodeSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCVerifyPIN) (MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfVerifyPIN;
+
+ if (vFunction != 0)
+ {
+ libMSCVerifyPIN = (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCULong32)) vFunction;
+ rv = (*libMSCVerifyPIN) (pConnection, pinNum, pPinCode,
+ pinCodeSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCChangePIN(MSCLPTokenConnection pConnection, MSCUChar8 pinNum,
+ MSCPUChar8 pOldPinCode, MSCUChar8 oldPinCodeSize,
+ MSCPUChar8 pNewPinCode, MSCUChar8 newPinCodeSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCChangePIN) (MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCUChar8, MSCPUChar8, MSCUChar8);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfChangePIN;
+
+ if (vFunction != 0)
+ {
+ libMSCChangePIN = (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCUChar8, MSCPUChar8, MSCUChar8)) vFunction;
+ rv = (*libMSCChangePIN) (pConnection, pinNum, pOldPinCode,
+ oldPinCodeSize, pNewPinCode, newPinCodeSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCUnblockPIN(MSCLPTokenConnection pConnection, MSCUChar8 pinNum,
+ MSCPUChar8 pUnblockCode, MSCULong32 unblockCodeSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCUnblockPIN) (MSCLPTokenConnection, MSCUChar8,
+ MSCPUChar8, MSCULong32);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfUnblockPIN;
+
+ if (vFunction != 0)
+ {
+ libMSCUnblockPIN = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCUChar8, MSCPUChar8, MSCULong32)) vFunction;
+ rv = (*libMSCUnblockPIN) (pConnection, pinNum, pUnblockCode,
+ unblockCodeSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCListPINs(MSCLPTokenConnection pConnection,
+ MSCPUShort16 pPinBitMask)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCListPINs) (MSCLPTokenConnection, MSCPUShort16);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfListPINs;
+
+ if (vFunction != 0)
+ {
+ libMSCListPINs = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCPUShort16)) vFunction;
+ rv = (*libMSCListPINs) (pConnection, pPinBitMask);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCCreateObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCULong32 objectSize, MSCLPObjectACL pObjectACL)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCCreateObject) (MSCLPTokenConnection, MSCString,
+ MSCULong32, MSCLPObjectACL);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfCreateObject;
+
+ if (vFunction != 0)
+ {
+ libMSCCreateObject = (MSCLong32(*)(MSCLPTokenConnection, MSCString,
+ MSCULong32, MSCLPObjectACL)) vFunction;
+ rv = (*libMSCCreateObject) (pConnection, objectID, objectSize,
+ pObjectACL);
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCDeleteObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCUChar8 zeroFlag)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCDeleteObject) (MSCLPTokenConnection, MSCString,
+ MSCUChar8);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfDeleteObject;
+
+ if (vFunction != 0)
+ {
+ libMSCDeleteObject = (MSCLong32(*)(MSCLPTokenConnection, MSCString,
+ MSCUChar8)) vFunction;
+ rv = (*libMSCDeleteObject) (pConnection, objectID, zeroFlag);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCWriteObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCULong32 offSet,
+ MSCPUChar8 pInputData, MSCULong32 dataSize,
+ LPRWEventCallback rwCallback, MSCPVoid32 addParams)
+{
+ MSC_RV rv = MSC_UNSPECIFIED_ERROR;
+ MSCULong32 objectSize;
+ int totalSteps, stepInterval;
+ MSC_RV(*callBackFunction) (void *, int);
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCWriteObject) (MSCLPTokenConnection, MSCString,
+ MSCULong32, MSCPUChar8, MSCUChar8);
+ int i;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfWriteObject;
+ callBackFunction = (MSC_RV(*)(void *, int)) rwCallback;
+ objectSize = dataSize;
+
+ if (vFunction == 0)
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ libMSCWriteObject = (MSCLong32(*)(MSCLPTokenConnection, MSCString,
+ MSCULong32, MSCPUChar8, MSCUChar8))
+ vFunction;
+
+ /*
+ * Figure out the number of steps total and present this in a percent
+ * step basis
+ */
+
+ totalSteps = objectSize / MSC_SIZEOF_KEYPACKET + 1;
+ stepInterval = MSC_PERCENT_STEPSIZE / totalSteps;
+
+ for (i = 0; i < objectSize / MSC_SIZEOF_KEYPACKET; i++)
+ {
+ rv = (*libMSCWriteObject) (pConnection, objectID,
+ i * MSC_SIZEOF_KEYPACKET + offSet,
+ &pInputData[i * MSC_SIZEOF_KEYPACKET],
+ MSC_SIZEOF_KEYPACKET);
+ if (rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rwCallback)
+ {
+ if ((*callBackFunction) (addParams,
+ stepInterval * i) == MSC_CANCELLED)
+ {
+ return MSC_CANCELLED;
+ }
+ }
+ }
+
+ if (objectSize % MSC_SIZEOF_KEYPACKET)
+ {
+
+ rv = (*libMSCWriteObject) (pConnection, objectID,
+ i * MSC_SIZEOF_KEYPACKET + offSet,
+ &pInputData[i * MSC_SIZEOF_KEYPACKET],
+ objectSize % MSC_SIZEOF_KEYPACKET);
+
+ if (rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+ }
+
+ if (rwCallback)
+ {
+ (*callBackFunction) (addParams, MSC_PERCENT_STEPSIZE);
+ }
+
+ return rv;
+}
+
+MSC_RV MSCReadObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCULong32 offSet,
+ MSCPUChar8 pOutputData, MSCULong32 dataSize,
+ LPRWEventCallback rwCallback,
+ MSCPVoid32 addParams)
+{
+
+ MSC_RV rv = MSC_UNSPECIFIED_ERROR;
+ MSCULong32 objectSize;
+ int totalSteps, stepInterval;
+ MSC_RV(*callBackFunction) (void *, int);
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCReadObject) (MSCLPTokenConnection, MSCString,
+ MSCULong32, MSCPUChar8, MSCUChar8);
+ int i;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfReadObject;
+ callBackFunction = (MSC_RV(*)(void *, int)) rwCallback;
+ objectSize = dataSize;
+
+ if (vFunction == 0)
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ libMSCReadObject = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCString, MSCULong32,
+ MSCPUChar8, MSCUChar8))
+ vFunction;
+
+ /*
+ * Figure out the number of steps total and present this in a percent
+ * step basis
+ */
+
+ totalSteps = objectSize / MSC_SIZEOF_KEYPACKET + 1;
+ stepInterval = MSC_PERCENT_STEPSIZE / totalSteps;
+
+ for (i = 0; i < objectSize / MSC_SIZEOF_KEYPACKET; i++)
+ {
+ rv = (*libMSCReadObject) (pConnection, objectID,
+ i * MSC_SIZEOF_KEYPACKET + offSet,
+ &pOutputData[i * MSC_SIZEOF_KEYPACKET],
+ MSC_SIZEOF_KEYPACKET);
+
+ if (rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rwCallback)
+ {
+ if ((*callBackFunction) (addParams,
+ stepInterval * i) == MSC_CANCELLED)
+ {
+ return MSC_CANCELLED;
+ }
+ }
+ }
+
+ if (objectSize % MSC_SIZEOF_KEYPACKET)
+ {
+ rv = (*libMSCReadObject) (pConnection, objectID,
+ i * MSC_SIZEOF_KEYPACKET + offSet,
+ &pOutputData[i * MSC_SIZEOF_KEYPACKET],
+ objectSize % MSC_SIZEOF_KEYPACKET);
+
+ if (rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+ }
+
+ if (rwCallback)
+ {
+ (*callBackFunction) (addParams, MSC_PERCENT_STEPSIZE);
+ }
+
+ return rv;
+}
+
+MSC_RV MSCListObjects(MSCLPTokenConnection pConnection,
+ MSCUChar8 seqOption, MSCLPObjectInfo pObjectInfo)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCListObjects) (MSCLPTokenConnection, MSCUChar8,
+ MSCLPObjectInfo);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfListObjects;
+
+ if (vFunction != 0)
+ {
+ libMSCListObjects = (MSCLong32(*)(MSCLPTokenConnection, MSCUChar8,
+ MSCLPObjectInfo)) vFunction;
+ rv = (*libMSCListObjects) (pConnection, seqOption, pObjectInfo);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCLogoutAll(MSCLPTokenConnection pConnection)
+{
+
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCLogoutAll) (MSCLPTokenConnection);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfLogoutAll;
+
+ if (vFunction != 0)
+ {
+ libMSCLogoutAll = (MSCLong32(*)(MSCLPTokenConnection)) vFunction;
+ rv = (*libMSCLogoutAll) (pConnection);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCGetChallenge(MSCLPTokenConnection pConnection, MSCPUChar8 pSeed,
+ MSCUShort16 seedSize, MSCPUChar8 pRandomData,
+ MSCUShort16 randomDataSize)
+{
+ MSCLong32 rv;
+ MSCPVoid32 vFunction;
+ MSCLong32(*libMSCGetChallenge) (MSCLPTokenConnection, MSCPUChar8,
+ MSCUShort16, MSCPUChar8, MSCUShort16);
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ vFunction = pConnection->libPointers.pvfGetChallenge;
+
+ if (vFunction != 0)
+ {
+ libMSCGetChallenge = (MSCLong32(*)(MSCLPTokenConnection,
+ MSCPUChar8, MSCUShort16,
+ MSCPUChar8, MSCUShort16)) vFunction;
+ rv = (*libMSCGetChallenge) (pConnection, pSeed, seedSize,
+ pRandomData, randomDataSize);
+
+ } else
+ {
+ return MSC_UNSUPPORTED_FEATURE;
+ }
+
+ return rv;
+}
+
+MSC_RV MSCGetKeyAttributes(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNumber, MSCLPKeyInfo pKeyInfo)
+{
+
+ MSC_RV rv;
+ MSCKeyInfo keyInfo;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ rv = MSCListKeys(pConnection, MSC_SEQUENCE_RESET, &keyInfo);
+
+ if (rv != MSC_SEQUENCE_END && rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rv == MSC_SEQUENCE_END)
+ {
+ return MSC_INVALID_PARAMETER;
+ }
+
+ if (keyNumber == keyInfo.keyNum)
+ {
+ pKeyInfo->keyNum = keyInfo.keyNum;
+ pKeyInfo->keyType = keyInfo.keyType;
+ pKeyInfo->keySize = keyInfo.keySize;
+
+ pKeyInfo->keyPolicy.cipherMode = keyInfo.keyPolicy.cipherMode;
+ pKeyInfo->keyPolicy.cipherDirection =
+ keyInfo.keyPolicy.cipherDirection;
+
+ pKeyInfo->keyACL.readPermission =
+ keyInfo.keyACL.readPermission;
+ pKeyInfo->keyACL.writePermission =
+ keyInfo.keyACL.writePermission;
+ pKeyInfo->keyACL.usePermission =
+ keyInfo.keyACL.usePermission;
+
+ return MSC_SUCCESS;
+ }
+
+ do
+ {
+ rv = MSCListKeys(pConnection, MSC_SEQUENCE_NEXT, &keyInfo);
+ if (keyNumber == keyInfo.keyNum)
+ break;
+ }
+ while (rv == MSC_SUCCESS);
+
+ if (rv != MSC_SEQUENCE_END && rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rv == MSC_SEQUENCE_END)
+ {
+ return MSC_INVALID_PARAMETER;
+ }
+
+ pKeyInfo->keyNum = keyInfo.keyNum;
+ pKeyInfo->keyType = keyInfo.keyType;
+ pKeyInfo->keySize = keyInfo.keySize;
+
+ pKeyInfo->keyPolicy.cipherMode = keyInfo.keyPolicy.cipherMode;
+ pKeyInfo->keyPolicy.cipherDirection =
+ keyInfo.keyPolicy.cipherDirection;
+
+ pKeyInfo->keyACL.readPermission = keyInfo.keyACL.readPermission;
+ pKeyInfo->keyACL.writePermission = keyInfo.keyACL.writePermission;
+ pKeyInfo->keyACL.usePermission = keyInfo.keyACL.usePermission;
+
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCGetObjectAttributes(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCLPObjectInfo pObjectInfo)
+{
+
+ MSC_RV rv;
+ MSCObjectInfo objInfo;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ rv = MSCListObjects(pConnection, MSC_SEQUENCE_RESET, &objInfo);
+
+ if (rv != MSC_SEQUENCE_END && rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rv == MSC_SEQUENCE_END)
+ {
+ return MSC_OBJECT_NOT_FOUND;
+ }
+
+ if (strncmp(objectID, objInfo.objectID, MSC_MAXSIZE_OBJID) == 0)
+ {
+ pObjectInfo->objectSize = objInfo.objectSize;
+ pObjectInfo->objectACL.readPermission =
+ objInfo.objectACL.readPermission;
+ pObjectInfo->objectACL.writePermission =
+ objInfo.objectACL.writePermission;
+ pObjectInfo->objectACL.deletePermission =
+ objInfo.objectACL.deletePermission;
+ strncpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
+ return MSC_SUCCESS;
+ }
+
+ do
+ {
+ rv = MSCListObjects(pConnection, MSC_SEQUENCE_NEXT, &objInfo);
+ if (strncmp(objectID, objInfo.objectID, MSC_MAXSIZE_OBJID) == 0)
+ break;
+ }
+ while (rv == MSC_SUCCESS);
+
+ if (rv != MSC_SEQUENCE_END && rv != MSC_SUCCESS)
+ {
+ return rv;
+ }
+
+ if (rv == MSC_SEQUENCE_END)
+ {
+ return MSC_OBJECT_NOT_FOUND;
+ }
+
+ pObjectInfo->objectSize = objInfo.objectSize;
+ pObjectInfo->objectACL.readPermission =
+ objInfo.objectACL.readPermission;
+ pObjectInfo->objectACL.writePermission =
+ objInfo.objectACL.writePermission;
+ pObjectInfo->objectACL.deletePermission =
+ objInfo.objectACL.deletePermission;
+ strncpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
+
+ return MSC_SUCCESS;
+}
+
+MSC_RV MSCReadAllocateObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCPUChar8 * pOutputData,
+ MSCPULong32 dataSize,
+ LPRWEventCallback rwCallback,
+ MSCPVoid32 addParams)
+{
+ MSC_RV rv;
+ MSCObjectInfo objInfo;
+ MSCULong32 objectSize;
+ MSCPUChar8 data = NULL;
+
+ if (pConnection == NULL)
+ return MSC_INVALID_PARAMETER;
+ if (localHContext == 0)
+ return MSC_INTERNAL_ERROR;
+
+ if (pOutputData == 0)
+ {
+ return MSC_INVALID_PARAMETER;
+ }
+
+ *dataSize = 0;
+ *pOutputData = 0;
+
+ rv = MSCGetObjectAttributes(pConnection, objectID, &objInfo);
+ if (rv == MSC_SUCCESS)
+ {
+ objectSize = objInfo.objectSize;
+ data = (MSCPUChar8) malloc(sizeof(MSCUChar8) * objectSize);
+ if(data)
+ {
+ rv = MSCReadObject(pConnection, objectID, 0, data,
+ objectSize, rwCallback, addParams);
+
+ if (rv == MSC_SUCCESS)
+ {
+ *dataSize = objectSize;
+ *pOutputData = data;
+ }
+ else
+ {
+ rv = MSC_INTERNAL_ERROR;
+ free(data);
+ }
+ }
+ }
+
+ return rv;
+}
+
+
+MSC_RV pcscToMSC(MSCLong32 pcscCode)
+{
+
+ switch (pcscCode)
+ {
+ case SCARD_S_SUCCESS:
+ return MSC_SUCCESS;
+ case SCARD_E_INVALID_HANDLE:
+ return MSC_INVALID_HANDLE;
+ case SCARD_E_SHARING_VIOLATION:
+ return MSC_SHARING_VIOLATION;
+ case SCARD_W_REMOVED_CARD:
+ return MSC_TOKEN_REMOVED;
+ case SCARD_E_NO_SMARTCARD:
+ return MSC_TOKEN_REMOVED;
+ case SCARD_W_RESET_CARD:
+ return MSC_TOKEN_RESET;
+ case SCARD_W_INSERTED_CARD:
+ return MSC_TOKEN_INSERTED;
+ case SCARD_E_NO_SERVICE:
+ return MSC_SERVICE_UNRESPONSIVE;
+ case SCARD_E_UNKNOWN_CARD:
+ case SCARD_W_UNSUPPORTED_CARD:
+ case SCARD_E_CARD_UNSUPPORTED:
+ return MSC_UNRECOGNIZED_TOKEN;
+ case SCARD_E_INVALID_PARAMETER:
+ case SCARD_E_INVALID_VALUE:
+ case SCARD_E_UNKNOWN_READER:
+ case SCARD_E_PROTO_MISMATCH:
+ case SCARD_E_READER_UNAVAILABLE:
+ return MSC_INVALID_PARAMETER;
+ case SCARD_E_CANCELLED:
+ return MSC_CANCELLED;
+ case SCARD_E_TIMEOUT:
+ return MSC_TIMEOUT_OCCURRED;
+
+ default:
+ return MSC_INTERNAL_ERROR;
+ }
+}
+
+char *msc_error(unsigned long int errorCode) //MSC_RV
+{
+
+ static char message[500];
+
+ switch (errorCode)
+ {
+ case MSC_SUCCESS:
+ strncpy(message, "Successful", sizeof(message));
+ break;
+ case MSC_NO_MEMORY_LEFT:
+ strncpy(message, "No more memory", sizeof(message));
+ break;
+ case MSC_AUTH_FAILED:
+ strncpy(message, "Authentication failed", sizeof(message));
+ break;
+ case MSC_OPERATION_NOT_ALLOWED:
+ strncpy(message, "Operation not allowed", sizeof(message));
+ break;
+ case MSC_INCONSISTENT_STATUS:
+ strncpy(message, "Inconsistent status", sizeof(message));
+ break;
+ case MSC_UNSUPPORTED_FEATURE:
+ strncpy(message, "Feature unsupported", sizeof(message));
+ break;
+ case MSC_UNAUTHORIZED:
+ strncpy(message, "Unauthorized usage", sizeof(message));
+ break;
+ case MSC_OBJECT_NOT_FOUND:
+ strncpy(message, "Object not found", sizeof(message));
+ break;
+ case MSC_OBJECT_EXISTS:
+ strncpy(message, "Object already exists", sizeof(message));
+ break;
+ case MSC_INCORRECT_ALG:
+ strncpy(message, "Incorrect algorithm", sizeof(message));
+ break;
+ case MSC_SIGNATURE_INVALID:
+ strncpy(message, "Invalid signature", sizeof(message));
+ break;
+ case MSC_IDENTITY_BLOCKED:
+ strncpy(message, "Identity is blocked", sizeof(message));
+ break;
+ case MSC_UNSPECIFIED_ERROR:
+ strncpy(message, "Unspecified error", sizeof(message));
+ break;
+ case MSC_TRANSPORT_ERROR:
+ strncpy(message, "Transport error", sizeof(message));
+ break;
+ case MSC_INVALID_PARAMETER:
+ strncpy(message, "Invalid parameter", sizeof(message));
+ break;
+ case MSC_SEQUENCE_END:
+ strncpy(message, "End of sequence", sizeof(message));
+ break;
+ case MSC_INTERNAL_ERROR:
+ strncpy(message, "Internal Error", sizeof(message));
+ break;
+ case MSC_CANCELLED:
+ strncpy(message, "Operation Cancelled", sizeof(message));
+ break;
+ case MSC_INSUFFICIENT_BUFFER:
+ strncpy(message, "Buffer is too small", sizeof(message));
+ break;
+ case MSC_UNRECOGNIZED_TOKEN:
+ strncpy(message, "Token is unsupported", sizeof(message));
+ break;
+ case MSC_SERVICE_UNRESPONSIVE:
+ strncpy(message, "Service is not running", sizeof(message));
+ break;
+ case MSC_TIMEOUT_OCCURRED:
+ strncpy(message, "Timeout has occurred", sizeof(message));
+ break;
+ case MSC_TOKEN_REMOVED:
+ strncpy(message, "Token was removed", sizeof(message));
+ break;
+ case MSC_TOKEN_RESET:
+ strncpy(message, "Token was reset", sizeof(message));
+ break;
+ case MSC_TOKEN_INSERTED:
+ strncpy(message, "Token was inserted", sizeof(message));
+ break;
+ case MSC_TOKEN_UNRESPONSIVE:
+ strncpy(message, "Token is unresponsive", sizeof(message));
+ break;
+ case MSC_INVALID_HANDLE:
+ strncpy(message, "Handle is invalid", sizeof(message));
+ break;
+ case MSC_SHARING_VIOLATION:
+ strncpy(message, "Sharing violation", sizeof(message));
+ break;
+
+ default:
+ sprintf(message, "Unknown SW: %04lu", errorCode);
+ break;
+ }
+
+ return message;
+}
+
+MSC_RV MSCReEstablishConnection(MSCLPTokenConnection pConnection)
+{
+
+ MSC_RV rv;
+ MSCPVoid32 vInitFunction, vFinFunction, vIdFunction;
+ MSCULong32 dwActiveProtocol;
+ MSCLong32(*libPL_MSCInitializePlugin) (MSCLPTokenConnection);
+ MSCLong32(*libPL_MSCFinalizePlugin) (MSCLPTokenConnection);
+ MSCLong32 (*libPL_MSCIdentifyToken)(MSCLPTokenConnection);
+
+ vInitFunction = 0;
+ vFinFunction = 0;
+ vIdFunction = 0;
+
+ /*
+ * Select the AID or initialization routine for the card
+ */
+ vInitFunction = pConnection->libPointers.pvfInitializePlugin;
+ vFinFunction = pConnection->libPointers.pvfFinalizePlugin;
+ vIdFunction = pConnection->libPointers.pvfIdentifyToken;
+
+ if (vInitFunction == 0)
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "InitializePlugin function missing");
+ return MSC_INTERNAL_ERROR;
+ }
+
+ if (vFinFunction == 0)
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "FinalizePlugin function missing");
+ return MSC_INTERNAL_ERROR;
+ }
+
+ if ( vIdFunction == 0 )
+ {
+ DebugLogB("Error: Card service failure: %s\n",
+ "IdentifyToken function missing");
+ return MSC_INTERNAL_ERROR;
+ }
+
+ libPL_MSCInitializePlugin = (MSCLong32(*)(MSCLPTokenConnection))
+ vInitFunction;
+
+ libPL_MSCFinalizePlugin = (MSCLong32(*)(MSCLPTokenConnection))
+ vFinFunction;
+
+ libPL_MSCIdentifyToken = (MSCLong32 (*)(MSCLPTokenConnection))
+ vIdFunction;
+
+ rv = SCardReconnect(pConnection->hCard, pConnection->shareMode,
+ SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+ SCARD_LEAVE_CARD, &dwActiveProtocol);
+
+ if (rv != SCARD_S_SUCCESS)
+ return pcscToMSC(rv);
+
+ /*
+ * Stop the plugin and start it up again
+ */
+ rv = (*libPL_MSCFinalizePlugin) (pConnection);
+
+ /*
+ * Use the default AID given by the Info.plist
+ */
+ rv = (*libPL_MSCInitializePlugin) (pConnection);
+
+ /*
+ * Use the default AID given by the Info.plist
+ */
+ rv = (*libPL_MSCIdentifyToken)(pConnection);
+
+ if (rv != MSC_SUCCESS)
+ return rv;
+
+ return MSC_SUCCESS;
+}
+
+MSCUChar8 MSCIsTokenReset(MSCLPTokenConnection pConnection)
+{
+ MSCULong32 rv;
+ char slotName[MAX_READERNAME];
+ MSCULong32 slotNameSize, slotState, slotProtocol;
+ MSCUChar8 tokenId[MAX_ATR_SIZE];
+ MSCULong32 tokenIdLength;
+
+ rv = SCardStatus(pConnection->hCard, slotName,
+ &slotNameSize, &slotState, &slotProtocol,
+ tokenId, &tokenIdLength);
+
+ if (rv == SCARD_W_RESET_CARD)
+ {
+ return 1;
+ }
+
+ if (pConnection->tokenInfo.tokenType & MSC_TOKEN_TYPE_RESET)
+ {
+ return 1;
+ } else
+ {
+ return 0;
+ }
+}
+
+MSCUChar8 MSCClearReset(MSCLPTokenConnection pConnection)
+{
+ pConnection->tokenInfo.tokenType &= ~MSC_TOKEN_TYPE_RESET;
+ return 1;
+}
+
+MSCUChar8 MSCIsTokenMoved(MSCLPTokenConnection pConnection)
+{
+ MSCULong32 rv;
+ char slotName[MAX_READERNAME];
+ MSCULong32 slotNameSize, slotState, slotProtocol;
+ MSCUChar8 tokenId[MAX_ATR_SIZE];
+ MSCULong32 tokenIdLength;
+
+
+ rv = SCardStatus(pConnection->hCard, slotName,
+ &slotNameSize, &slotState, &slotProtocol,
+ tokenId, &tokenIdLength);
+
+ if (rv == SCARD_W_REMOVED_CARD)
+ {
+ return 1;
+ } else if (rv == SCARD_W_INSERTED_CARD)
+ {
+ return 1;
+ } else if (slotState & SCARD_ABSENT)
+ {
+ return 1;
+ }
+
+
+ if (pConnection->tokenInfo.tokenType & MSC_TOKEN_TYPE_REMOVED)
+ {
+ return 1;
+ } else
+ {
+ return 0;
+ }
+}
+
+MSCUChar8 MSCIsTokenChanged(MSCLPTokenConnection pConnection)
+{
+ if (MSCIsTokenMoved(pConnection))
+ {
+ return 1;
+ } else if (MSCIsTokenReset(pConnection))
+ {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+MSCUChar8 MSCIsTokenKnown(MSCLPTokenConnection pConnection)
+{
+ if (pConnection->tokenInfo.tokenType & MSC_TOKEN_TYPE_KNOWN)
+ {
+ return 1;
+ } else
+ {
+ return 0;
+ }
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/musclecard.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1050 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : musclecard.h
+ Package: MuscleCard Framework
+ Author : David Corcoran
+ Date : 11/28/01
+ License: Copyright (C) 2001 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This abstracts the MUSCLE Card Edge Inteface
+
+ You may not remove this header from this file
+ without prior permission from the author.
+
+********************************************************************/
+
+#ifndef __musclecard_h__
+#define __musclecard_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef WIN32
+#include "PCSC.h"
+#endif
+
+#ifndef __APPLE__
+#include <mscdefines.h>
+#else
+#include <PCSC/mscdefines.h>
+#endif
+
+ /****************
+ * Return codes *
+ ****************/
+
+ /** success */
+#define MSC_SUCCESS 0x9000
+
+ /** There have been memory problems on the card */
+#define MSC_NO_MEMORY_LEFT 0x9C01
+ /** Entered PIN is not correct */
+#define MSC_AUTH_FAILED 0x9C02
+ /** Required operation is not allowed in actual circumstances */
+#define MSC_OPERATION_NOT_ALLOWED 0x9C03
+ /** Required operation is inconsistent with memory contents */
+#define MSC_INCONSISTENT_STATUS 0x9C04
+ /** Required feature is not (yet) supported */
+#define MSC_UNSUPPORTED_FEATURE 0x9C05
+ /** Required operation was not authorized because of a lack of privileges */
+#define MSC_UNAUTHORIZED 0x9C06
+ /** Required object is missing */
+#define MSC_OBJECT_NOT_FOUND 0x9C07
+ /** New object ID already in use */
+#define MSC_OBJECT_EXISTS 0x9C08
+ /** Algorithm specified is not correct */
+#define MSC_INCORRECT_ALG 0x9C09
+
+ /** Verify operation detected an invalid signature */
+#define MSC_SIGNATURE_INVALID 0x9C0B
+ /** Operation has been blocked for security reason */
+#define MSC_IDENTITY_BLOCKED 0x9C0C
+ /** Unspecified error */
+#define MSC_UNSPECIFIED_ERROR 0x9C0D
+ /** PCSC and driver transport errors */
+#define MSC_TRANSPORT_ERROR 0x9C0E
+ /** Invalid parameter given */
+#define MSC_INVALID_PARAMETER 0x9C0F
+ /** Incorrect P1 parameter */
+#define MSC_INCORRECT_P1 0x9C10
+ /** Incorrect P2 parameter */
+#define MSC_INCORRECT_P2 0x9C11
+ /** End of sequence */
+#define MSC_SEQUENCE_END 0x9C12
+ /** For debugging purposes */
+#define MSC_INTERNAL_ERROR 0x9CFF
+
+ /*******************************************************/
+ /*
+ * These returns are beyond the protocol specification
+ */
+ /*
+ * and only exist here to provide return codes for the
+ */
+ /*
+ * additional functions provided by the MuscleCard API
+ */
+ /*
+ * beyond the protocol specification.
+ */
+ /*******************************************************/
+
+ /** A blocking event has been cancelled */
+#define MSC_CANCELLED 0x9C50
+ /*
+ * The buffer provided is too short
+ */
+#define MSC_INSUFFICIENT_BUFFER 0x9C51
+ /*
+ * The selected token is not recognized
+ */
+#define MSC_UNRECOGNIZED_TOKEN 0x9C52
+ /*
+ * The PC/SC services is not available
+ */
+#define MSC_SERVICE_UNRESPONSIVE 0x9C53
+ /*
+ * The action has timed out
+ */
+#define MSC_TIMEOUT_OCCURRED 0x9C54
+ /*
+ * The token has been removed
+ */
+#define MSC_TOKEN_REMOVED 0x9C55
+ /*
+ * The token has been reset
+ */
+#define MSC_TOKEN_RESET 0x9C56
+ /*
+ * The token has been inserted
+ */
+#define MSC_TOKEN_INSERTED 0x9C57
+ /*
+ * The token is unresponsive
+ */
+#define MSC_TOKEN_UNRESPONSIVE 0x9C58
+ /*
+ * The handle is invalid
+ */
+#define MSC_INVALID_HANDLE 0x9C59
+ /*
+ * Invalid sharing
+ */
+#define MSC_SHARING_VIOLATION 0x9C60
+
+
+#define MSC_BLOCKSTATUS_RESUME 0x0000
+#define MSC_BLOCKSTATUS_BLOCKING 0x0001
+#define MSC_BLOCKSTATUS_CANCELLING 0x0002
+
+ /*
+ * Some boundary defines
+ */
+#define MSC_MAX_KEYS 16
+#define MSC_MAX_PINS 8
+#define MSC_SIZEOF_KEYPACKET 200
+#define MSC_MAXSIZEOF_APDU_DATALEN 255
+#define MSC_PERCENT_STEPSIZE 1000
+#define MSC_SINGLE_READ_PACKET 255
+#define MSC_MAXSIZE_TOKENARRAY 255
+
+ /*
+ * KeyPair Generation algorithms
+ */
+#define MSC_GEN_ALG_RSA 0x00
+#define MSC_GEN_ALG_RSA_CRT 0x01
+#define MSC_GEN_ALG_DSA 0x02
+#define MSC_GEN_ALG_DES 0x03
+#define MSC_GEN_ALG_3DES 0x04
+#define MSC_GEN_ALG_3DES3 0x05
+
+ /*
+ * Blob encodings in KeyBlob structure
+ */
+#define MSC_BLOB_ENC_PLAIN 0x00
+#define MSC_BLOB_ENC_CRYPT 0x01
+
+ /*
+ * Key Type in Key Blobs
+ */
+#define MSC_KEY_RSA_PUBLIC 0x01
+#define MSC_KEY_RSA_PRIVATE 0x02
+#define MSC_KEY_RSA_PRIVATE_CRT 0x03
+#define MSC_KEY_DSA_PUBLIC 0x04
+#define MSC_KEY_DSA_PRIVATE 0x05
+#define MSC_KEY_DES 0x06
+#define MSC_KEY_3DES 0x07
+#define MSC_KEY_3DES3 0x08
+
+ /*
+ * Key generation options TODO: add other
+ */
+#define MSC_OPT_DEFAULT 0x00
+#define MSC_OPT_RSA_PUB_EXP 0x01
+#define MSC_OPT_DSA_GPQ 0x02
+
+ /*
+ * Cipher operations in ComputeCrypt()
+ */
+#define MSC_CIPHER_INIT 0x01
+#define MSC_CIPHER_PROCESS 0x02
+#define MSC_CIPHER_FINAL 0x03
+
+ /*
+ * Cipher modes in ComputeCrypt()
+ */
+#define MSC_MODE_RSA_NOPAD 0x00
+#define MSC_MODE_RSA_PAD_PKCS1 0x01
+#define MSC_MODE_DSA_SHA 0x10
+#define MSC_MODE_DES_CBC_NOPAD 0x20
+#define MSC_MODE_DES_ECB_NOPAD 0x21
+
+ /*
+ * Cipher directions
+ */
+#define MSC_DIR_SIGN 0x01
+#define MSC_DIR_VERIFY 0x02
+#define MSC_DIR_ENCRYPT 0x03
+#define MSC_DIR_DECRYPT 0x04
+
+ /*
+ * Sequence options in ListXXX()
+ */
+#define MSC_SEQUENCE_RESET 0x00
+#define MSC_SEQUENCE_NEXT 0x01
+
+ /*
+ * Zero flag in DeleteObject()
+ */
+#define MSC_ZF_DEFAULT 0x00
+#define MSC_ZF_WRITE_ZERO 0x01
+
+ /*
+ * Some defines for ID's Bitmask
+ */
+#define MSC_AUT_ALL 0x0000
+#define MSC_AUT_NONE 0xFFFF
+
+#define MSC_AUT_PIN_0 0x0001
+#define MSC_AUT_PIN_1 0x0002
+#define MSC_AUT_PIN_2 0x0004
+#define MSC_AUT_PIN_3 0x0008
+#define MSC_AUT_PIN_4 0x0010
+
+#define MSC_AUT_KEY_0 0x0100
+#define MSC_AUT_KEY_1 0x0200
+#define MSC_AUT_KEY_2 0x0400
+#define MSC_AUT_KEY_3 0x0800
+#define MSC_AUT_KEY_4 0x1000
+#define MSC_AUT_KEY_5 0x2000
+
+#define MSC_AUT_USR_0 0x4000
+#define MSC_AUT_USR_1 0x8000
+
+ /*
+ * This structure allows you to customize your MuscleCard. It is used
+ * in MSCWriteFramework to specify attributes you may want to set in
+ * this 'personalization' routine and will be getting new values in
+ * future revisions of the API
+ */
+
+#define MSC_INIT_DEFAULT_KEY 0x00 /* Use card's default transport
+ * key */
+#define MSC_INIT_IGNORE_KEY 0x01 /* Don't verify any key at all */
+#define MSC_INIT_USE_KEY 0x02 /* Use the key in this struct */
+
+ typedef struct
+ {
+ MSCUChar8 transportKey[MAX_BUFFER_SIZE];
+ MSCULong32 transportKeyLen;
+ MSCUChar8 transportBehavior;
+ MSCULong32 objectMemory;
+
+ MSCUChar8 newTransportKey[MAX_BUFFER_SIZE];
+ MSCULong32 newTransportKeyLen;
+
+ MSCUChar8 defaultCHV[MAX_BUFFER_SIZE];
+ MSCULong32 defaultCHVLen;
+ MSCUChar8 defaultCHVTries;
+
+ MSCUChar8 defaultCHVUnblock[MAX_BUFFER_SIZE];
+ MSCULong32 defaultCHVUnblockSize;
+ MSCUChar8 defaultCHVUnblockTries;
+
+ MSCUShort16 createObjectACL;
+ MSCUShort16 createKeysACL;
+ MSCUShort16 createPINsACL;
+
+ MSCUChar8 maxNumberKeys;
+ MSCUChar8 maxNumberPINs;
+ MSCUShort16 maxNumberObjects;
+
+ }
+ MSCInitTokenParams, *MSCLPInitTokenParams;
+
+ /*
+ * Direction policy bitmasks for MSCKeyPolicy
+ */
+#define MSC_KEYPOLICY_MODE_RSA_NOPAD 0x0001
+#define MSC_KEYPOLICY_MODE_RSA_PAD_PKCS1 0x0002
+#define MSC_KEYPOLICY_MODE_DSA_SHA 0x0004
+#define MSC_KEYPOLICY_MODE_DES_CBC_NOPAD 0x0008
+#define MSC_KEYPOLICY_MODE_DES_ECB_NOPAD 0x0010
+
+#define MSC_KEYPOLICY_DIR_SIGN 0x0100
+#define MSC_KEYPOLICY_DIR_VERIFY 0x0200
+#define MSC_KEYPOLICY_DIR_ENCRYPT 0x0400
+#define MSC_KEYPOLICY_DIR_DECRYPT 0x0800
+
+ typedef struct
+ {
+ MSCUShort16 cipherMode;
+ MSCUShort16 cipherDirection;
+ }
+ MSCKeyPolicy, *MSCLPKeyPolicy;
+
+ typedef struct
+ {
+ MSCUShort16 readPermission;
+ MSCUShort16 writePermission;
+ MSCUShort16 usePermission;
+ }
+ MSCKeyACL, *MSCLPKeyACL;
+
+ typedef struct
+ {
+ MSCUShort16 readPermission;
+ MSCUShort16 writePermission;
+ MSCUShort16 deletePermission;
+ }
+ MSCObjectACL, *MSCLPObjectACL, MSCCertACL, *MSCLPCertACL;
+
+ typedef struct
+ {
+ MSCUChar8 algoType;
+ MSCUShort16 keySize;
+ MSCKeyACL privateKeyACL;
+ MSCKeyACL publicKeyACL;
+ MSCKeyPolicy privateKeyPolicy;
+ MSCKeyPolicy publicKeyPolicy;
+ MSCUChar8 keyGenOptions;
+ MSCPUChar8 pOptParams;
+ MSCULong32 optParamsSize;
+ }
+ MSCGenKeyParams, *MSCLPGenKeyParams;
+
+ typedef MSCPUChar8 MSCLPKeyBlob;
+
+ typedef struct
+ {
+ MSCUChar8 keyNum;
+ MSCUChar8 keyType;
+ MSCUChar8 keyPartner; /* Do not use (deprecated) */
+ MSCUChar8 keyMapping; /* Do not use (deprecated) */
+ MSCUShort16 keySize;
+ MSCKeyPolicy keyPolicy;
+ MSCKeyACL keyACL;
+ }
+ MSCKeyInfo, *MSCLPKeyInfo;
+
+ typedef struct
+ {
+ MSCUChar8 keyNum;
+ MSCUChar8 cipherMode;
+ MSCUChar8 cipherDirection;
+ MSCPUChar8 optParams;
+ MSCUShort16 optParamsSize;
+ }
+ MSCCryptInit, *MSCLPCryptInit;
+
+ /*
+ * Scope definitions for MSCListTokens
+ */
+#define MSC_LIST_KNOWN 1 /* Lists known tokens only */
+#define MSC_LIST_SLOTS 2 /* Lists all slots, with or without tokens
+ */
+#define MSC_LIST_ALL 3 /* Lists all tokens, known or not */
+
+#define MSC_TOKEN_EMPTY_STR "Token Removed"
+#define MSC_TOKEN_UNKNOWN_STR "Token Unknown"
+
+#define MSC_TOKEN_TYPE_REMOVED 1 /* Token was removed at one point */
+#define MSC_TOKEN_TYPE_UNKNOWN 2 /* Token is unknown, state is fine */
+#define MSC_TOKEN_TYPE_KNOWN 4 /* Token is known, state is fine */
+#define MSC_TOKEN_TYPE_RESET 8 /* Token is known, was reset */
+
+ /*
+ * endAction definitions for MSCReleaseConnection
+ */
+#define MSC_LEAVE_TOKEN SCARD_LEAVE_CARD
+#define MSC_RESET_TOKEN SCARD_RESET_CARD
+#define MSC_EJECT_TOKEN SCARD_EJECT_CARD
+
+ /*
+ * sharingMode for MSCEstablishConnection
+ */
+#define MSC_SHARE_SHARED SCARD_SHARE_SHARED
+#define MSC_SHARE_EXCLUSIVE SCARD_SHARE_EXCLUSIVE
+#define MSC_SHARE_DIRECT SCARD_SHARE_DIRECT
+
+ /*
+ * tokenState for MSCWaitForTokenEvent
+ */
+#define MSC_STATE_UNAWARE 0x4000
+#define MSC_STATE_CHANGED SCARD_STATE_CHANGED
+#define MSC_STATE_UNKNOWN SCARD_STATE_UNKNOWN
+#define MSC_STATE_UNAVAILABLE SCARD_STATE_UNAVAILABLE
+#define MSC_STATE_EMPTY SCARD_STATE_EMPTY
+#define MSC_STATE_PRESENT SCARD_STATE_PRESENT
+#define MSC_STATE_EXCLUSIVE SCARD_STATE_EXCLUSIVE
+#define MSC_STATE_INUSE SCARD_STATE_INUSE
+#define MSC_STATE_MUTE SCARD_STATE_MUTE
+
+#define MSC_NO_TIMEOUT INFINITE
+
+/********************** TAGS for GetStatus ********************************/
+
+ /*
+ * high level tags
+ */
+#define MSC_TAG_SUPPORT_FUNCTIONS 101 /* Supported functions */
+#define MSC_TAG_SUPPORT_CRYPTOALG 102 /* Supported crypto algorithms
+ */
+
+ /*
+ * crypto related tags
+ */
+#define MSC_TAG_CAPABLE_RSA 103 /* RSA capabilities */
+#define MSC_TAG_CAPABLE_DSA 104 /* DSA capabilities */
+#define MSC_TAG_CAPABLE_ECURVE 105 /* Eliptic Curve capabilities */
+#define MSC_TAG_CAPABLE_ELGAMAL 106 /* El Gamal capabilities */
+
+#define MSC_TAG_CAPABLE_KEY_AUTH 180 /* Key import/gen AUT needed */
+
+#define MSC_TAG_CAPABLE_DES 201 /* DES capabilities */
+#define MSC_TAG_CAPABLE_3DES 202 /* Triple DES capabilities */
+#define MSC_TAG_CAPABLE_IDEA 203 /* IDEA capabilities */
+#define MSC_TAG_CAPABLE_AES 204 /* AES capabilities */
+#define MSC_TAG_CAPABLE_BLOWFISH 205 /* Blowfish capabilities */
+#define MSC_TAG_CAPABLE_TWOFISH 206 /* Twofish capabilities */
+
+#define MSC_TAG_CAPABLE_MD5 207 /* MD5 capabilities */
+#define MSC_TAG_CAPABLE_SHA1 208 /* SHA1 capabilities */
+
+ /*
+ * object related tags
+ */
+#define MSC_TAG_CAPABLE_OBJ_ATTR 301 /* returns general attributes */
+#define MSC_TAG_CAPABLE_OBJ_IDSIZE 302 /* returns size of object id */
+#define MSC_TAG_CAPABLE_OBJ_AUTH 303 /* return AUT needed for
+ * create */
+#define MSC_TAG_CAPABLE_OBJ_MAXNUM 304 /* maximum number of objects */
+
+ /*
+ * pin related tags
+ */
+#define MSC_TAG_CAPABLE_PIN_ATTR 401 /* returns general attributes */
+#define MSC_TAG_CAPABLE_PIN_MAXNUM 402 /* returns max number of pins */
+#define MSC_TAG_CAPABLE_PIN_MINSIZE 403 /* returns minimum pin size */
+#define MSC_TAG_CAPABLE_PIN_MAXSIZE 404 /* returns maximum pin size */
+#define MSC_TAG_CAPABLE_PIN_CHARSET 405 /* char set supported
+ * (bitmask) */
+#define MSC_TAG_CAPABLE_PIN_POLICY 406 /* returns pin policy
+ * (bitmask) */
+#define MSC_TAG_CAPABLE_PIN_AUTH 407 /* return AUT needed for
+ * create */
+
+#define MSC_TAG_CAPABLE_ID_STATE 501 /* returns state capability */
+
+#define MSC_TAG_CAPABLE_RANDOM 600 /* Random number capabilities */
+#define MSC_TAG_CAPABLE_RANDOM_MAX 601 /* Maximum random number */
+#define MSC_TAG_CAPABLE_RANDOM_MIN 602 /* Minimum random number */
+
+/********************************** END OF TAGS ***************************/
+
+ /*
+ * Bitmask for TAG MSC_TAG_SUPPORT_FUNCTIONS
+ */
+#define MSC_SUPPORT_GENKEYS 0x00000001
+#define MSC_SUPPORT_IMPORTKEY 0x00000002
+#define MSC_SUPPORT_EXPORTKEY 0x00000004
+#define MSC_SUPPORT_COMPUTECRYPT 0x00000008
+#define MSC_SUPPORT_EXTAUTH 0x00000010
+#define MSC_SUPPORT_LISTKEYS 0x00000020
+#define MSC_SUPPORT_CREATEPIN 0x00000040
+#define MSC_SUPPORT_VERIFYPIN 0x00000080
+#define MSC_SUPPORT_CHANGEPIN 0x00000100
+#define MSC_SUPPORT_UNBLOCKPIN 0x00000200
+#define MSC_SUPPORT_LISTPINS 0x00000400
+#define MSC_SUPPORT_CREATEOBJECT 0x00000800
+#define MSC_SUPPORT_DELETEOBJECT 0x00001000
+#define MSC_SUPPORT_WRITEOBJECT 0x00002000
+#define MSC_SUPPORT_READOBJECT 0x00004000
+#define MSC_SUPPORT_LISTOBJECTS 0x00008000
+#define MSC_SUPPORT_LOGOUTALL 0x00010000
+#define MSC_SUPPORT_GETCHALLENGE 0x00020000
+
+ /*
+ * Bitmask for MSC_TAG_SUPPORT_CRYPTOALG
+ */
+#define MSC_SUPPORT_RSA 0x00000001 /* Supports RSA */
+#define MSC_SUPPORT_DSA 0x00000002 /* Supports DSA */
+#define MSC_SUPPORT_ECURVE 0x00000004 /* Supports Eliptic Curve */
+#define MSC_SUPPORT_ELGAMAL 0x00000008 /* Supports El Gamal */
+
+#define MSC_SUPPORT_DES 0x00000010 /* Supports DES */
+#define MSC_SUPPORT_3DES 0x00000020 /* Supports Triple DES */
+#define MSC_SUPPORT_IDEA 0x00000040 /* Supports IDEA */
+#define MSC_SUPPORT_AES 0x00000080 /* Supports AES */
+#define MSC_SUPPORT_BLOWFISH 0x00000100 /* Supports Blowfish */
+#define MSC_SUPPORT_TWOFISH 0x00000200 /* Supports Twofish */
+#define MSC_SUPPORT_SHA1 0x00000400 /* Supports SHA1 */
+#define MSC_SUPPORT_MD5 0x00000800 /* Supports MD5 */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_RSA
+ */
+#define MSC_CAPABLE_RSA_512 0x00000001 /* Supports 512 bit RSA */
+#define MSC_CAPABLE_RSA_768 0x00000002 /* Supports 768 bit RSA */
+#define MSC_CAPABLE_RSA_1024 0x00000004 /* Supports 1024 bit RSA */
+#define MSC_CAPABLE_RSA_2048 0x00000008 /* Supports 2048 bit RSA */
+#define MSC_CAPABLE_RSA_4096 0x00000010 /* Supports 4096 bit RSA */
+
+#define MSC_CAPABLE_RSA_KEYGEN 0x00001000 /* Support RSA key-gen */
+#define MSC_CAPABLE_RSA_NOPAD 0x00002000 /* Supports RSA NO PAD */
+#define MSC_CAPABLE_RSA_PKCS1 0x00004000 /* Supports PKCS padding */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_DSA
+ */
+#define MSC_CAPABLE_DSA_512 0x00000001 /* Supports 512 bit DSA */
+#define MSC_CAPABLE_DSA_768 0x00000002 /* Supports 768 bit DSA */
+#define MSC_CAPABLE_DSA_1024 0x00000004 /* Supports 1024 bit DSA */
+#define MSC_CAPABLE_DSA_2048 0x00000008 /* Supports 2048 bit DSA */
+#define MSC_CAPABLE_DSA_4096 0x00000010 /* Supports 4096 bit DSA */
+#define MSC_CAPABLE_DSA_KEYGEN 0x00001000 /* Supports DSA key-gen */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_DES
+ */
+#define MSC_CAPABLE_DES_KEYGEN 0x00001000 /* Supports DES key-gen */
+#define MSC_CAPABLE_DES_CBC 0x00002000 /* Supports DES CBC mode */
+#define MSC_CAPABLE_DES_EBC 0x00004000 /* Supports DES EBC mode */
+#define MSC_CAPABLE_DES_ECB 0x00008000 /* Supports DES ECB mode */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_3DES
+ */
+#define MSC_CAPABLE_3DES_KEYGEN 0x00001000 /* Supports 3DES key-gen */
+#define MSC_CAPABLE_3DES_3KEY 0x00002000 /* Support 3 key 3DES */
+#define MSC_CAPABLE_3DES_CBC 0x00004000 /* Supports 3DES CBC mode */
+#define MSC_CAPABLE_3DES_EBC 0x00008000 /* Supports 3DES EBC mode */
+#define MSC_CAPABLE_3DES_ECB 0x00010000 /* Supports 3DES ECB mode */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_IDEA
+ */
+#define MSC_CAPABLE_IDEA_KEYGEN 0x00001000 /* Supports IDEA key-gen */
+#define MSC_CAPABLE_IDEA_CBC 0x00002000 /* Supports IDEA CBC mode */
+#define MSC_CAPABLE_IDEA_ECB 0x00008000 /* Supports IDEA ECB mode */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_AES
+ */
+#define MSC_CAPABLE_AES_KEYGEN 0x00001000 /* Supports AES key-gen */
+#define MSC_CAPABLE_AES_CBC 0x00002000 /* Supports AES CBC mode */
+#define MSC_CAPABLE_AES_ECB 0x00008000 /* Supports AES ECB mode */
+
+ /***********************************
+ Bitmasks for other crypto algorithms
+ will come in future releases
+ ************************************/
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_OBJ_ATTR
+ */
+#define MSC_CAPABLE_OBJ_ZERO 0x00010000 /* Supports zero on DEL */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_PIN_ATTR
+ */
+#define MSC_CAPABLE_PIN_RESET 0x00000100 /* Unblock reset's pin */
+#define MSC_CAPABLE_PIN_LEAVE 0x00000200 /* Unblock leaves pin */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_PIN_CHARSET
+ */
+#define MSC_CAPABLE_PIN_A_Z 0x00000001 /* Supports uppercase A-Z */
+#define MSC_CAPABLE_PIN_a_z 0x00000002 /* Supports lowercase a-z */
+#define MSC_CAPABLE_PIN_0_9 0x00000004 /* Supports numbers 0-9 */
+#define MSC_CAPABLE_PIN_SPACE 0x00000008 /* Supports spaces */
+#define MSC_CAPABLE_PIN_CALC 0x00000010 /* Supports + - / * % .= */
+#define MSC_CAPABLE_PIN_NONALPHA 0x00000020 /* Supports all other
+ * chars */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_PIN_POLICY
+ */
+#define MSC_CAPABLE_PIN_A_Z 0x00000001 /* Requires uppercase A-Z */
+#define MSC_CAPABLE_PIN_a_z 0x00000002 /* Requires lowercase a-z */
+#define MSC_CAPABLE_PIN_0_9 0x00000004 /* Requires numbers 0-9 */
+#define MSC_CAPABLE_PIN_NONALPHA 0x00000020 /* Requires
+ * non-alphanumeric */
+#define MSC_CAPABLE_PIN_HISTORY 0x00001000 /* Checks pin history */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_ID_STATE
+ */
+#define MSC_CAPABLE_ID_STATE 0x00000001 /* maintains logged id
+ * state */
+
+ /*
+ * Bitmask for TAG MSC_TAG_CAPABLE_RANDOM
+ */
+#define MSC_CAPABLE_RANDOM_SEED 0x00000001 /* Uses supplied seed */
+
+ /*
+ * Structure used in MSCGetStatus to return status and capability
+ * information about the inserted token
+ */
+
+ typedef struct
+ {
+ MSCUShort16 appVersion; /* Applet version number */
+ MSCUShort16 swVersion; /* Software version number */
+ MSCULong32 freeMemory; /* Free memory for objects */
+ MSCULong32 totalMemory; /* Total amount of memory */
+ MSCUChar8 usedPINs; /* Number of pins used */
+ MSCUChar8 usedKeys; /* Number of keys used */
+ MSCUShort16 loggedID; /* Bitmask of ID's verified */
+ }
+ MSCStatusInfo, *MSCLPStatusInfo;
+
+ typedef struct
+ {
+ MSCChar8 objectID[MSC_MAXSIZE_OBJID];
+ MSCULong32 objectSize;
+ MSCObjectACL objectACL;
+ }
+ MSCObjectInfo, *MSCLPObjectInfo;
+
+ /*******************************************************************/
+ /*
+ * Connection oriented functions
+ */
+ /*
+ * These functions do not coorespond to internal library funcions
+ */
+ /*
+ * but serve to connect to tokens. You can still use the internal
+ */
+ /*
+ * PC/SC calls to do this. These provide an abstract means.
+ */
+ /*******************************************************************/
+
+ /*
+ * Lists all known tokens on the system
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCListTokens(MSCULong32 listScope, /* defines the scope to
+ * return */
+ MSCLPTokenInfo tokenArray, /* token struct array */
+ MSCPULong32 arrayLength /* Length of array */
+ );
+
+ /*
+ * Establishes a connection to the specified token
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCEstablishConnection(MSCLPTokenInfo tokenStruct, /* The
+ * struct
+ * of
+ * token */
+ MSCULong32 sharingMode, /* Mode of sharing */
+ MSCPUChar8 applicationName, /* The applet ID/Name */
+ MSCULong32 nameSize, /* The ID/Name Size */
+ MSCLPTokenConnection pConnection /* Returned connection */
+ );
+
+ /*
+ * Releases a connection to the specified token
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCReleaseConnection(MSCLPTokenConnection pConnection, /* Connection
+ * handle
+ */
+ MSCULong32 endAction /* Action to perform */
+ );
+
+ /*
+ * Blocks for an event to occur on a token
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCWaitForTokenEvent(MSCLPTokenInfo tokenArray, /* Array of
+ * token
+ * structs */
+ MSCULong32 arraySize, /* Size of the array */
+ MSCULong32 timeoutValue /* Timeout */
+ );
+
+ /*
+ * Cancels a pending MSCWaitForTokenEvent
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCCancelEventWait(void /* No parameters */
+ );
+
+ /*
+ * Registers a callback function for event change
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCCallbackForTokenEvent(MSCLPTokenInfo tokenArray, /* Array
+ * of
+ * token
+ * structs
+ */
+ MSCULong32 arraySize, /* Size of the array */
+ MSCCallBack callBack, /* Callback function */
+ MSCPVoid32 appData /* Application data */
+ );
+
+ /*
+ * Cancels all callback registrations
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCCallbackCancelEvent();
+
+ /*
+ * Locks a transaction to the token
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCBeginTransaction(MSCLPTokenConnection pConnection /* Connection
+ * handle */
+ );
+
+ /*
+ * Releases a locked transaction to the token
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCEndTransaction(MSCLPTokenConnection pConnection, /* Connection
+ * handle */
+ MSCULong32 endAction /* Action to perform on token */
+ );
+
+ /*
+ * Selects applet - Not to be used by applications
+ */
+ MSC_RV MSCSelectAID(MSCLPTokenConnection pConnection,
+ MSCPUChar8 aidValue, MSCULong32 aidSize);
+
+ /*
+ * Pre-personalization function
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCWriteFramework(MSCLPTokenConnection pConnection,
+ MSCLPInitTokenParams pInitParams);
+
+ /*****************************************************************/
+ /*
+ * Core Musclecard functions
+ */
+ /*
+ * These functions coorespond directly to internal library
+ */
+ /*
+ * functions.
+ */
+ /*****************************************************************/
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGetStatus(MSCLPTokenConnection pConnection,
+ MSCLPStatusInfo pStatusInfo);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGetCapabilities(MSCLPTokenConnection pConnection,
+ MSCULong32 Tag, MSCPUChar8 Value, MSCPULong32 Length);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCExtendedFeature(MSCLPTokenConnection pConnection,
+ MSCULong32 extFeature,
+ MSCPUChar8 outData,
+ MSCULong32 outLength, MSCPUChar8 inData, MSCPULong32 inLength);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGenerateKeys(MSCLPTokenConnection pConnection,
+ MSCUChar8 prvKeyNum,
+ MSCUChar8 pubKeyNum, MSCLPGenKeyParams pParams);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCImportKey(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNum,
+ MSCLPKeyACL pKeyACL,
+ MSCPUChar8 pKeyBlob,
+ MSCULong32 keyBlobSize,
+ MSCLPKeyPolicy keyPolicy,
+ MSCPVoid32 pAddParams, MSCUChar8 addParamsSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCExportKey(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNum,
+ MSCPUChar8 pKeyBlob,
+ MSCPULong32 keyBlobSize,
+ MSCPVoid32 pAddParams, MSCUChar8 addParamsSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCComputeCrypt(MSCLPTokenConnection pConnection,
+ MSCLPCryptInit cryptInit,
+ MSCPUChar8 pInputData,
+ MSCULong32 inputDataSize,
+ MSCPUChar8 pOutputData, MSCPULong32 outputDataSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCExtAuthenticate(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNum,
+ MSCUChar8 cipherMode,
+ MSCUChar8 cipherDirection,
+ MSCPUChar8 pData,
+ MSCULong32 dataSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCListKeys(MSCLPTokenConnection pConnection,
+ MSCUChar8 seqOption,
+ MSCLPKeyInfo pKeyInfo);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCCreatePIN(MSCLPTokenConnection pConnection,
+ MSCUChar8 pinNum,
+ MSCUChar8 pinAttempts,
+ MSCPUChar8 pPinCode,
+ MSCULong32 pinCodeSize,
+ MSCPUChar8 pUnblockCode,
+ MSCUChar8 unblockCodeSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCVerifyPIN(MSCLPTokenConnection pConnection,
+ MSCUChar8 pinNum,
+ MSCPUChar8 pPinCode,
+ MSCULong32 pinCodeSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCChangePIN(MSCLPTokenConnection pConnection,
+ MSCUChar8 pinNum,
+ MSCPUChar8 pOldPinCode,
+ MSCUChar8 oldPinCodeSize,
+ MSCPUChar8 pNewPinCode, MSCUChar8 newPinCodeSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCUnblockPIN(MSCLPTokenConnection pConnection,
+ MSCUChar8 pinNum,
+ MSCPUChar8 pUnblockCode, MSCULong32 unblockCodeSize);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCListPINs(MSCLPTokenConnection pConnection,
+ MSCPUShort16 pPinBitMask);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCCreateObject(MSCLPTokenConnection pConnection,
+ MSCString objectID,
+ MSCULong32 objectSize, MSCLPObjectACL pObjectACL);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCDeleteObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCUChar8 zeroFlag);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCWriteObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCULong32 offset,
+ MSCPUChar8 pInputData, MSCULong32 dataSize,
+ LPRWEventCallback rwCallback, MSCPVoid32 addParams);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCReadObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCULong32 offset,
+ MSCPUChar8 pOutputData, MSCULong32 dataSize,
+ LPRWEventCallback rwCallback, MSCPVoid32 addParams);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCReadAllocateObject(MSCLPTokenConnection pConnection,
+ MSCString objectID, MSCPUChar8 *pOutputData,
+ MSCPULong32 dataSize,
+ LPRWEventCallback rwCallback, MSCPVoid32 addParams);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCListObjects(MSCLPTokenConnection pConnection,
+ MSCUChar8 seqOption, MSCLPObjectInfo pObjectInfo);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCLogoutAll(MSCLPTokenConnection pConnection);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGetChallenge(MSCLPTokenConnection pConnection,
+ MSCPUChar8 pSeed,
+ MSCUShort16 seedSize,
+ MSCPUChar8 pRandomData, MSCUShort16 randomDataSize);
+
+ /*****************************************************************/
+ /*
+ * Extended Musclecard functions
+ */
+ /*
+ * These functions do not coorespond to internal library funcions
+ */
+ /*
+ * but rather use them to provide some extended functionality.
+ */
+ /*****************************************************************/
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGetKeyAttributes(MSCLPTokenConnection pConnection,
+ MSCUChar8 keyNumber,
+ MSCLPKeyInfo pKeyInfo);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSC_RV MSCGetObjectAttributes(MSCLPTokenConnection pConnection,
+ MSCString objectID,
+ MSCLPObjectInfo pObjectInfo);
+
+#ifdef WIN32
+ PCSC_API
+#endif
+ char *msc_error(unsigned long int errorCode);
+
+ /*
+ * Was the token reset ?
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSCUChar8 MSCIsTokenReset(MSCLPTokenConnection pConnection);
+
+ /*
+ * Clear the Reset state
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSCUChar8 MSCClearReset(MSCLPTokenConnection pConnection);
+
+ /*
+ * Was the token moved (removed, removed/inserted) ?
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSCUChar8 MSCIsTokenMoved(MSCLPTokenConnection pConnection);
+
+ /*
+ * Did any state change with the token ?
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSCUChar8 MSCIsTokenChanged(MSCLPTokenConnection pConnection);
+
+ /*
+ * Is the token recognized ?
+ */
+#ifdef WIN32
+ PCSC_API
+#endif
+ MSCUChar8 MSCIsTokenKnown(MSCLPTokenConnection pConnection);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __musclecard_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/muscletest.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/muscletest.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/muscletest.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,372 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : test.c
+ Package: card edge
+ Author : David Corcoran
+ Date : 10/04/01
+ License: Copyright (C) 2001 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This tests the virtual card edge
+
+
+********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <winscard.h>
+#include <mscdefines.h>
+#include <musclecard.h>
+
+#define MY_OBJECT_ID "c1"
+#define MY_OBJECT_SIZE 50
+
+#ifdef MSC_ARCH_WIN32
+MSCString pcsc_stringify_error(MSCLong32 Error);
+#endif
+
+int main(int argc, char **argv)
+{
+
+ MSCLong32 rv;
+ MSCTokenConnection pConnection;
+ MSCStatusInfo statusInf;
+ MSCObjectACL objACL;
+ MSCObjectInfo objInfo;
+ MSCUChar8 pRandomData[20];
+ MSCUChar8 pSeed[8];
+ MSCUChar8 defaultPIN[16];
+ MSCUChar8 AID[6] = { 0xA0, 0x00, 0x00, 0x00, 0x01, 0x01 };
+ MSCUChar8 myData[] =
+ { 'M', 'U', 'S', 'C', 'L', 'E', ' ', 'V', 'I', 'R',
+ 'T', 'U', 'A', 'L', ' ', 'C', 'A', 'R', 'D', '.', 0
+ };
+ MSCUChar8 readData[50];
+ MSCLPTokenInfo tokenList;
+ MSCULong32 tokenSize;
+ int i, j;
+
+ printf("********************************************************\n");
+ printf("\n");
+
+ tokenList = 0;
+ tokenSize = 0;
+
+ rv = MSCListTokens(MSC_LIST_SLOTS, tokenList, &tokenSize);
+ if (rv != MSC_SUCCESS)
+ {
+ printf("MSCListTokens returns : %s\n", msc_error(rv));
+ return -1;
+ }
+
+ tokenList = (MSCLPTokenInfo) malloc(sizeof(MSCTokenInfo) * tokenSize);
+
+ rv = MSCListTokens(MSC_LIST_SLOTS, tokenList, &tokenSize);
+ if (rv != MSC_SUCCESS)
+ {
+ printf("MSCListTokens returns : %s\n", msc_error(rv));
+ return -1;
+ }
+
+ for (i = 0; i < tokenSize; i++)
+ {
+ printf("Token #%d\n", i);
+ printf("Token name : %s\n", tokenList[i].tokenName);
+ printf("Slot name : %s\n", tokenList[i].slotName);
+ printf("Token id : ");
+ for (j = 0; j < tokenList[i].tokenIdLength; j++)
+ {
+ printf("%02X", tokenList[i].tokenId[j]);
+ }
+ printf("\n");
+ printf("Token state : %ld\n", tokenList[i].tokenState);
+ printf("\n");
+
+ tokenList[i].tokenState = MSC_STATE_EMPTY;
+ }
+
+ printf("********************************************************\n");
+
+ rv = MSCWaitForTokenEvent(tokenList, tokenSize, MSC_NO_TIMEOUT);
+
+ for (i = 0; i < tokenSize; i++)
+ {
+ printf("Token #%d\n", i);
+ printf("Token name : %s\n", tokenList[i].tokenName);
+ printf("Slot name : %s\n", tokenList[i].slotName);
+ printf("Token id : ");
+ for (j = 0; j < tokenList[i].tokenIdLength; j++)
+ {
+ printf("%02X", tokenList[i].tokenId[j]);
+ }
+ printf("\n");
+ printf("Token state : %ld\n", tokenList[i].tokenState);
+ printf("\n");
+ }
+
+ rv = MSCEstablishConnection(&tokenList[0], MSC_SHARE_SHARED, AID,
+ 6, &pConnection);
+ if (rv != MSC_SUCCESS)
+ {
+ printf("EstablishConn returns : %s\n", msc_error(rv));
+ return -1;
+ }
+
+ rv = MSCBeginTransaction(&pConnection);
+ printf("BeginTransaction returns : %s\n", msc_error(rv));
+
+ rv = MSCGetStatus(&pConnection, &statusInf);
+ printf("GetStatus returns : %s\n", msc_error(rv));
+ printf("Protocol version : %04x\n", statusInf.appVersion);
+ printf("Applet version : %04x\n", statusInf.swVersion);
+ printf("Total object memory : %08ld\n", statusInf.totalMemory);
+ printf("Free object memory : %08ld\n", statusInf.freeMemory);
+ printf("Number of used PINs : %02d\n", statusInf.usedPINs);
+ printf("Number of used Keys : %02d\n", statusInf.usedKeys);
+ printf("Currently logged identities : %04x\n", statusInf.loggedID);
+
+ printf("Please enter the pin value\n");
+ fgets(defaultPIN, sizeof(defaultPIN), stdin);
+
+ rv = MSCVerifyPIN(&pConnection, 0, defaultPIN, strlen(defaultPIN) - 1);
+ printf("Verify default PIN : %s\n", msc_error(rv));
+
+ rv = MSCGetStatus(&pConnection, &statusInf);
+ printf("Currently logged identities : %04x\n", statusInf.loggedID);
+
+ objACL.readPermission = MSC_AUT_ALL;
+ objACL.writePermission = MSC_AUT_ALL;
+ objACL.deletePermission = MSC_AUT_ALL;
+
+ rv = MSCCreateObject(&pConnection, MY_OBJECT_ID, MY_OBJECT_SIZE,
+ &objACL);
+ printf("CreateObject returns : %s\n", msc_error(rv));
+
+ rv = MSCWriteObject(&pConnection, MY_OBJECT_ID, 0, myData,
+ sizeof(myData), 0, 0);
+ printf("WriteObject returns : %s\n", msc_error(rv));
+
+ rv = MSCReadObject(&pConnection, MY_OBJECT_ID, 0, readData, 25, 0, 0);
+ printf("ReadObject returns : %s\n", msc_error(rv));
+
+ if (rv == MSC_SUCCESS)
+ {
+ printf("Object data : %s\n", readData);
+ if (strcmp(readData, myData) == 0)
+ {
+ printf("Data comparison : Successful\n");
+ } else
+ {
+ printf("Data comparison : Data mismatch\n");
+ }
+ }
+
+ rv = MSCListObjects(&pConnection, MSC_SEQUENCE_RESET, &objInfo);
+
+ printf("\n");
+ printf("Listing objects : %s\n", msc_error(rv));
+ printf("------------------------------------------------------\n");
+ printf("%20s %12s %6s %6s %6s\n", "Object ID", "Object Size",
+ "READ", "WRITE", "DELETE");
+ printf(" ----------------- ----------- ---- ----- ------\n");
+
+ if (rv == MSC_SUCCESS)
+ {
+ printf("%20s %12d %04x %04x %04x\n", objInfo.objectID,
+ objInfo.objectSize,
+ objInfo.objectACL.readPermission,
+ objInfo.objectACL.writePermission,
+ objInfo.objectACL.deletePermission);
+ }
+
+ do
+ {
+ rv = MSCListObjects(&pConnection, MSC_SEQUENCE_NEXT, &objInfo);
+ if (rv == MSC_SUCCESS)
+ {
+ printf("%20s %12d %04x %04x %04x\n", objInfo.objectID,
+ objInfo.objectSize,
+ objInfo.objectACL.readPermission,
+ objInfo.objectACL.writePermission,
+ objInfo.objectACL.deletePermission);
+ } else
+ {
+ break;
+ }
+
+ }
+ while (1);
+
+ printf("------------------------------------------------------\n");
+ printf("\n");
+
+ rv = MSCGetStatus(&pConnection, &statusInf);
+ printf("Free object memory : %08ld\n", statusInf.freeMemory);
+
+ rv = MSCDeleteObject(&pConnection, MY_OBJECT_ID, MSC_ZF_DEFAULT);
+ printf("DeleteObject returns : %s\n", msc_error(rv));
+
+ rv = MSCGetStatus(&pConnection, &statusInf);
+ printf("Free object memory : %08ld\n", statusInf.freeMemory);
+
+ rv = MSCGetChallenge(&pConnection, pSeed, 0, pRandomData, 8);
+ printf("GetChallenge returns : %s\n", msc_error(rv));
+ printf("Random data : ");
+
+ for (i = 0; i < 8; i++)
+ {
+ printf("%x ", pRandomData[i]);
+ }
+ printf("\n");
+
+ rv = MSCLogoutAll(&pConnection);
+ printf("Logout all identities : %s\n", msc_error(rv));
+
+ rv = MSCGetStatus(&pConnection, &statusInf);
+ printf("Currently logged identities : %04x\n", statusInf.loggedID);
+
+ rv = MSCEndTransaction(&pConnection, SCARD_LEAVE_CARD);
+ printf("EndTransaction returns : %s\n", msc_error(rv));
+
+ MSCReleaseConnection(&pConnection, SCARD_LEAVE_CARD);
+ printf("ReleaseConn returns : %s\n", msc_error(rv));
+
+ return 0;
+}
+
+#ifdef MSC_ARCH_WIN32
+MSCString pcsc_stringify_error(MSCLong32 Error)
+{
+
+ static char strError[75];
+
+ switch (Error)
+ {
+ case SCARD_S_SUCCESS:
+ strcpy(strError, "Command successful.");
+ break;
+ case SCARD_E_CANCELLED:
+ strcpy(strError, "Command cancelled.");
+ break;
+ case SCARD_E_CANT_DISPOSE:
+ strcpy(strError, "Cannot dispose handle.");
+ break;
+ case SCARD_E_INSUFFICIENT_BUFFER:
+ strcpy(strError, "Insufficient buffer.");
+ break;
+ case SCARD_E_INVALID_ATR:
+ strcpy(strError, "Invalid ATR.");
+ break;
+ case SCARD_E_INVALID_HANDLE:
+ strcpy(strError, "Invalid handle.");
+ break;
+ case SCARD_E_INVALID_PARAMETER:
+ strcpy(strError, "Invalid parameter given.");
+ break;
+ case SCARD_E_INVALID_TARGET:
+ strcpy(strError, "Invalid target given.");
+ break;
+ case SCARD_E_INVALID_VALUE:
+ strcpy(strError, "Invalid value given.");
+ break;
+ case SCARD_E_NO_MEMORY:
+ strcpy(strError, "Not enough memory.");
+ break;
+ case SCARD_F_COMM_ERROR:
+ strcpy(strError, "RPC transport error.");
+ break;
+ case SCARD_F_INTERNAL_ERROR:
+ strcpy(strError, "Unknown internal error.");
+ break;
+ case SCARD_F_UNKNOWN_ERROR:
+ strcpy(strError, "Unknown internal error.");
+ break;
+ case SCARD_F_WAITED_TOO_MSCLong32:
+ strcpy(strError, "Waited too long.");
+ break;
+ case SCARD_E_UNKNOWN_READER:
+ strcpy(strError, "Unknown reader specified.");
+ break;
+ case SCARD_E_TIMEOUT:
+ strcpy(strError, "Command timeout.");
+ break;
+ case SCARD_E_SHARING_VIOLATION:
+ strcpy(strError, "Sharing violation.");
+ break;
+ case SCARD_E_NO_SMARTCARD:
+ strcpy(strError, "No smartcard inserted.");
+ break;
+ case SCARD_E_UNKNOWN_CARD:
+ strcpy(strError, "Unknown card.");
+ break;
+ case SCARD_E_PROTO_MISMATCH:
+ strcpy(strError, "Card protocol mismatch.");
+ break;
+ case SCARD_E_NOT_READY:
+ strcpy(strError, "Subsystem not ready.");
+ break;
+ case SCARD_E_SYSTEM_CANCELLED:
+ strcpy(strError, "System cancelled.");
+ break;
+ case SCARD_E_NOT_TRANSACTED:
+ strcpy(strError, "Transaction failed.");
+ break;
+ case SCARD_E_READER_UNAVAILABLE:
+ strcpy(strError, "Reader/s is unavailable.");
+ break;
+ case SCARD_W_UNSUPPORTED_CARD:
+ strcpy(strError, "Card is not supported.");
+ break;
+ case SCARD_W_UNRESPONSIVE_CARD:
+ strcpy(strError, "Card is unresponsive.");
+ break;
+ case SCARD_W_UNPOWERED_CARD:
+ strcpy(strError, "Card is unpowered.");
+ break;
+ case SCARD_W_RESET_CARD:
+ strcpy(strError, "Card was reset.");
+ break;
+ case SCARD_W_REMOVED_CARD:
+ strcpy(strError, "Card was removed.");
+ break;
+ case SCARD_E_PCI_TOO_SMALL:
+ strcpy(strError, "PCI struct too small.");
+ break;
+ case SCARD_E_READER_UNSUPPORTED:
+ strcpy(strError, "Reader is unsupported.");
+ break;
+ case SCARD_E_DUPLICATE_READER:
+ strcpy(strError, "Reader already exists.");
+ break;
+ case SCARD_E_CARD_UNSUPPORTED:
+ strcpy(strError, "Card is unsupported.");
+ break;
+ case SCARD_E_NO_SERVICE:
+ strcpy(strError, "Service not available.");
+ break;
+ case SCARD_E_SERVICE_STOPPED:
+ strcpy(strError, "Service was stopped.");
+ break;
+
+ };
+
+ return strError;
+}
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdaemon.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdaemon.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdaemon.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,761 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * pcscdaemon.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2005
+ * David Corcoran <corcoran at linuxnet.com>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: pcscdaemon.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This is the main pcscd daemon.
+ *
+ * The function \c main() starts up the communication environment.\n
+ * Then an endless loop is calld to look for Client connections. For each
+ * Client connection a call to \c CreateContextThread() is done.
+ */
+
+#include "config.h"
+#include <time.h>
+#include <syslog.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "debuglog.h"
+#include "winscard_msg.h"
+#include "winscard_svc.h"
+#include "sys_generic.h"
+#include "thread_generic.h"
+#include "hotplug.h"
+#include "readerfactory.h"
+#include "configfile.h"
+#include "powermgt_generic.h"
+
+#include <security_utilities/debugging.h>
+
+char AraKiri = 0;
+int respawn = 0;
+static char Init = 1;
+int HPForceReaderPolling = 0;
+
+char **globalArgv;
+
+/*
+ * Some internal functions
+ */
+void SVCServiceRunLoop(void);
+void SVCClientCleanup(psharedSegmentMsg);
+void at_exit(void);
+void clean_temp_files(void);
+void signal_reload(int sig);
+void signal_respawn(int sig);
+void signal_trap(int);
+void print_version (void);
+void print_usage (char const * const);
+int ProcessHotplugRequest();
+void tryRespawn();
+
+PCSCLITE_MUTEX usbNotifierMutex;
+
+#ifdef USE_RUN_PID
+pid_t GetDaemonPid(void);
+pid_t GetDaemonPid(void)
+{
+ FILE *f;
+ pid_t pid;
+
+ /* pids are only 15 bits but 4294967296
+ * (32 bits in case of a new system use it) is on 10 bytes
+ */
+ if ((f = fopen(USE_RUN_PID, "rb")) != NULL)
+ {
+#define PID_ASCII_SIZE 11
+ char pid_ascii[PID_ASCII_SIZE];
+
+ fgets(pid_ascii, PID_ASCII_SIZE, f);
+ fclose(f);
+
+ pid = atoi(pid_ascii);
+ }
+ else
+ {
+ Log2(PCSC_LOG_CRITICAL, "Can't open " USE_RUN_PID ": %s",
+ strerror(errno));
+ return -1;
+ }
+
+ return pid;
+} /* GetDaemonPid */
+#endif
+
+int SendHotplugSignal(void)
+{
+#ifdef USE_RUN_PID
+ pid_t pid;
+
+ pid = GetDaemonPid();
+
+ if (pid != -1)
+ {
+ Log2(PCSC_LOG_INFO, "Send hotplug signal to pcscd (pid=%d)", pid);
+ if (kill(pid, SIGUSR1) < 0)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Can't signal pcscd (pid=%d): %s",
+ pid, strerror(errno));
+ return EXIT_FAILURE ;
+ }
+ }
+#endif
+
+ return EXIT_SUCCESS;
+} /* SendHotplugSignal */
+
+int ProcessHotplugRequest()
+{
+#ifdef USE_RUN_PID
+
+ /* read the pid file to get the old pid and test if the old pcscd is
+ * still running
+ */
+ if (GetDaemonPid() != -1)
+ return SendHotplugSignal();
+
+ Log1(PCSC_LOG_CRITICAL, "file " USE_RUN_PID " does not exist");
+ Log1(PCSC_LOG_CRITICAL, "Perhaps pcscd is not running?");
+#else
+ struct stat tmpStat;
+ if (SYS_Stat(PCSCLITE_CSOCK_NAME, &tmpStat) == 0) // socket file exists, so maybe pcscd is running
+ return SendHotplugSignal();
+ Log1(PCSC_LOG_CRITICAL, "pcscd was not configured with --enable-runpid=FILE");
+#endif
+ Log1(PCSC_LOG_CRITICAL, "Hotplug failed");
+ return EXIT_FAILURE;
+}
+
+/*
+ * Cleans up messages still on the queue when a client dies
+ */
+void SVCClientCleanup(psharedSegmentMsg msgStruct)
+{
+ /*
+ * May be implemented in future releases
+ */
+}
+
+/**
+ * @brief The Server's Message Queue Listener function.
+ *
+ * An endless loop calls the function \c SHMProcessEventsServer() to check for
+ * messages sent by clients.
+ * If the message is valid, \c CreateContextThread() is called to serve this
+ * request.
+ */
+void SVCServiceRunLoop(void)
+{
+ int rsp;
+ LONG rv;
+ DWORD dwClientID; /* Connection ID used to reference the Client */
+
+ rsp = 0;
+ rv = 0;
+
+ /*
+ * Initialize the comm structure
+ */
+ rsp = SHMInitializeCommonSegment();
+
+ if (rsp == -1)
+ {
+ Log1(PCSC_LOG_CRITICAL, "Error initializing pcscd.");
+ exit(-1);
+ }
+
+ /*
+ * Initialize the contexts structure
+ */
+ rv = ContextsInitialize();
+
+ if (rv == -1)
+ {
+ Log1(PCSC_LOG_CRITICAL, "Error initializing pcscd.");
+ exit(-1);
+ }
+
+ /*
+ * Solaris sends a SIGALRM and it is annoying
+ */
+
+ signal(SIGALRM, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGHUP, SIG_IGN); /* needed for Solaris. The signal is sent
+ * when the shell is existed */
+
+ /*
+ * This function always returns zero
+ */
+ rsp = SYS_MutexInit(&usbNotifierMutex);
+
+ /*
+ * Set up the search for USB/PCMCIA devices
+ */
+ HPSearchHotPluggables();
+ HPRegisterForHotplugEvents();
+
+ /*
+ * Set up the power management callback routine
+ */
+// PMRegisterForPowerEvents();
+
+ while (1)
+ {
+ switch (rsp = SHMProcessEventsServer(&dwClientID, 0))
+ {
+
+ case 0:
+ Log2(PCSC_LOG_DEBUG, "A new context thread creation is requested: %d", dwClientID);
+ rv = CreateContextThread(&dwClientID);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log1(PCSC_LOG_ERROR, "Problem during the context thread creation");
+ AraKiri = 1;
+ }
+
+ break;
+
+ case 2:
+ /*
+ * timeout in SHMProcessEventsServer(): do nothing
+ * this is used to catch the Ctrl-C signal at some time when
+ * nothing else happens
+ */
+ break;
+
+ case -1:
+ Log1(PCSC_LOG_ERROR, "Error in SHMProcessEventsServer");
+ break;
+
+ case -2:
+ /* Nothing to do in case of a syscall interrupted
+ * It happens when SIGUSR1 (reload) or SIGINT (Ctrl-C) is received
+ * We just try again */
+ break;
+
+ default:
+ Log2(PCSC_LOG_ERROR, "SHMProcessEventsServer unknown retval: %d",
+ rsp);
+ break;
+ }
+
+ if (AraKiri)
+ {
+ /* stop the hotpug thread and waits its exit */
+ Log1(PCSC_LOG_ERROR, "Preparing to exit...");
+ HPStopHotPluggables();
+ SYS_Sleep(1);
+
+ /* now stop all the drivers */
+ int shouldExit = !respawn;
+ RFCleanupReaders(shouldExit);
+ }
+ if (respawn)
+ {
+ HPCancelHotPluggables();
+ HPJoinHotPluggables();
+ clean_temp_files();
+ tryRespawn();
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ int rv;
+ char setToForeground;
+ char HotPlug;
+ char *newReaderConfig;
+ struct stat fStatBuf;
+ int opt;
+#ifdef HAVE_GETOPT_LONG
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"config", 1, 0, 'c'},
+ {"foreground", 0, 0, 'f'},
+ {"help", 0, 0, 'h'},
+ {"version", 0, 0, 'v'},
+ {"apdu", 0, 0, 'a'},
+ {"debug", 0, 0, 'd'},
+ {"info", 0, 0, 0},
+ {"error", 0, 0, 'e'},
+ {"critical", 0, 0, 'C'},
+ {"hotplug", 0, 0, 'H'},
+ {"force-reader-polling", optional_argument, 0, 0},
+ {0, 0, 0, 0}
+ };
+#endif
+#define OPT_STRING "c:fdhvaeCH"
+
+ rv = 0;
+ newReaderConfig = NULL;
+ setToForeground = 0;
+ HotPlug = 0;
+ globalArgv = argv;
+
+ /*
+ * test the version
+ */
+ if (strcmp(PCSCLITE_VERSION_NUMBER, VERSION) != 0)
+ {
+ printf("BUILD ERROR: The release version number PCSCLITE_VERSION_NUMBER\n");
+ printf(" in pcsclite.h (%s) does not match the release version number\n",
+ PCSCLITE_VERSION_NUMBER);
+ printf(" generated in config.h (%s) (see configure.in).\n", VERSION);
+
+ return EXIT_FAILURE;
+ }
+
+ /*
+ * By default we create a daemon (not connected to any output)
+ * The log will go to wherever securityd log output goes.
+ */
+ DebugLogSetLogType(DEBUGLOG_NO_DEBUG);
+
+ /*
+ * Handle any command line arguments
+ */
+#ifdef HAVE_GETOPT_LONG
+ while ((opt = getopt_long (argc, argv, OPT_STRING, long_options, &option_index)) != -1) {
+#else
+ while ((opt = getopt (argc, argv, OPT_STRING)) != -1) {
+#endif
+ switch (opt) {
+#ifdef HAVE_GETOPT_LONG
+ case 0:
+ if (strcmp(long_options[option_index].name,
+ "force-reader-polling") == 0)
+ HPForceReaderPolling = optarg ? abs(atoi(optarg)) : 1;
+ break;
+#endif
+ case 'c':
+ Log2(PCSC_LOG_INFO, "using new config file: %s", optarg);
+ newReaderConfig = optarg;
+ break;
+
+ case 'f':
+ setToForeground = 1;
+ /* debug to stderr instead of default syslog */
+ Log1(PCSC_LOG_INFO,
+ "pcscd set to foreground with debug send to stderr");
+ break;
+
+ case 'd':
+ DebugLogSetLogType(DEBUGLOG_STDERR_DEBUG);
+ DebugLogSetLevel(PCSC_LOG_DEBUG);
+ break;
+
+ case 'e':
+ DebugLogSetLogType(DEBUGLOG_STDERR_DEBUG);
+ DebugLogSetLevel(PCSC_LOG_ERROR);
+ break;
+
+ case 'C':
+ DebugLogSetLogType(DEBUGLOG_STDERR_DEBUG);
+ DebugLogSetLevel(PCSC_LOG_CRITICAL);
+ break;
+
+ case 'h':
+ print_usage (argv[0]);
+ return EXIT_SUCCESS;
+
+ case 'v':
+ print_version ();
+ return EXIT_SUCCESS;
+
+ case 'a':
+ DebugLogSetCategory(DEBUG_CATEGORY_APDU);
+ break;
+
+ case 'H':
+ /* debug to stderr instead of default syslog */
+ DebugLogSetLogType(DEBUGLOG_STDERR_DEBUG);
+ HotPlug = 1;
+ break;
+
+ default:
+ print_usage (argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ }
+
+ if (argv[optind])
+ {
+ printf("Unknown option: %s\n\n", argv[optind]);
+ print_usage(argv[0]);
+ return EXIT_SUCCESS;
+ }
+
+ /*
+ If this run of pcscd has the hotplug option, just send a signal to the
+ running one and exit
+ */
+
+ if (HotPlug)
+ return ProcessHotplugRequest();
+
+ /*
+ * test the presence of /var/run/pcsc.comm
+ */
+
+ rv = SYS_Stat(PCSCLITE_CSOCK_NAME, &fStatBuf);
+
+ if (rv == 0)
+ {
+#ifdef USE_RUN_PID
+ pid_t pid;
+
+ /* read the pid file to get the old pid and test if the old pcscd is
+ * still running
+ */
+ pid = GetDaemonPid();
+
+ if (pid != -1)
+ {
+ if (kill(pid, 0) == 0)
+ {
+ Log2(PCSC_LOG_CRITICAL,
+ "Another pcscd (pid: %d) seems to be running.", pid);
+ Log1(PCSC_LOG_CRITICAL,
+ "Remove " USE_RUN_PID " if pcscd is not running to clear this message.");
+ return EXIT_FAILURE;
+ }
+ else
+ /* the old pcscd is dead. Do some cleanup */
+ clean_temp_files();
+ }
+#else
+ {
+ Log1(PCSC_LOG_CRITICAL,
+ "file " PCSCLITE_CSOCK_NAME " already exists.");
+ Log1(PCSC_LOG_CRITICAL,
+ "Maybe another pcscd is running?");
+ Log1(PCSC_LOG_CRITICAL,
+ "Remove " PCSCLITE_CSOCK_NAME "if pcscd is not running to clear this message.");
+ return EXIT_FAILURE;
+ }
+#endif
+ }
+
+ /*
+ * If this is set to one the user has asked it not to fork
+ */
+ if (!setToForeground)
+ {
+ if (SYS_Daemon(0, 0))
+ Log2(PCSC_LOG_CRITICAL, "SYS_Daemon() failed: %s",
+ strerror(errno));
+ }
+
+ /*
+ * cleanly remove /tmp/pcsc when exiting
+ */
+ signal(SIGQUIT, signal_trap);
+ signal(SIGTERM, signal_trap);
+ signal(SIGINT, signal_trap);
+ signal(SIGHUP, signal_trap);
+
+#ifdef USE_RUN_PID
+ /*
+ * Record our pid to make it easier
+ * to kill the correct pcscd
+ */
+ {
+ FILE *f;
+
+ if ((f = fopen(USE_RUN_PID, "wb")) != NULL)
+ {
+ fprintf(f, "%u\n", (unsigned) getpid());
+ fclose(f);
+ }
+ }
+#endif
+
+ /*
+ * If PCSCLITE_IPC_DIR does not exist then create it
+ */
+ rv = SYS_Stat(PCSCLITE_IPC_DIR, &fStatBuf);
+ if (rv < 0)
+ {
+ rv = SYS_Mkdir(PCSCLITE_IPC_DIR, S_ISVTX | S_IRWXO | S_IRWXG | S_IRWXU);
+ if (rv != 0)
+ {
+ Log2(PCSC_LOG_CRITICAL,
+ "cannot create " PCSCLITE_IPC_DIR ": %s", strerror(errno));
+ return EXIT_FAILURE;
+ }
+ }
+
+ /* cleanly remove /var/run/pcsc.* files when exiting */
+ if (atexit(at_exit))
+ Log2(PCSC_LOG_CRITICAL, "atexit() failed: %s", strerror(errno));
+
+ /*
+ * Allocate memory for reader structures
+ */
+ RFAllocateReaderSpace();
+
+ /*
+ Grab the information from the reader.conf. If a file has been specified
+ and there is any error, consider it fatal. If no file was explicitly
+ specified, ignore if file not present.
+
+ DBUpdateReaders returns:
+
+ 1 if config file can't be opened
+ -1 if config file is broken
+ 0 if all good
+
+ We skip this step if running in 64 bit mode, as serial readers are considered
+ legacy code.
+ */
+
+ rv = RFStartSerialReaders(newReaderConfig?newReaderConfig:PCSCLITE_READER_CONFIG);
+ if (rv == -1)
+ {
+ Log3(PCSC_LOG_CRITICAL, "invalid file %s: %s", newReaderConfig,
+ strerror(errno));
+ at_exit();
+ }
+ else
+ if ((rv == 1) && newReaderConfig)
+ {
+ Log3(PCSC_LOG_CRITICAL, "file %s can't be opened: %s",
+ newReaderConfig, strerror(errno));
+ at_exit();
+ }
+
+ /*
+ * Set the default globals
+ */
+ g_rgSCardT0Pci.dwProtocol = SCARD_PROTOCOL_T0;
+ g_rgSCardT1Pci.dwProtocol = SCARD_PROTOCOL_T1;
+ g_rgSCardRawPci.dwProtocol = SCARD_PROTOCOL_RAW;
+
+ Log1(PCSC_LOG_INFO, "pcsc-lite " VERSION " daemon ready.");
+
+ /*
+ * post initialistion
+ */
+ Init = 0;
+
+ /*
+ * signal_trap() does just set a global variable used by the main loop
+ */
+ signal(SIGQUIT, signal_trap);
+ signal(SIGTERM, signal_trap);
+ signal(SIGINT, signal_trap);
+ signal(SIGHUP, signal_trap);
+
+ signal(SIGUSR1, signal_reload);
+ signal(SIGUSR2, signal_respawn);
+
+ SVCServiceRunLoop();
+
+ Log1(PCSC_LOG_ERROR, "SVCServiceRunLoop returned");
+ return EXIT_FAILURE;
+}
+
+void at_exit(void)
+{
+ Log1(PCSC_LOG_INFO, "cleaning " PCSCLITE_IPC_DIR);
+
+ clean_temp_files();
+
+ SYS_Exit(EXIT_SUCCESS);
+}
+
+void clean_temp_files(void)
+{
+ int rv;
+
+ rv = SYS_Unlink(PCSCLITE_CSOCK_NAME);
+ if (rv != 0)
+ Log2(PCSC_LOG_ERROR, "Cannot unlink " PCSCLITE_CSOCK_NAME ": %s",
+ strerror(errno));
+
+#ifdef USE_RUN_PID
+ rv = SYS_Unlink(USE_RUN_PID);
+ if (rv != 0)
+ Log2(PCSC_LOG_ERROR, "Cannot unlink " USE_RUN_PID ": %s",
+ strerror(errno));
+#endif
+}
+
+void signal_reload(int sig)
+{
+ static int rescan_ongoing = 0;
+
+ if (AraKiri)
+ return;
+
+ Log1(PCSC_LOG_INFO, "Reload serial configuration");
+ if (rescan_ongoing)
+ {
+ Log1(PCSC_LOG_INFO, "Rescan already ongoing");
+ return;
+ }
+
+ rescan_ongoing = 0;
+
+ HPReCheckSerialReaders();
+
+ rescan_ongoing = 0;
+ Log1(PCSC_LOG_INFO, "End reload serial configuration");
+} /* signal_reload */
+
+void signal_trap(int sig)
+{
+ /* the signal handler is called several times for the same Ctrl-C */
+ if (AraKiri == 0)
+ {
+ Log1(PCSC_LOG_INFO, "Preparing for suicide");
+ AraKiri = 1;
+
+ /* if still in the init/loading phase the AraKiri will not be
+ * seen by the main event loop
+ */
+ if (Init)
+ {
+ Log1(PCSC_LOG_INFO, "Suicide during init");
+ at_exit();
+ }
+ }
+}
+
+void signal_respawn(int sig)
+{
+ Log1(PCSC_LOG_INFO, "Got signal to respawn in 32 bit mode");
+ AraKiri = 1;
+ respawn = 1;
+}
+
+#if MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
+ #include <spawn.h>
+ #include <err.h>
+ #include <CoreFoundation/CFBundle.h>
+ #include <CoreFoundation/CFNumber.h>
+#endif
+
+extern char **environ;
+
+void tryRespawn()
+{
+#if MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
+ /* now try respawn */
+ static cpu_type_t only32cpu[] = { CPU_TYPE_I386 };
+ const size_t only32cpuSize = (sizeof(only32cpu) / sizeof(cpu_type_t));
+
+ int rx;
+ posix_spawnattr_t attr;
+ if ((rx = posix_spawnattr_init(&attr)) != 0)
+ errc(1, rx, "posix_spawnattr_init");
+
+ if ((rx = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC)) != 0)
+ errc(1, rx, "posix_spawnattr_setflags");
+
+ size_t copied = 0;
+ if ((rx = posix_spawnattr_setbinpref_np(&attr, only32cpuSize, only32cpu, &copied)) != 0)
+ errc(1, rx, "posix_spawnattr_setbinpref_np");
+
+ if (copied != only32cpuSize)
+ errx(1, "posix_spawnattr_setbinpref_np only copied %d of %d", (int)copied, only32cpuSize);
+
+ pid_t pid = 0;
+ rx = posix_spawn(&pid, globalArgv[0], NULL, &attr, globalArgv, environ);
+ errc(1, rx, "posix_spawn: %s", globalArgv[0]);
+#else
+ /* we shouldn't get here, but if we do, we are in no state to continue */
+ Log1(PCSC_LOG_INFO, "Unexpected call to tryRespawn");
+ at_exit();
+#endif
+}
+
+void print_version (void)
+{
+ printf("%s version %s.\n", PACKAGE, VERSION);
+ printf("Copyright (C) 1999-2002 by David Corcoran <corcoran at linuxnet.com>.\n");
+ printf("Copyright (C) 2001-2005 by Ludovic Rousseau <ludovic.rousseau at free.fr>.\n");
+ printf("Copyright (C) 2003-2004 by Damien Sauveron <sauveron at labri.fr>.\n");
+ printf("Portions Copyright (C) 2000-2007 by Apple Inc.\n");
+ printf("Report bugs to <sclinux at linuxnet.com>.\n");
+}
+
+void print_usage (char const * const progname)
+{
+ printf("Usage: %s options\n", progname);
+ printf("Options:\n");
+#ifdef HAVE_GETOPT_LONG
+ printf(" -a, --apdu log APDU commands and results\n");
+ printf(" -c, --config path to reader.conf\n");
+ printf(" -f, --foreground run in foreground (no daemon),\n");
+ printf(" send logs to stderr instead of syslog\n");
+ printf(" -h, --help display usage information\n");
+ printf(" -H, --hotplug ask the daemon to rescan the available readers\n");
+ printf(" -v, --version display the program version number\n");
+ printf(" -d, --debug display lower level debug messages\n");
+ printf(" --info display info level debug messages (default level)\n");
+ printf(" -e --error display error level debug messages\n");
+ printf(" -C --critical display critical only level debug messages\n");
+ printf(" --force-reader-polling ignore the IFD_GENERATE_HOTPLUG reader capability\n");
+#else
+ printf(" -a log APDU commands and results\n");
+ printf(" -c path to reader.conf\n");
+ printf(" -f run in foreground (no daemon), send logs to stderr instead of syslog\n");
+ printf(" -d display debug messages. Output may be:\n");
+ printf(" -h display usage information\n");
+ printf(" -H ask the daemon to rescan the avaiable readers\n");
+ printf(" -v display the program version number\n");
+#endif
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1177 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+//
+// pcscmonitor - use PCSC to monitor smartcard reader/card state for securityd
+//
+// PCSCDMonitor is the "glue" between PCSC and the securityd objects representing
+// smartcard-related things. Its job is to manage the daemon and translate real-world
+// events (such as card and device insertions) into the securityd object web.
+//
+// PCSCDMonitor uses multiple inheritance to the hilt. It is (among others)
+// (*) A notification listener, to listen to pcscd state notifications
+// (*) A MachServer::Timer, to handle timed actions
+// (*) A NotificationPort::Receiver, to get IOKit notifications of device insertions
+//
+
+#include "pcscdmonitor.h"
+#include <security_utilities/logging.h>
+#include <security_utilities/refcount.h>
+#include <IOKit/usb/IOUSBLib.h>
+#include <IOKit/IOMessage.h>
+#include <asl.h>
+//#include <Kernel/IOKit/pccard/IOPCCardBridge.h>
+//#include <Kernel/IOKit/pccard/cs.h>
+
+#ifndef _IOKIT_IOPCCARDBRIDGE_H
+// Avoid kernel header include
+#define kIOPCCardVersionOneMatchKey "VersionOneInfo"
+#define kIOPCCardFunctionNameMatchKey "FunctionName"
+#define kIOPCCardFunctionIDMatchKey "FunctionID"
+#define kIOPCCardVendorIDMatchKey "VendorID"
+#define kIOPCCardDeviceIDMatchKey "DeviceID"
+#define kIOPCCardFunctionExtensionMatchKey "FunctionExtension"
+#define kIOPCCardMemoryDeviceNameMatchKey "MemoryDeviceName"
+
+// this should be unique across the entire system
+#define sub_iokit_pccard err_sub(21)
+#define kIOPCCardCSEventMessage iokit_family_msg(sub_iokit_pccard, 1)
+#endif /* _IOKIT_IOPCCARDBRIDGE_H */
+
+// _LINUX_CS_H
+#define CS_EVENT_CARD_INSERTION 0x000004
+#define CS_EVENT_CARD_REMOVAL 0x000008
+#define CS_EVENT_EJECTION_REQUEST 0x010000
+
+// Locally defined string constants for IOKit values
+
+#define kzIOUSBSerialNumberKey "Serial Number"
+#define kzIOUSBVendorNameKey "USB Vendor Name"
+#define kzIOUSBProductNameKey "USB Product Name"
+#define kzIOUSBLocationIDKey "locationID"
+#define kzIOUSBbInterfaceClassKey "bInterfaceClass"
+#define kzIOUSBbDeviceClassKey "bDeviceClass"
+
+#define kzIOPCCardIONameKey "IOName"
+#define kzIOPCCardIODeviceMemoryKey "IODeviceMemory"
+#define kzIOPCCardParentKey "parent"
+#define kzIOPCCardAddressKey "address"
+
+#define kzIOPCCard16DeviceClassName "IOPCCard16Device"
+
+#define PTRPARAMCAST(X) (static_cast<unsigned int>(reinterpret_cast<uintptr_t>(X)))
+
+//
+// Fixed configuration parameters
+//
+static const Time::Interval PCSCD_IDLE_SHUTDOWN(120); // kill daemon if no devices present
+
+// Apple built-in iSight Device VendorID/ProductID: 0x05AC/0x8501
+
+static const uint32_t kVendorProductMask = 0x0000FFFF;
+static const uint32_t kVendorIDApple = 0x05AC;
+static const uint16_t kProductIDBuiltInISight = 0x8501;
+
+/*
+ Copied from USBVideoClass-230.2.3/Digitizers/USBVDC/Camera/USBClient/APW_VDO_USBVDC_USBClient.h
+*/
+
+enum {
+ kBuiltIniSightProductID = 0x8501,
+ kBuiltIniSightWave2ProductID = 0x8502,
+ kBuiltIniSightWave3ProductID = 0x8505,
+ kUSBWave4ProductID = 0x8507,
+ kUSBWave2InK29ProductID = 0x8508,
+ kUSBWaveReserved1ProductID = 0x8509,
+ kUSBWaveReserved2ProductID = 0x850a,
+ kExternaliSightProductID = 0x1111,
+ kLogitechVendorID = 0x046d
+};
+
+//static void dumpdictentry(const void *key, const void *value, void *context);
+
+#pragma mark -------------------- Class Methods --------------------
+
+//
+// Construct a PCSCDMonitor.
+// We strongly assume there's only one of us around here.
+//
+// Note that this constructor may well run before the server loop has started.
+// Don't call anything here that requires an active server loop (like Server::active()).
+// In fact, you should push all the hard work into a timer, so as not to hold up the
+// general startup process.
+//
+
+PCSCDMonitor::PCSCDMonitor(PCSCD::Server &server, PCSCD::DriverBundles &drivers) :
+ MachPlusPlus::MachServer::Timer(true), // "heavy" timer task
+ server(server),
+ drivers(drivers),
+ mAddDeviceCallback(NULL), mRemoveDeviceCallback(NULL),
+ mWillSleepCallback(NULL), mIsWakingCallback(NULL),
+ mTimerAction(&PCSCDMonitor::initialSetup),
+ mGoingToSleep(false),
+ mTerminationNoticeReceiver(*this),
+ mSleepWakePeriod(false),
+ mWakeConditionVariable(mWakeConditionLock)
+{
+ // do all the smartcard-related work once the event loop has started
+ secdebug("pcsc", "PCSCDMonitor server is %p", &server);
+ server.setTimer(this, Time::now()); // ASAP
+ // timer only used now to call initialSetup
+ mDevices.erase(mDevices.begin(),mDevices.end());
+}
+
+//
+// Power event notifications
+//
+void PCSCDMonitor::systemWillSleep()
+{
+ StLock<Mutex> _(mLock);
+ secdebug("pcsc", "setting sleep marker (%ld readers as of now)", mDevices.size());
+ mGoingToSleep = true;
+ server.clearTimer(this);
+ if (mWillSleepCallback)
+ {
+ uint32_t rx = (*mWillSleepCallback)();
+ secdebug("pcsc", " WillSleepCallback returned %d", rx);
+ }
+ setSystemIsAwakeCondition(false);
+}
+
+void PCSCDMonitor::systemIsWaking()
+{
+ StLock<Mutex> _(mLock);
+ secdebug("pcsc", "------------------ Waking from sleep ... ------------------ ");
+ secdebug("pcsc", "clearing sleep marker (%ld readers as of now)", mDevices.size());
+ mGoingToSleep = false;
+ // rescan here
+ if (mIsWakingCallback)
+ {
+ uint32_t rx = (*mIsWakingCallback)();
+ secdebug("pcsc", " IsWakingCallback returned %d", rx);
+ }
+ setSystemIsAwakeCondition(true);
+}
+
+void PCSCDMonitor::setSystemIsAwakeCondition(bool isAwake)
+{
+ secdebug("pcsc", " setSystemIsAwakeCondition %d", isAwake);
+ if (isAwake)
+ {
+ sleepWakePeriod(false);
+ mWakeConditionVariable.broadcast();
+ }
+ else
+ sleepWakePeriod(true);
+}
+
+bool PCSCDMonitor::isSleepWakePeriod() const
+{
+ StLock<Mutex> _(mSleepWakePeriodLock);
+ return mSleepWakePeriod;
+}
+
+void PCSCDMonitor::sleepWakePeriod(bool isASleepWakePeriod)
+{
+ StLock<Mutex> _(mSleepWakePeriodLock);
+ mSleepWakePeriod = isASleepWakePeriod;
+}
+
+void PCSCDMonitor::systemAwakeAndReadyCheck()
+{
+// const long sleepTimeMSec = 100; // 0.1s
+
+ StLock<Mutex> _(mWakeConditionLock);
+ while (isSleepWakePeriod())
+ {
+ secdebug("pcsc", "...### thread paused before waking ###...");
+ mWakeConditionVariable.wait();
+ secdebug("pcsc", "...### thread resume after waking ###...");
+ }
+}
+
+void PCSCDMonitor::action()
+{
+ // Timer action
+ StLock<Mutex> _(mLock);
+ secdebug("pcsc", "Calling PCSCDMonitor::action()");
+ (this->*mTimerAction)();
+ mTimerAction = &PCSCDMonitor::noDeviceTimeout;
+}
+
+void PCSCDMonitor::scheduleTimer(bool enable)
+{
+ // Update the timeout timer as requested (and indicated by context)
+}
+
+//
+// Perform the initial PCSC subsystem initialization.
+// This runs (shortly) after securityd is fully functional and the
+// server loop has started.
+//
+void PCSCDMonitor::initialSetup()
+{
+ secdebug("pcsc", "Calling PCSCDMonitor::initialSetup()");
+ // receive Mach-based IOKit notifications through mIOKitNotifier
+ server.add(mIOKitNotifier);
+
+ // receive power event notifications (through our IOPowerWatcher personality)
+ server.add(this);
+
+ AddIOKitNotifications();
+
+ PCSCDMonitor::postNotification(SecurityServer::kNotificationPCSCInitialized);
+}
+
+void PCSCDMonitor::AddIOKitNotifications()
+{
+ try
+ {
+ // ask for IOKit notifications for all new USB devices and process present ones
+ IOKit::DeviceMatch usbSelector(kIOUSBInterfaceClassName);
+ IOKit::DeviceMatch pcCardSelector(kzIOPCCard16DeviceClassName);
+ mIOKitNotifier.add(usbSelector, *this, kIOMatchedNotification); // this will scan existing USB devices
+ // mIOKitNotifier.add(usbSelector, mTerminationNoticeReceiver, kIOTerminatedNotification); // ditto for PC Card devices
+ mIOKitNotifier.add(pcCardSelector, *this, kIOMatchedNotification); // ditto for PC Card devices
+ mIOKitNotifier.add(pcCardSelector, mTerminationNoticeReceiver, kIOTerminatedNotification); // ditto for PC Card devices
+
+ // catch custom non-composite USB devices - they don't have IOServices attached
+ IOKit::DeviceMatch customUsbSelector(::IOServiceMatching(kIOUSBDeviceClassName));
+ mIOKitNotifier.add(customUsbSelector, *this, kIOMatchedNotification); // ditto for custom USB devices
+ // mIOKitNotifier.add(customUsbSelector, mTerminationNoticeReceiver, kIOTerminatedNotification);
+ }
+ catch (...)
+ {
+ secdebug("pcscd", "trouble adding IOKit notifications (ignored)");
+ }
+}
+
+void PCSCDMonitor::RemoveIOKitNotifications()
+{
+}
+
+
+void PCSCDMonitor::rescanExistingDevices()
+{
+ kern_return_t kr;
+ mach_port_t masterPort = ((IOKit::NotificationPort)mIOKitNotifier).port();
+// mach_port_t masterPort = port();
+ io_iterator_t iterator;
+
+ // Process existing USB devices
+ IOKit::DeviceMatch usbSelector(kIOUSBInterfaceClassName);
+ kr = IOServiceGetMatchingServices(masterPort, usbSelector, &iterator);
+ IOKit::DeviceIterator usbdev(iterator);
+ ioChange(usbdev);
+
+ // Process existing PC Card devices
+ IOKit::DeviceMatch pcCardSelector(kzIOPCCard16DeviceClassName);
+ kr = IOServiceGetMatchingServices(masterPort, pcCardSelector, &iterator);
+ IOKit::DeviceIterator pcdev(iterator);
+ ioChange(pcdev);
+
+ // catch custom non-composite USB devices - they don't have IOServices attached
+ IOKit::DeviceMatch customUsbSelector(::IOServiceMatching(kIOUSBDeviceClassName));
+ kr = IOServiceGetMatchingServices(masterPort, customUsbSelector, &iterator);
+ IOKit::DeviceIterator customusbdev(iterator);
+ ioChange(customusbdev);
+}
+
+void PCSCDMonitor::postNotification(const SecurityServer::NotificationEvent event)
+{
+ // send a change notification to securityd
+ // Either kNotificationPCSCStateChange or kNotificationPCSCInitialized
+ using namespace SecurityServer;
+ ClientSession session(Allocator::standard(), Allocator::standard());
+ try {
+ session.postNotification(kNotificationDomainPCSC, event, CssmData());
+ secdebug("pcscd", "notification sent");
+ } catch (const MachPlusPlus::Error &err) {
+ switch (err.error) {
+ case BOOTSTRAP_UNKNOWN_SERVICE: // securityd not yet available; this is not an error
+ secdebug("pcscd", "securityd not up; no notification sent");
+ break;
+#if !defined(NDEBUG)
+ // for debugging only, support a securityd restart. This is NOT thread-safe
+ case MACH_SEND_INVALID_DEST:
+ secdebug("pcscd", "resetting securityd connection for debugging");
+ session.reset();
+ try {
+ session.postNotification(kNotificationDomainPCSC,
+ kNotificationPCSCStateChange, CssmData());
+ } catch (...) {
+ secdebug("pcscd", "re-send attempt failed, punting");
+ }
+ break;
+#endif //NDEBUG
+ default:
+ secdebug("pcscd", "exception trying to send notification (ignored)");
+ }
+ } catch (...) {
+ secdebug("pcscd", "trouble sending security notification (ignored)");
+ }
+}
+
+//
+// This function is called (as a timer function) when there haven't been any (recognized)
+// smartcard devicees in the system for a while.
+//
+void PCSCDMonitor::noDeviceTimeout()
+{
+ secdebug("pcsc", "killing pcscd (no smartcard devices present for %g seconds)",
+ PCSCD_IDLE_SHUTDOWN.seconds());
+}
+
+void PCSCDMonitor::addInterestNotification()
+{
+ secdebug("pcsc", "Adding interest notification for service 0x%04X (this=%p)", mServiceOfInterest,this);
+ mIOKitNotifier.addInterestNotification(*this, mServiceOfInterest);
+}
+
+void PCSCDMonitor::scheduleAddInterestNotification(io_service_t serviceOfInterest)
+{
+ StLock<Mutex> _(mLock);
+ secdebug("pcsc", "Scheduling interest notification for service 0x%04X (this=%p)", serviceOfInterest, this);
+ mServiceOfInterest = serviceOfInterest;
+ mTimerAction = &PCSCDMonitor::addInterestNotification;
+ server.setTimer(this, Time::now()); // ASAP
+}
+
+//
+// IOKit device event notification.
+// Here we listen for newly inserted devices
+//
+void PCSCDMonitor::ioChange(IOKit::DeviceIterator &iterator)
+{
+ secdebug("pcsc", "Processing device event notification");
+ int def=0, pos=0, total=0;
+ // Always drain this iterator
+ while (IOKit::Device dev = iterator())
+ {
+ ++total;
+ displayPropertiesOfDevice(dev);
+ switch (deviceSupport(dev))
+ {
+ case definite:
+ ++def;
+ addDevice(dev);
+ break;
+ case possible:
+ ++pos;
+ addDevice(dev);
+ break;
+ case impossible:
+ break;
+ }
+ }
+
+ dumpDevices();
+ secdebug("pcsc", "Relevant devices: %d definite, %d possible, %d total", def, pos, total);
+}
+
+// IOKit device event notification.
+// Here we listen for newly removed devices
+//
+void PCSCDMonitor::ioServiceChange(void *refCon, io_service_t service,
+ natural_t messageType, void *messageArgument)
+{
+ uintptr_t messageArg = uintptr_t(messageArgument);
+ secdebug("pcsc", "Processing ioServiceChange notice: 0x%08X [refCon=0x%08lX, service=0x%08X, arg=0x%08lX]",
+ messageType, (uintptr_t)refCon, service, messageArg);
+
+ if (mGoingToSleep && isSleepWakePeriod()) // waking up but still drowsy
+ {
+ secdebug("pcsc", " ignoring ioServiceChange notice during wake up phase");
+ return;
+ }
+
+ PCSCDMonitor::displayPropertiesOfDevice(service);
+ // This is called since we asked for kIOGeneralInterest notices
+ // Usually it is the "device removed" notification
+ switch (messageType)
+ {
+ case kIOMessageServiceIsTerminated: // We get these when device is removed
+ {
+ uint32_t address;
+ if (deviceAddress(service, address))
+ {
+ secdebug("pcsc", " device removed notice: 0x%04X address: 0x%08X", service, address);
+ this->removeDevice(service, address);
+ }
+ else
+ secdebug("pcsc", " device removed notice, but failed to find address for service: 0x%04X", service);
+ }
+ break;
+ case kIOMessageServiceWasClosed: // We get these when the system sleeps
+ {
+#ifndef NDEBUG
+ uint32_t address;
+ deviceAddress(service, address);
+ secdebug("pcsc", " service was closed notice: 0x%04X address: 0x%08X", service, address);
+#endif
+ }
+ break;
+ case kIOPCCardCSEventMessage: // 0xE0054001 - not handled by mach_error_string
+ secdebug("pcsc", " pccard event message: service: 0x%04X, type: 0x%08X",
+ service, (unsigned int)messageArg);
+ // Card Services Events are defined in IOKit/pccard/cs.h
+ switch (messageArg)
+ {
+ case CS_EVENT_EJECTION_REQUEST:
+ secdebug("pcsc", " pccard event message: ejection request");
+ break;
+
+ case CS_EVENT_CARD_REMOVAL:
+ {
+ uint32_t address;
+ if (deviceMemoryAddress(service, address))
+ {
+ secdebug("pcsc", " device removed notice: 0x%04X address: 0x%08X", service, address);
+ this->removeDevice(service, address);
+ }
+ else
+ secdebug("pcsc", " device removed notice, but failed to find address for service: 0x%04X", service);
+ break;
+ }
+ }
+ break;
+ default:
+ secdebug("pcsc", " processing device general notice: 0x%08X", messageType);
+ break;
+ }
+}
+
+void PCSCDMonitor::addDevice(const IOKit::Device &dev)
+{
+ DeviceMap::iterator it;
+ if (!findDevice(dev,it)) // new device
+ {
+ io_service_t service = dev.ioObject();
+
+ RefPointer<PCSCD::Device> newDevice = new PCSCD::Device(service);
+ uint32_t address = 0;
+
+ if (deviceAddress(dev, address))
+ {
+ newDevice->setAddress(address);
+ secdebug("scsel", " Device address: 0x%08X [service: 0x%04X]", address, service);
+ setDeviceProperties(dev, *newDevice);
+ if (drivers.find(*newDevice))
+ {
+ secdebug("driver", " found matching driver for %s: %s", newDevice->name().c_str(), newDevice->path().c_str());
+ setDebugPropertiesForDevice(dev, newDevice);
+ insert(make_pair(address, newDevice));
+ if (mAddDeviceCallback)
+ {
+ // kPCSCLITE_HP_BASE_PORT
+ uint32_t rx = (*mAddDeviceCallback)(newDevice->name().c_str(), address, newDevice->path().c_str(), newDevice->name().c_str());
+ secdebug("pcsc", " AddDeviceCallback returned %d", rx);
+ if (rx != SCARD_S_SUCCESS && rx != SCARD_E_DUPLICATE_READER)
+ {
+ DeviceMap::iterator it = mDevices.find(address);
+ if (it != mDevices.end()) // found it
+ remove(it); // remove from reader map
+ return;
+ }
+ }
+ PCSCDMonitor::postNotification(SecurityServer::kNotificationPCSCStateChange);
+ secdebug("pcsc", " added to device map, address: 0x%08X, service: 0x%04X, [class @:%p]", address, service, newDevice.get());
+ }
+ else
+ {
+ secdebug("driver", " no matching driver found for %s: %s", newDevice->name().c_str(), newDevice->path().c_str());
+ // Add MessageTracer logging as per <rdar://problem/6432650>. If we get here, pcscd was launched
+ // for a device insertion, but the device is not a smartcard reader (or doesn't have a
+ // matching driver.
+ char buf[256];
+ aslmsg msg = asl_new(ASL_TYPE_MSG);
+ asl_set(msg, "com.apple.message.domain", "com.apple.security.smartcardservices.unknowndevice" );
+ asl_set(msg, "com.apple.message.signature", "Non-smartcard device launched pcscd");
+ snprintf(buf, sizeof(buf), "%u", newDevice->vendorid());
+ asl_set(msg, "com.apple.message.signature2", buf); // vendor ID
+ snprintf(buf, sizeof(buf), "%u", newDevice->productid());
+ asl_set(msg, "com.apple.message.signature3", buf); // product ID
+ snprintf(buf, sizeof(buf), "Non-smartcard device launched pcscd [Vendor: %#X, Product: %#X]",
+ newDevice->vendorid(), newDevice->productid());
+ asl_log(NULL, msg, ASL_LEVEL_NOTICE, buf);
+ asl_free(msg);
+ }
+ }
+ else
+ secdebug("pcsc", " device added notice, but failed to find address for service: 0x%04X", service);
+ }
+ else
+ {
+ PCSCD::Device *theDevice = static_cast<PCSCD::Device *>(it->second);
+ secdebug("scsel", " Already in map: Device address: 0x%08X [service: 0x%04X]",
+ theDevice->address(), dev.ioObject());
+ setDeviceProperties(dev, *theDevice);
+ setDebugPropertiesForDevice(dev, theDevice);
+ }
+
+ // We always try to add the interest notification. It may be that
+ // we added the device during a callback for a particular plane,
+ // but we didn't have the right information then to add the notification
+ io_service_t servicex = dev.ioObject();
+ mIOKitNotifier.addInterestNotification(*this, servicex);
+ dumpDevices();
+}
+
+bool PCSCDMonitor::findDevice(const IOKit::Device &dev, DeviceMap::iterator &it)
+{
+ uint32_t address = 0;
+ deviceAddress(dev, address);
+ it = mDevices.find(address);
+ return (it != mDevices.end());
+}
+
+bool PCSCDMonitor::findDeviceByName(const IOKit::Device &dev, DeviceMap::iterator &outit)
+{
+ CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey);
+ if (!ioName)
+ return false;
+
+ std::string devname = cfString(ioName);
+ for (DeviceMap::iterator it = mDevices.begin(); it != mDevices.end(); ++it)
+ {
+ PCSCD::Device *theDevice = static_cast<PCSCD::Device *>(it->second);
+ if (theDevice->name() == devname)
+ {
+ outit = it;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void PCSCDMonitor::updateDevice(const IOKit::Device &dev)
+{
+ DeviceMap::iterator it;
+ if (findDevice(dev,it))
+ {
+ PCSCD::Device *theDevice = static_cast<PCSCD::Device *>(it->second);
+ setDeviceProperties(dev, *theDevice);
+ if (drivers.find(*theDevice))
+ secdebug("driver", " found matching driver for %s: %s", theDevice->name().c_str(), theDevice->path().c_str());
+ setDebugPropertiesForDevice(dev, theDevice);
+ }
+}
+
+bool PCSCDMonitor::hasLegacyDriver(const IOKit::Device &dev)
+{
+ PCSCD::Device tmpDevice(0); //dev.ioObject() - fake it
+ uint32_t address = 0;
+ if (deviceAddress(dev, address))
+ tmpDevice.setAddress(address);
+ setDeviceProperties(dev, tmpDevice);
+ if (drivers.find(tmpDevice))
+ {
+ secdebug("driver", " found matching driver for legacy device: %s", tmpDevice.path().c_str());
+ return true;
+ }
+
+ return false;
+}
+
+bool PCSCDMonitor::deviceIsPCCard(const IOKit::Device &dev)
+{
+ if (CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey))
+ if (cfString(ioName).find("pccard", 0, 1) == 0)
+ return true;
+
+ return false;
+}
+
+bool PCSCDMonitor::deviceIsPCCard(io_service_t service)
+{
+ if (CFRef<CFStringRef> ioName = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOPCCardIONameKey), kCFAllocatorDefault, 0)))
+ if (cfString(ioName).find("pccard", 0, 1) == 0)
+ return true;
+
+ return false;
+}
+
+void PCSCDMonitor::getVendorAndProductID(const IOKit::Device &dev, uint32_t &vendorID, uint32_t &productID, bool &isPCCard)
+{
+ vendorID = productID = 0;
+ isPCCard = deviceIsPCCard(dev);
+
+ if (!isPCCard)
+ {
+ if (CFRef<CFNumberRef> cfVendorID = dev.property<CFNumberRef>(kUSBVendorID))
+ vendorID = cfNumber(cfVendorID);
+
+ if (CFRef<CFNumberRef> cfProductID = dev.property<CFNumberRef>(kUSBProductID))
+ productID = cfNumber(cfProductID);
+ }
+ else
+ {
+ if (CFRef<CFNumberRef> cfVendorID = dev.property<CFNumberRef>(kIOPCCardVendorIDMatchKey))
+ vendorID = cfNumber(cfVendorID);
+
+ if (CFRef<CFNumberRef> cfProductID = dev.property<CFNumberRef>(kIOPCCardDeviceIDMatchKey))
+ productID = cfNumber(cfProductID);
+
+ // One special case for legacy OmniKey CardMan 4040 support
+ CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey);
+ if (ioName && CFEqual(ioName, CFSTR("pccard-no-cis")))
+ {
+ vendorID = 0x0223;
+ productID = 0x0200;
+ }
+ }
+}
+
+void PCSCDMonitor::setDeviceProperties(const IOKit::Device &dev, PCSCD::Device &device)
+{
+ uint32_t vendorID, productID;
+ bool isPCCard;
+
+ getVendorAndProductID(dev, vendorID, productID, isPCCard);
+
+ device.setIsPCCard(isPCCard);
+
+ if (CFRef<CFNumberRef> cfInterface = dev.property<CFNumberRef>(kzIOUSBbInterfaceClassKey))
+ device.setInterfaceClass(cfNumber(cfInterface));
+
+ if (CFRef<CFNumberRef> cfDevice = dev.property<CFNumberRef>(kzIOUSBbDeviceClassKey))
+ device.setDeviceClass(cfNumber(cfDevice));
+
+ device.setVendorid(vendorID);
+ device.setProductid(productID);
+
+ if (CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey))
+ device.setName(cfString(ioName));
+}
+
+bool PCSCDMonitor::isExcludedDevice(const IOKit::Device &dev)
+{
+ uint32_t vendorID, productID;
+ bool isPCCard;
+
+ getVendorAndProductID(dev, vendorID, productID, isPCCard);
+
+ if ((vendorID & kVendorProductMask) != kVendorIDApple)
+ return false; // i.e. it is not an excluded device
+
+ // Since Apple does not manufacture smartcard readers, just exclude
+ // If we even start making them, we should make it a CCID reader anyway
+
+ return true;
+}
+
+void PCSCDMonitor::setDebugPropertiesForDevice(const IOKit::Device &dev, PCSCD::Device * newDevice)
+{
+ /*
+ Many of these properties are only defined on the "IOUSBDevice" plane, so
+ will be non-empty on the third iteration.
+ */
+ std::string vendorName, productName, serialNumber;
+
+ if (CFRef<CFStringRef> cfVendorString = dev.property<CFStringRef>(kzIOUSBVendorNameKey))
+ vendorName = cfString(cfVendorString);
+
+ if (CFRef<CFStringRef> cfProductString = dev.property<CFStringRef>(kzIOUSBProductNameKey))
+ productName = cfString(cfProductString);
+
+ if (CFRef<CFStringRef> cfSerialString = dev.property<CFStringRef>(kzIOUSBSerialNumberKey))
+ serialNumber = cfString(cfSerialString);
+
+ if (deviceIsPCCard(dev))
+ {
+ if (CFRef<CFArrayRef> cfVersionOne = dev.property<CFArrayRef>(kIOPCCardVersionOneMatchKey))
+ if (CFArrayGetCount(cfVersionOne) > 1)
+ {
+ CFStringRef cfVendorString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 0);
+ if (cfVendorString)
+ vendorName = cfString(cfVendorString);
+
+ CFStringRef cfProductString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 1);
+ if (cfProductString)
+ productName = cfString(cfProductString);
+ }
+ }
+
+ newDevice->setDebugParams(vendorName, productName, serialNumber);
+
+// secdebug("scsel", " deviceSupport: vendor/product: 0x%04X/0x%04X, vendor: %s, product: %s, serial: %s", vendorid, productid,
+// vendorName.c_str(), productName.c_str(), serialNumber.c_str());
+}
+
+void PCSCDMonitor::removeDevice(io_service_t service, uint32_t address)
+{
+ secdebug("pcsc", " Size of mDevices: %ld, service: 0x%04X", mDevices.size(), service);
+ if (!mDevices.empty())
+ {
+ secdebug("pcsc", " device removed notice: 0x%04X address: 0x%08X", service, address);
+ DeviceMap::iterator it = mDevices.find(address);
+ if (it != mDevices.end()) // found it
+ {
+ if (mRemoveDeviceCallback)
+ {
+ uint32_t rx = (*mRemoveDeviceCallback)((it->second)->name().c_str(), address);
+ secdebug("pcsc", " RemoveDeviceCallback returned %d", rx);
+ }
+ remove(it); // remove from reader map
+ }
+ else
+ secdebug("pcsc", " service: 0x%04X at address 0x%04X not found ??", service, address);
+ }
+ dumpDevices();
+ ::IOObjectRelease(service); // we don't want notifications here until re-added
+}
+
+void PCSCDMonitor::removeDeviceByName(const IOKit::Device &dev)
+{
+ io_service_t service = dev.ioObject();
+ secdebug("pcsc", " Size of mDevices: %ld, service: 0x%04X", mDevices.size(), service);
+ if (!mDevices.empty())
+ {
+ uint32_t address = 0;
+ deviceAddress(dev, address);
+ DeviceMap::iterator it;
+ if (findDeviceByName(dev, it)) // found it
+ {
+ if (mRemoveDeviceCallback)
+ {
+ uint32_t rx = (*mRemoveDeviceCallback)((it->second)->name().c_str(), address);
+ secdebug("pcsc", " RemoveDeviceCallback returned %d", rx);
+ }
+ remove(it); // remove from reader map
+ }
+ else
+ secdebug("pcsc", " service: 0x%04X at address 0x%04X not found ??", service, address);
+ }
+ dumpDevices();
+ ::IOObjectRelease(service); // we don't want notifications here until re-added
+}
+
+void PCSCDMonitor::removeAllDevices()
+{
+ secdebug("pcsc", ">>>>>> removeAllDevices: Size of mDevices: %ld", mDevices.size());
+ for (DeviceMap::iterator it = mDevices.begin(); it != mDevices.end(); ++it)
+ {
+ PCSCD::Device *dev = static_cast<PCSCD::Device *>(it->second);
+ uint32_t address = 0;
+ // PCSCDMonitor::deviceAddress(*dev, &address);
+ address = dev->address();
+ io_service_t service = dev->ioObject();
+ if (mRemoveDeviceCallback)
+ {
+ uint32_t rx = (*mRemoveDeviceCallback)(dev->name().c_str(), address);
+ secdebug("pcsc", " RemoveDeviceCallback returned %d", rx);
+ }
+ ::IOObjectRelease(service); // we don't want notifications here until re-added
+ remove(it); // remove from reader map
+ }
+ secdebug("pcsc", ">>>>>> removeAllDevices [end]: Size of mDevices: %ld", mDevices.size());
+}
+
+
+//
+// Check an IOKit device that's just come online to see if it's
+// a smartcard device of some sort.
+//
+PCSCDMonitor::DeviceSupport PCSCDMonitor::deviceSupport(const IOKit::Device &dev)
+{
+#ifndef NDEBUG
+ try
+ {
+ secdebug("scsel", "path: %s", dev.path().c_str()); // this can fail sometimes
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception while displaying device path - ignoring error");
+ }
+#endif
+
+ try
+ {
+ // composite USB device with interface class
+ if (CFRef<CFNumberRef> cfInterface = dev.property<CFNumberRef>(kzIOUSBbInterfaceClassKey))
+ switch (uint32_t clas = cfNumber(cfInterface))
+ {
+ case kUSBChipSmartCardInterfaceClass: // CCID smartcard reader - go
+ secdebug("scsel", " CCID smartcard reader recognized");
+ return definite;
+ case kUSBVendorSpecificInterfaceClass:
+ if (isExcludedDevice(dev))
+ {
+ secdebug("scsel", " interface class %d is not a smartcard device (excluded)", clas);
+ return impossible;
+ }
+ secdebug("scsel", " Vendor-specific interface - possible match");
+ return possible;
+ default:
+ if ((clas == 0) && hasLegacyDriver(dev))
+ {
+ secdebug("scsel", " Vendor-specific legacy driver - possible match");
+ return possible;
+ }
+ secdebug("scsel", " interface class %d is not a smartcard device", clas);
+ return impossible;
+ }
+
+ // noncomposite USB device
+ if (CFRef<CFNumberRef> cfDevice = dev.property<CFNumberRef>(kzIOUSBbDeviceClassKey))
+ if (cfNumber(cfDevice) == kUSBVendorSpecificClass)
+ {
+ if (isExcludedDevice(dev))
+ {
+ secdebug("scsel", " device class %d is not a smartcard device (excluded)", cfNumber(cfDevice));
+ return impossible;
+ }
+ secdebug("scsel", " Vendor-specific device - possible match");
+ return possible;
+ }
+
+ // PCCard (aka PCMCIA aka ...) interface (don't know how to recognize a reader here)
+ if (deviceIsPCCard(dev))
+ {
+ secdebug("scsel", " PCCard - possible match");
+ return possible;
+ }
+
+ return impossible;
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception while examining device - ignoring it");
+ return impossible;
+ }
+}
+
+#pragma mark -------------------- Static Methods --------------------
+
+bool PCSCDMonitor::deviceAddress(io_service_t service, uint32_t &address)
+{
+ if (CFRef<CFNumberRef> cfLocationID = static_cast<CFNumberRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOUSBLocationIDKey), kCFAllocatorDefault, 0)))
+ {
+ address = cfNumber(cfLocationID);
+ return true;
+ }
+
+ // don't bother to test if it is a pc card, just try looking
+ return deviceMemoryAddress(service, address);
+}
+
+bool PCSCDMonitor::deviceAddress(const IOKit::Device &dev, uint32_t &address)
+{
+ if (CFRef<CFNumberRef> cfLocationID = dev.property<CFNumberRef>(kzIOUSBLocationIDKey))
+ {
+ address = cfNumber(cfLocationID);
+ return true;
+ }
+
+ // don't bother to test if it is a pc card, just try looking
+ return deviceMemoryAddress(dev, address);
+}
+
+bool PCSCDMonitor::deviceMemoryAddress(const IOKit::Device &dev, uint32_t &address)
+{
+// CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey);
+ CFRef<CFArrayRef> cfDeviceMemory = dev.property<CFArrayRef>(kzIOPCCardIODeviceMemoryKey);
+ return deviceMemoryAddressCore(cfDeviceMemory, dev.path(), address);
+}
+
+bool PCSCDMonitor::deviceMemoryAddress(io_service_t service, uint32_t &address)
+{
+// CFRef<CFStringRef> ioName = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+// service, CFSTR(kzIOPCCardIONameKey), kCFAllocatorDefault, 0));
+ CFRef<CFArrayRef> cfDeviceMemory = static_cast<CFArrayRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOPCCardIODeviceMemoryKey), kCFAllocatorDefault, 0));
+ return deviceMemoryAddressCore(cfDeviceMemory, "", address);
+}
+
+bool PCSCDMonitor::deviceMemoryAddressCore(CFArrayRef cfDeviceMemory, std::string path, uint32_t &address)
+{
+ address = 0;
+ try
+ {
+ if (cfDeviceMemory)
+ {
+ if (CFRef<CFDictionaryRef> cfTempMem = (CFDictionaryRef)CFRetain(CFArrayGetValueAtIndex(cfDeviceMemory, 0)))
+ {
+ // CFDictionaryApplyFunction(cfTempMem, dumpdictentry, NULL);
+ if (CFRef<CFArrayRef> cfParent = (CFArrayRef)CFRetain(CFDictionaryGetValue(cfTempMem, CFSTR(kzIOPCCardParentKey))))
+ if (CFRef<CFDictionaryRef> cfTempMem2 = (CFDictionaryRef)CFRetain(CFArrayGetValueAtIndex(cfParent, 0)))
+ if (CFRef<CFNumberRef> cfAddress = (CFNumberRef)CFRetain(CFDictionaryGetValue((CFDictionaryRef)cfTempMem2, CFSTR(kzIOPCCardAddressKey))))
+ {
+ address = cfNumber(cfAddress);
+ secdebug("scsel", " address from device memory address property: 0x%08X", address);
+ return true;
+ }
+ }
+ }
+ else
+ if (!path.empty())
+ {
+ // std::string name = cfString(ioName);
+ // address = CFHash (ioName);
+ // address = 0xF2000000;
+ addressFromPath(path, address);
+ secdebug("scsel", " extracted address: 0x%08X for device [%s]", address, path.c_str());
+ return true;
+ }
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception while examining deviceMemoryAddress property");
+ }
+ return false;
+}
+
+bool PCSCDMonitor::addressFromPath(std::string path, uint32_t &address)
+{
+ /*
+ Try to extract the address from the path if the other keys are not present.
+ An example path is:
+
+ IOService:/MacRISC2PE/pci at f2000000/AppleMacRiscPCI/cardbus at 13/IOPCCardBridge/pccard2bd,1003 at 0,0
+
+ where e.g. the address is f2000000, the vendor is 0x2bd, and the product id is 0x1003
+ */
+ address = 0;
+ #define HEX_TO_INT(x) ((x) >= '0' &&(x) <= '9' ? (x) - '0' : (x) - ('a' - 10))
+
+ try
+ {
+ secdebug("scsel", "path: %s", path.c_str()); // this can fail sometimes
+
+ std::string lhs("/pci@");
+ std::string rhs("/");
+
+ std::string::size_type start = path.find(lhs)+lhs.length();
+ std::string::size_type end = path.find(rhs, start);
+
+ std::string addressString(path, start, end-start);
+
+ // now addressString should contain something like f2000000
+ uint32_t tmp = 0;
+ const char *px = addressString.c_str();
+ size_t len = strlen(px);
+ for (unsigned int ix=0;ix<len;ix++,px++)
+ {
+ tmp<<=4;
+ tmp += HEX_TO_INT(*px);
+ }
+
+ address = tmp;
+
+ secdebug("scsel", " address 0x%08X extracted from path", address);
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception while displaying device path - ignoring error");
+ return false;
+ }
+
+ return true;
+}
+
+#pragma mark -------------------- Termination Notice Receiver --------------------
+
+TerminationNoticeReceiver::~TerminationNoticeReceiver()
+{
+}
+
+void TerminationNoticeReceiver::ioChange(IOKit::DeviceIterator &iterator)
+{
+ secdebug("pcsc", "[TerminationNoticeReceiver] Processing ioChange notification");
+ // Always drain this iterator
+ while (IOKit::Device dev = iterator())
+ {
+ PCSCDMonitor::displayPropertiesOfDevice(dev);
+ parent().removeDeviceByName(dev);
+ }
+}
+
+void TerminationNoticeReceiver::ioServiceChange(void *refCon, io_service_t service,
+ natural_t messageType, void *messageArgument)
+{
+ uintptr_t messageArg = uintptr_t(messageArgument);
+ secdebug("pcsc", " [TerminationNoticeReceiver] processing ioServiceChange notice: 0x%08X [refCon=0x%08lX, service=0x%08X, arg=0x%08lX]",
+ messageType, (uintptr_t)refCon, service, messageArg);
+ parent().ioServiceChange(refCon, service, messageType, messageArgument);
+}
+
+#pragma mark -------------------- Debug Routines --------------------
+
+void PCSCDMonitor::displayPropertiesOfDevice(const IOKit::Device &dev)
+{
+ /*
+ Many of these properties are only defined on the "IOUSBDevice" plane, so
+ will be non-empty on the third iteration.
+ */
+ try
+ {
+ std::string vendorName, productName, serialNumber, name;
+
+ uint32_t vendorID, productID;
+ bool isPCCard;
+
+ CFRef<CFStringRef> ioName = dev.property<CFStringRef>(kzIOPCCardIONameKey);
+ if (ioName)
+ name = cfString(ioName);
+
+ getVendorAndProductID(dev, vendorID, productID, isPCCard);
+
+ if (CFRef<CFStringRef> cfSerialString = dev.property<CFStringRef>(kzIOUSBSerialNumberKey))
+ serialNumber = cfString(cfSerialString);
+
+ if (isPCCard)
+ {
+ if (CFRef<CFArrayRef> cfVersionOne = dev.property<CFArrayRef>(kIOPCCardVersionOneMatchKey))
+ if (CFArrayGetCount(cfVersionOne) > 1)
+ {
+ CFStringRef cfVendorString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 0);
+ if (cfVendorString)
+ vendorName = cfString(cfVendorString);
+
+ CFStringRef cfProductString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 1);
+ if (cfProductString)
+ productName = cfString(cfProductString);
+ }
+
+ uint32_t address;
+ deviceMemoryAddress(dev, address);
+ }
+ else
+ {
+ if (CFRef<CFStringRef> cfVendorString = dev.property<CFStringRef>(kzIOUSBVendorNameKey))
+ vendorName = cfString(cfVendorString);
+
+ if (CFRef<CFStringRef> cfProductString = dev.property<CFStringRef>(kzIOUSBProductNameKey))
+ productName = cfString(cfProductString);
+ }
+
+ secdebug("scsel", "--- properties: service: 0x%04X, name: %s, vendor/product: 0x%04X/0x%04X, vendor: %s, product: %s, serial: %s",
+ dev.ioObject(), name.c_str(), vendorID, productID,
+ vendorName.c_str(), productName.c_str(), serialNumber.c_str());
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception in displayPropertiesOfDevice - ignoring error");
+ }
+}
+
+void PCSCDMonitor::displayPropertiesOfDevice(io_service_t service)
+{
+ kern_return_t kr;
+ CFMutableDictionaryRef properties = NULL;
+
+ // get a copy of the in kernel registry object
+ kr = IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, 0);
+ if (kr != KERN_SUCCESS)
+ {
+ printf("IORegistryEntryCreateCFProperties failed with %x\n", kr);
+ }
+ else
+ if (properties)
+ {
+// CFShow(properties);
+ CFRelease(properties);
+ }
+
+ try
+ {
+ std::string vendorName, productName, serialNumber, name;
+
+ uint32_t vendorID, productID;
+ bool isPCCard;
+
+ CFRef<CFStringRef> ioName = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOPCCardIONameKey), kCFAllocatorDefault, 0));
+ if (ioName)
+ name = cfString(ioName);
+
+// getVendorAndProductID(dev, vendorID, productID, isPCCard);
+
+ CFRef<CFStringRef> cfSerialString = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOUSBSerialNumberKey), kCFAllocatorDefault, 0));
+ if (cfSerialString)
+ serialNumber = cfString(cfSerialString);
+
+ if (isPCCard)
+ {
+ CFRef<CFArrayRef> cfVersionOne = static_cast<CFArrayRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kIOPCCardVersionOneMatchKey), kCFAllocatorDefault, 0));
+ if (cfVersionOne && (CFArrayGetCount(cfVersionOne) > 1))
+ {
+ CFStringRef cfVendorString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 0);
+ if (cfVendorString)
+ vendorName = cfString(cfVendorString);
+
+ CFStringRef cfProductString = (CFStringRef)CFArrayGetValueAtIndex(cfVersionOne, 1);
+ if (cfProductString)
+ productName = cfString(cfProductString);
+ }
+
+ uint32_t address;
+ deviceMemoryAddress(service, address);
+ }
+ else
+ {
+ CFRef<CFStringRef> cfVendorString = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOUSBVendorNameKey), kCFAllocatorDefault, 0));
+ if (cfVendorString)
+ vendorName = cfString(cfVendorString);
+
+ CFRef<CFStringRef> cfProductString = static_cast<CFStringRef>(::IORegistryEntryCreateCFProperty(
+ service, CFSTR(kzIOUSBProductNameKey), kCFAllocatorDefault, 0));
+ if (cfProductString)
+ productName = cfString(cfProductString);
+ }
+
+ secdebug("scsel", "--- properties: service: 0x%04X, name: %s, vendor/product: 0x%04X/0x%04X, vendor: %s, product: %s, serial: %s",
+ service, name.c_str(), vendorID, productID,
+ vendorName.c_str(), productName.c_str(), serialNumber.c_str());
+ }
+ catch (...)
+ {
+ secdebug("scsel", " exception in displayPropertiesOfDevice - ignoring error");
+ }
+}
+
+void PCSCDMonitor::dumpDevices()
+{
+ secdebug("pcsc", "------------------ Device Map ------------------");
+ for (DeviceMap::iterator it = mDevices.begin();it!=mDevices.end();++it)
+ {
+ PCSCD::Device *dev = static_cast<PCSCD::Device *>(it->second);
+ dev->dump();
+ }
+ secdebug("pcsc", "------------------------------------------------");
+}
+
+#if 0
+static void dumpdictentry(const void *key, const void *value, void *context)
+{
+ secdebug("dumpd", " dictionary key: %s, val: %p, CFGetTypeID: %d", cfString((CFStringRef)key).c_str(), value, (int)CFGetTypeID(value));
+}
+#endif
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdmonitor.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+//
+// pcscmonitor - use PCSC to monitor smartcard reader/card state for securityd
+//
+#ifndef _H_PCSCDMONITOR
+#define _H_PCSCDMONITOR
+
+#include <security_utilities/powerwatch.h>
+#include <security_utilities/pcsc++.h>
+#include <security_utilities/refcount.h>
+#include <security_utilities/iodevices.h>
+#include <security_utilities/threading.h>
+#include <securityd_client/ssclient.h>
+
+#include "pcscdserver.h"
+#include "PCSCDevice.h"
+#include "PCSCDriverBundles.h"
+
+typedef int32_t (*addDeviceCallback)(const char *name, uint32_t address, const char *pathLibrary, const char *pathDevice);
+typedef int32_t (*removeDeviceCallback)(const char *name, uint32_t address);
+typedef int32_t (*willSleepCallback)();
+typedef int32_t (*isWakingCallback)();
+
+#if defined(__cplusplus)
+
+class PCSCDMonitor;
+
+class TerminationNoticeReceiver : public IOKit::NotificationPort::Receiver
+{
+public:
+ TerminationNoticeReceiver(PCSCDMonitor &parent) : mParent(parent) {}
+ virtual ~TerminationNoticeReceiver();
+
+ virtual void ioChange(IOKit::DeviceIterator &iterator);
+ virtual void ioServiceChange(void *refCon, io_service_t service, //IOServiceInterestCallback
+ natural_t messageType, void *messageArgument);
+
+ virtual PCSCDMonitor &parent() { return mParent; }
+
+private:
+ PCSCDMonitor &mParent;
+};
+
+//
+// A PCSCMonitor uses PCSC to monitor the state of smartcard readers and
+// tokens (cards) in the system, and dispatches messages and events to the
+// various related players in securityd. There should be at most one of these
+// objects active within securityd.
+//
+class PCSCDMonitor :
+ private MachPlusPlus::MachServer::Timer,
+ private IOKit::NotificationPort::Receiver,
+ private MachPlusPlus::PowerWatcher
+{
+public:
+
+ friend class TerminationNoticeReceiver;
+
+ PCSCDMonitor(PCSCD::Server &server, PCSCD::DriverBundles &drivers);
+ void setCallbacks(addDeviceCallback theAddDeviceCallback, removeDeviceCallback theRemoveDeviceCallback,
+ willSleepCallback theWillSleepCallback, isWakingCallback theIsWakingCallback)
+ { mAddDeviceCallback = theAddDeviceCallback; mRemoveDeviceCallback = theRemoveDeviceCallback;
+ mWillSleepCallback = theWillSleepCallback; mIsWakingCallback = theIsWakingCallback; }
+
+ static void postNotification(const SecurityServer::NotificationEvent event);
+
+ void systemAwakeAndReadyCheck();
+
+protected:
+
+ PCSCD::Server &server;
+ PCSCD::DriverBundles &drivers;
+ addDeviceCallback mAddDeviceCallback;
+ removeDeviceCallback mRemoveDeviceCallback;
+ willSleepCallback mWillSleepCallback;
+ isWakingCallback mIsWakingCallback;
+
+protected:
+ // MachServer::Timer
+ void action();
+
+ // NotificationPort::Receiver
+ void ioChange(IOKit::DeviceIterator &iterator);
+ void ioServiceChange(void *refCon, io_service_t service, natural_t messageType, void *messageArgument);
+
+ // PowerWatcher
+ void systemWillSleep();
+ void systemIsWaking();
+
+protected:
+ void scheduleTimer(bool enable);
+ void initialSetup();
+ void noDeviceTimeout();
+
+ enum DeviceSupport
+ {
+ impossible, // certain this is not a smartcard
+ definite, // definitely a smartcard device
+ possible // perhaps... we're not sure
+ };
+ DeviceSupport deviceSupport(const IOKit::Device &dev);
+
+ void addDevice(const IOKit::Device &dev);
+ void removeDevice(io_service_t service, uint32_t address);
+ void removeDeviceByName(const IOKit::Device &dev);
+ bool hasLegacyDriver(const IOKit::Device &dev);
+ bool isExcludedDevice(const IOKit::Device &dev);
+ void scheduleAddInterestNotification(io_service_t serviceOfInterest);
+ void addInterestNotification();
+ void removeAllDevices();
+ void AddIOKitNotifications();
+ void RemoveIOKitNotifications();
+ void rescanExistingDevices();
+
+ typedef std::map<uint32_t, RefPointer<PCSCD::Device> > DeviceMap;
+ DeviceMap mDevices;
+
+ mutable Mutex mDeviceMapLock;
+
+ void insert(pair<uint32_t, RefPointer<PCSCD::Device> > devicepair) { StLock<Mutex> _(mDeviceMapLock); mDevices.insert(devicepair); }
+ void remove(DeviceMap::iterator it) { StLock<Mutex> _(mDeviceMapLock); mDevices.erase(it); }
+
+private:
+ void (PCSCDMonitor::*mTimerAction)(); // what to do when our timer fires
+ bool mGoingToSleep; // between sleep and wakeup; special timer handling
+
+ mutable Mutex mLock;
+
+ IOKit::MachPortNotificationPort mIOKitNotifier; // IOKit connection
+ TerminationNoticeReceiver mTerminationNoticeReceiver;
+
+ io_object_t mRemoveNotification;
+ io_service_t mServiceOfInterest;
+
+ bool mSleepWakePeriod;
+ mutable Mutex mSleepWakePeriodLock;
+ mutable Mutex mWakeConditionLock;
+ Condition mWakeConditionVariable;
+ bool isSleepWakePeriod() const;
+ void sleepWakePeriod(bool isASleepWakePeriod);
+ void setSystemIsAwakeCondition(bool isAwake);
+
+ bool findDevice(const IOKit::Device &dev, DeviceMap::iterator &it);
+ bool findDeviceByName(const IOKit::Device &dev, DeviceMap::iterator &outit);
+ void updateDevice(const IOKit::Device &dev);
+ void setDeviceProperties(const IOKit::Device &dev, PCSCD::Device &device);
+
+ static void getVendorAndProductID(const IOKit::Device &dev, uint32_t &vendorID, uint32_t &productID, bool &isPCCard);
+ static bool deviceIsPCCard(const IOKit::Device &dev);
+ static bool deviceIsPCCard(io_service_t service);
+ static bool deviceAddress(io_service_t service, uint32_t &address);
+ static bool deviceAddress(const IOKit::Device &dev, uint32_t &address);
+ static bool deviceMemoryAddress(const IOKit::Device &dev, uint32_t &address);
+ static bool deviceMemoryAddress(io_service_t service, uint32_t &address);
+ static bool deviceMemoryAddressCore(CFArrayRef cfDeviceMemory, std::string path, uint32_t &address);
+ static bool addressFromPath(std::string path, uint32_t &address);
+
+ // debug
+ void setDebugPropertiesForDevice(const IOKit::Device &dev, PCSCD::Device* newDevice);
+ static void displayPropertiesOfDevice(const IOKit::Device &dev);
+ static void displayPropertiesOfDevice(io_service_t service);
+ void dumpDevices();
+};
+
+#endif /* __cplusplus__ */
+
+#endif //_H_PCSCDMONITOR
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+//
+// server - pcscd main server object
+//
+#include "pcscdserver.h"
+#include <mach/mach_error.h>
+
+using namespace Security;
+using namespace MachPlusPlus;
+
+namespace PCSCD {
+
+Server::Server(const char *bootstrapName) : MachServer(bootstrapName),
+ mBootstrapName(bootstrapName)
+{
+ // Construct the server object
+ // engage the subsidiary port handler for sleep notifications
+ add(sleepWatcher);
+}
+
+Server::~Server()
+{
+ // Clean up the server object
+}
+
+void Server::run()
+{
+ // Run the server. This will not return until the server is forced to exit.
+ MachServer::run(0x10000,
+ MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0) |
+ MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT));
+}
+
+//
+// Handle thread overflow. MachServer will call this if it has hit its thread
+// limit and yet still needs another thread.
+//
+void Server::threadLimitReached(UInt32 limit)
+{
+// Syslog::notice("pcscd has reached its thread limit (%ld) - service deadlock is possible",
+// limit);
+}
+
+void Server::notifyDeadName(Port port)
+{
+ // Handling dead-port notifications.
+ // This receives DPNs for all kinds of ports we're interested in.
+ StLock<Mutex> _(mLock);
+ secdebug("SSports", "port %d is dead", port.port());
+
+ // well, what IS IT?!
+ secdebug("server", "spurious dead port notification for port %d", port.port());
+}
+
+//
+// Handling no-senders notifications.
+// This is currently only used for (subsidiary) service ports
+//
+void Server::notifyNoSenders(Port port, mach_port_mscount_t)
+{
+ secdebug("SSports", "port %d no senders", port.port());
+// Session::destroy(port);
+}
+
+void Server::notifyIfDead(MachPlusPlus::Port port, bool doNotify) const
+{
+ secdebug("SSports", "port %d is dead", port.port());
+ MachServer::notifyIfDead(port, doNotify);
+}
+
+void Server::notifyIfUnused(MachPlusPlus::Port port, bool doNotify) const
+{
+ secdebug("SSports", "port %d is dead", port.port());
+ MachServer::notifyIfUnused(port, doNotify);
+}
+
+void Server::SleepWatcher::systemWillSleep()
+{
+ // Notifier for system sleep events
+ secdebug("SS", "sleep notification received");
+// Session::processSystemSleep();
+ secdebug("server", "distributing sleep event to %ld clients", mPowerClients.size());
+ for (set<PowerWatcher *>::const_iterator it = mPowerClients.begin(); it != mPowerClients.end(); it++)
+ (*it)->systemWillSleep();
+}
+
+void Server::SleepWatcher::systemIsWaking()
+{
+ secdebug("server", "distributing wakeup event to %ld clients", mPowerClients.size());
+ for (set<PowerWatcher *>::const_iterator it = mPowerClients.begin(); it != mPowerClients.end(); it++)
+ (*it)->systemIsWaking();
+}
+
+void Server::SleepWatcher::add(PowerWatcher *client)
+{
+ assert(mPowerClients.find(client) == mPowerClients.end());
+ mPowerClients.insert(client);
+}
+
+void Server::SleepWatcher::remove(PowerWatcher *client)
+{
+ assert(mPowerClients.find(client) != mPowerClients.end());
+ mPowerClients.erase(client);
+}
+
+boolean_t Server::handle(mach_msg_header_t *in, mach_msg_header_t *out)
+{
+ // The primary server run-loop function
+ secdebug("SSreq", "Server::handle(mach_msg_header_t *in, mach_msg_header_t *out)");
+ return false;
+}
+
+
+} // end namespace PCSCD
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscdserver.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+//
+// pcscdserver - stripped down securityd main server object
+//
+#ifndef _H_PCSCDSERVER
+#define _H_PCSCDSERVER
+
+#include <security_utilities/machserver.h>
+#include <security_utilities/powerwatch.h>
+#include <map>
+
+#if defined(__cplusplus)
+
+namespace PCSCD {
+//
+// The server object itself. This is the "go to" object for anyone who wants
+// to access the server's global state. It runs the show.
+// There is only one Server, and its name is Server::active().
+//
+
+class Server : public MachPlusPlus::MachServer
+{
+public:
+ Server(const char *bootstrapName);
+ ~Server();
+
+ // run the server until it shuts down
+ void run();
+
+ //
+ // Retrieve pieces of the Server's object web.
+ // These are all static methods that use the active() Server of this thread.
+ //
+ static Server &active() { return safer_cast<Server &>(MachServer::active()); }
+ static const char *bootstrapName() { return active().mBootstrapName.c_str(); }
+
+protected:
+ // implementation methods of MachServer
+ boolean_t handle(mach_msg_header_t *in, mach_msg_header_t *out);
+ void notifyDeadName(MachPlusPlus::Port port);
+ void notifyNoSenders(MachPlusPlus::Port port, mach_port_mscount_t);
+ void threadLimitReached(UInt32 count);
+ // request port status notifications (override virtual methods below to receive)
+ virtual void notifyIfDead(MachPlusPlus::Port port, bool doNotify = true) const;
+ virtual void notifyIfUnused(MachPlusPlus::Port port, bool doNotify = true) const;
+
+private:
+ class SleepWatcher : public MachPlusPlus::PortPowerWatcher
+ {
+ public:
+ void systemWillSleep();
+ void systemIsWaking();
+
+ void add(PowerWatcher *client);
+ void remove(PowerWatcher *client);
+
+ private:
+ set<PowerWatcher *> mPowerClients;
+ };
+
+ SleepWatcher sleepWatcher;
+
+public:
+ using MachServer::add;
+ using MachServer::remove;
+ void add(MachPlusPlus::PowerWatcher *client) { StLock<Mutex> _(mLock); sleepWatcher.add(client); }
+ void remove(MachPlusPlus::PowerWatcher *client) { StLock<Mutex> _(mLock); sleepWatcher.remove(client); }
+
+private:
+ // mach bootstrap registration name
+ std::string mBootstrapName;
+ mutable Mutex mLock;
+};
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif //_H_PCSCDSERVER
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscexport.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscexport.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcscexport.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,62 @@
+/*
+ * This handles GCC attributes
+ *
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2005
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: misc.h 2188 2006-10-19 11:29:29Z rousseau $
+ */
+
+#ifndef __misc_h__
+#define __misc_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*
+ * Declare the function as internal to the library: the function name is
+ * not exported and can't be used by a program linked to the library
+ *
+ * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes
+ * see http://www.nedprod.com/programs/gccvisibility.html
+ */
+#if defined __GNUC__ && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
+#define INTERNAL __attribute__ ((visibility("hidden")))
+/*
+#define PCSC_API __attribute__ ((visibility("default")))
+We don't want to change how this was defined in previous versions*/
+#define PCSC_API
+#else
+#define INTERNAL
+#define PCSC_API
+#endif
+#define EXTERNAL PCSC_API
+
+#if defined __GNUC__
+
+/* GNU Compiler Collection (GCC) */
+#define CONSTRUCTOR __attribute__ ((constructor))
+#define DESTRUCTOR __attribute__ ((destructor))
+
+#else
+
+/* SUN C compiler does not use __attribute__ but #pragma init (function)
+ * We can't use a # inside a #define so it is not possible to use
+ * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x)
+ * The #pragma is used directly where needed */
+
+/* any other */
+#define CONSTRUCTOR
+#define DESTRUCTOR
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __misc_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcsclite.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcsclite.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/pcsclite.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: pcsclite.h.in 2124 2006-08-07 14:18:52Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This keeps a list of defines for pcsc-lite.
+ */
+
+#ifndef __pcsclite_h__
+#define __pcsclite_h__
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef int32_t SCARDCONTEXT;
+typedef SCARDCONTEXT *PSCARDCONTEXT;
+typedef SCARDCONTEXT *LPSCARDCONTEXT;
+typedef int32_t SCARDHANDLE;
+typedef SCARDHANDLE *PSCARDHANDLE;
+typedef SCARDHANDLE *LPSCARDHANDLE;
+
+#define MAX_ATR_SIZE 33 /**< Maximum ATR size */
+
+/* Set structure elements aligment on bytes
+ * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */
+#ifdef __APPLE__
+#pragma pack(1)
+#else
+#pragma pack(push, 1)
+#endif
+
+typedef struct
+{
+ const char *szReader;
+ void *pvUserData;
+ uint32_t dwCurrentState;
+ uint32_t dwEventState;
+ uint32_t cbAtr;
+ unsigned char rgbAtr[MAX_ATR_SIZE];
+}
+SCARD_READERSTATE_A;
+
+typedef SCARD_READERSTATE_A SCARD_READERSTATE, *PSCARD_READERSTATE_A,
+ *LPSCARD_READERSTATE_A;
+
+typedef struct _SCARD_IO_REQUEST
+{
+ uint32_t dwProtocol; /* Protocol identifier */
+ uint32_t cbPciLength; /* Protocol Control Inf Length */
+}
+SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;
+
+typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;
+
+extern SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci,
+ g_rgSCardRawPci;
+
+/* restore default structure elements alignment */
+#ifdef __APPLE__
+#pragma pack()
+#else
+#pragma pack(pop)
+#endif
+
+#define SCARD_PCI_T0 (&g_rgSCardT0Pci)
+#define SCARD_PCI_T1 (&g_rgSCardT1Pci)
+#define SCARD_PCI_RAW (&g_rgSCardRawPci)
+
+#define SCARD_S_SUCCESS 0x00000000
+#define SCARD_E_CANCELLED 0x80100002
+#define SCARD_E_CANT_DISPOSE 0x8010000E
+#define SCARD_E_INSUFFICIENT_BUFFER 0x80100008
+#define SCARD_E_INVALID_ATR 0x80100015
+#define SCARD_E_INVALID_HANDLE 0x80100003
+#define SCARD_E_INVALID_PARAMETER 0x80100004
+#define SCARD_E_INVALID_TARGET 0x80100005
+#define SCARD_E_INVALID_VALUE 0x80100011
+#define SCARD_E_NO_MEMORY 0x80100006
+#define SCARD_F_COMM_ERROR 0x80100013
+#define SCARD_F_INTERNAL_ERROR 0x80100001
+#define SCARD_F_UNKNOWN_ERROR 0x80100014
+#define SCARD_F_WAITED_TOO_LONG 0x80100007
+#define SCARD_E_UNKNOWN_READER 0x80100009
+#define SCARD_E_TIMEOUT 0x8010000A
+#define SCARD_E_SHARING_VIOLATION 0x8010000B
+#define SCARD_E_NO_SMARTCARD 0x8010000C
+#define SCARD_E_UNKNOWN_CARD 0x8010000D
+#define SCARD_E_PROTO_MISMATCH 0x8010000F
+#define SCARD_E_NOT_READY 0x80100010
+#define SCARD_E_SYSTEM_CANCELLED 0x80100012
+#define SCARD_E_NOT_TRANSACTED 0x80100016
+#define SCARD_E_READER_UNAVAILABLE 0x80100017
+
+#define SCARD_W_UNSUPPORTED_CARD 0x80100065
+#define SCARD_W_UNRESPONSIVE_CARD 0x80100066
+#define SCARD_W_UNPOWERED_CARD 0x80100067
+#define SCARD_W_RESET_CARD 0x80100068
+#define SCARD_W_REMOVED_CARD 0x80100069
+
+#define SCARD_E_PCI_TOO_SMALL 0x80100019
+#define SCARD_E_READER_UNSUPPORTED 0x8010001A
+#define SCARD_E_DUPLICATE_READER 0x8010001B
+#define SCARD_E_CARD_UNSUPPORTED 0x8010001C
+#define SCARD_E_NO_SERVICE 0x8010001D
+#define SCARD_E_SERVICE_STOPPED 0x8010001E
+
+#define SCARD_SCOPE_USER 0x0000 /**< Scope in user space */
+#define SCARD_SCOPE_TERMINAL 0x0001 /**< Scope in terminal */
+#define SCARD_SCOPE_SYSTEM 0x0002 /**< Scope in system */
+
+#define SCARD_PROTOCOL_UNSET 0x0000 /**< protocol not set */
+#define SCARD_PROTOCOL_T0 0x0001 /**< T=0 active protocol. */
+#define SCARD_PROTOCOL_T1 0x0002 /**< T=1 active protocol. */
+#define SCARD_PROTOCOL_RAW 0x0004 /**< Raw active protocol. */
+#define SCARD_PROTOCOL_T15 0x0008 /**< T=15 protocol. */
+
+#define SCARD_PROTOCOL_ANY (SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1) /**< IFD determines prot. */
+
+#define SCARD_SHARE_EXCLUSIVE 0x0001 /**< Exclusive mode only */
+#define SCARD_SHARE_SHARED 0x0002 /**< Shared mode only */
+#define SCARD_SHARE_DIRECT 0x0003 /**< Raw mode only */
+
+#define SCARD_LEAVE_CARD 0x0000 /**< Do nothing on close */
+#define SCARD_RESET_CARD 0x0001 /**< Reset on close */
+#define SCARD_UNPOWER_CARD 0x0002 /**< Power down on close */
+#define SCARD_EJECT_CARD 0x0003 /**< Eject on close */
+
+#define SCARD_UNKNOWN 0x0001 /**< Unknown state */
+#define SCARD_ABSENT 0x0002 /**< Card is absent */
+#define SCARD_PRESENT 0x0004 /**< Card is present */
+#define SCARD_SWALLOWED 0x0008 /**< Card not powered */
+#define SCARD_POWERED 0x0010 /**< Card is powered */
+#define SCARD_NEGOTIABLE 0x0020 /**< Ready for PTS */
+#define SCARD_SPECIFIC 0x0040 /**< PTS has been set */
+
+#define SCARD_STATE_UNAWARE 0x0000 /**< App wants status */
+#define SCARD_STATE_IGNORE 0x0001 /**< Ignore this reader */
+#define SCARD_STATE_CHANGED 0x0002 /**< State has changed */
+#define SCARD_STATE_UNKNOWN 0x0004 /**< Reader unknown */
+#define SCARD_STATE_UNAVAILABLE 0x0008 /**< Status unavailable */
+#define SCARD_STATE_EMPTY 0x0010 /**< Card removed */
+#define SCARD_STATE_PRESENT 0x0020 /**< Card inserted */
+#define SCARD_STATE_ATRMATCH 0x0040 /**< ATR matches card */
+#define SCARD_STATE_EXCLUSIVE 0x0080 /**< Exclusive Mode */
+#define SCARD_STATE_INUSE 0x0100 /**< Shared Mode */
+#define SCARD_STATE_MUTE 0x0200 /**< Unresponsive card */
+#define SCARD_STATE_UNPOWERED 0x0400 /**< Unpowered card */
+
+/** PC/SC Lite specific extensions */
+#define SCARD_W_INSERTED_CARD 0x8010006A
+#define SCARD_E_UNSUPPORTED_FEATURE 0x8010001F
+
+#define SCARD_SCOPE_GLOBAL 0x0003 /**< Scope is global */
+
+#define SCARD_RESET 0x0001 /**< Card was reset */
+#define SCARD_INSERTED 0x0002 /**< Card was inserted */
+#define SCARD_REMOVED 0x0004 /**< Card was removed */
+
+#define BLOCK_STATUS_RESUME 0x00FF /**< Normal resume */
+#define BLOCK_STATUS_BLOCKING 0x00FA /**< Function is blocking */
+
+#define PCSCLITE_CONFIG_DIR "/etc"
+
+#ifndef USE_IPCDIR
+#define PCSCLITE_IPC_DIR "/var/run"
+#else
+#define PCSCLITE_IPC_DIR USE_IPCDIR
+#endif
+
+#define PCSCLITE_READER_CONFIG PCSCLITE_CONFIG_DIR "/reader.conf"
+#define PCSCLITE_PUBSHM_FILE PCSCLITE_IPC_DIR "/pcscd.pub"
+#define PCSCLITE_CSOCK_NAME PCSCLITE_IPC_DIR "/pcscd.comm"
+
+#define PCSCLITE_SVC_IDENTITY 0x01030000 /**< Service ID */
+
+#ifndef INFINITE
+#define INFINITE 0xFFFFFFFF /**< Infinite timeout */
+#endif
+#define PCSCLITE_INFINITE_TIMEOUT 4320000 /**< 50 day infinite t/o */
+
+#define PCSCLITE_VERSION_NUMBER "1.4.0" /**< Current version */
+#define PCSCLITE_CLIENT_ATTEMPTS 120 /**< Attempts to reach sv */
+#define PCSCLITE_MCLIENT_ATTEMPTS 20 /**< Attempts to reach sv */
+#define PCSCLITE_STATUS_POLL_RATE 400000 /**< Status polling rate */
+#define PCSCLITE_MSG_KEY_LEN 16 /**< App ID key length */
+#define PCSCLITE_RW_ATTEMPTS 100 /**< Attempts to rd/wrt */
+
+/** Maximum applications */
+#define PCSCLITE_MAX_APPLICATIONS 16
+/** Maximum contexts by application */
+#define PCSCLITE_MAX_APPLICATION_CONTEXTS 16
+/** Maximum of applications contexts that pcscd can accept */
+#define PCSCLITE_MAX_APPLICATIONS_CONTEXTS \
+ PCSCLITE_MAX_APPLICATIONS * PCSCLITE_MAX_APPLICATION_CONTEXTS
+/** Maximum channels on a reader context */
+#define PCSCLITE_MAX_READER_CONTEXT_CHANNELS 16
+/** Maximum channels on an application context */
+#define PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS 16
+/** Maximum readers context (a slot is count as a reader) */
+#define PCSCLITE_MAX_READERS_CONTEXTS 16
+
+/* PCSCLITE_MAX_READERS is deprecated
+ * use PCSCLITE_MAX_READERS_CONTEXTS instead */
+/* extern int PCSCLITE_MAX_READERS __attribute__ ((deprecated)); */
+
+#define PCSCLITE_MAX_THREADS 16 /**< Stat change threads */
+#define PCSCLITE_STATUS_WAIT 200000 /**< Status Change Sleep */
+#define PCSCLITE_TRANSACTION_TIMEOUT 40 /**< Transaction timeout */
+#define MAX_READERNAME 52
+#define MAX_LIBNAME 100
+#define MAX_DEVICENAME 255
+
+#ifndef SCARD_ATR_LENGTH
+#define SCARD_ATR_LENGTH MAX_ATR_SIZE /**< Maximum ATR size */
+#endif
+
+/* These are deprecated */
+#define PCSCLITE_MAX_CHANNELS 16 /* Maximum channels */
+#define PCSCLITE_MAX_CONTEXTS 16 /* Maximum readers */
+#define PCSCLITE_MAX_COMSIZE 64 /* Maximum arg size */
+
+/*
+ * Enhanced messaging has been added to accomodate newer devices which have
+ * more advanced capabilites, such as dedicated secure co-processors which
+ * can stream and encrypt data over USB. In order to used enhanced messaging
+ * you must define PCSCLITE_ENHANCED_MESSAGING in the framework(library),
+ * the daemon, and your application
+ */
+
+/*
+ * The message and buffer sizes must be multiples of 16.
+ * The max message size must be at least large enough
+ * to accomodate the transmit_struct
+ */
+
+#ifndef PCSCLITE_ENHANCED_MESSAGING
+#define PCSCLITE_MAX_MESSAGE_SIZE 2048 /**< Transport msg len */
+#define MAX_BUFFER_SIZE 264 /**< Maximum Tx/Rx Buffer for short APDU */
+#define PCSCLITE_SERVER_ATTEMPTS 5 /**< Attempts to reach cl */
+#else
+#define PCSCLITE_MAX_MESSAGE_SIZE (1<<17) /* enhanced (128K) msg len */
+#define MAX_BUFFER_SIZE (1<<15) /* enhanced (32K) Tx/Rx Buffer */
+#define PCSCLITE_SERVER_ATTEMPTS 200 /* To allow larger data reads/writes */
+#endif
+
+#define MAX_BUFFER_SIZE_EXTENDED (4 + 3 + (1<<16) + 3) /**< enhanced (64K + APDU + Lc + Le) Tx/Rx Buffer */
+
+/*
+ * Gets a stringified error response
+ */
+char *pcsc_stringify_error(int32_t err);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_generic.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_generic.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_generic.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : powermgt_generic.h
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 04/22/02
+ License: Copyright (C) 2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This handles power management routines.
+
+$Id: powermgt_generic.h,v 1.2 2003/02/13 20:06:28 ghoo Exp $
+
+********************************************************************/
+
+#ifndef __powermgt_generic_h__
+#define __powermgt_generic_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/*
+ * Registers for Power Management callbacks
+ */
+
+ULONG PMRegisterForPowerEvents();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_macosx.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_macosx.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/powermgt_macosx.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+cc test2.c -o pm_callback -Wall -Wno-four-char-constants -framework IOKit -framework CoreFoundation
+*/
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <mach/mach_port.h>
+#include <mach/mach_interface.h>
+#include <mach/mach_init.h>
+
+#include <IOKit/pwr_mgt/IOPMLib.h>
+#include <IOKit/IOMessage.h>
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "debuglog.h"
+#include "readerfactory.h"
+#include "thread_generic.h"
+#include "hotplug.h"
+
+
+static io_connect_t root_port;
+static IONotificationPortRef notify;
+static io_object_t anIterator;
+
+PCSCLITE_THREAD_T pmgmtThread;
+extern PCSCLITE_MUTEX usbNotifierMutex;
+
+void PMPowerRegistrationThread();
+
+
+void PMPowerEventCallback(void * x,io_service_t y,natural_t messageType,void * messageArgument)
+{
+
+ switch ( messageType ) {
+ case kIOMessageCanSystemSleep:
+ IOAllowPowerChange(root_port,(long)messageArgument);
+ break;
+ case kIOMessageSystemWillSleep:
+ DebugLogA("PMPowerEventCallback: system will sleep");
+ SYS_MutexLock(&usbNotifierMutex);
+ // see WrapRFSuspendAllReaders
+ // RFSuspendAllReaders();
+ IOAllowPowerChange(root_port,(long)messageArgument);
+ DebugLogA("PMPowerEventCallback: system allowed to sleep");
+ break;
+ case kIOMessageSystemHasPoweredOn:
+ DebugLogA("PMPowerEventCallback: system has powered on");
+ // see WrapRFSuspendAllReaders
+ // HPSearchHotPluggables();
+ // RFAwakeAllReaders();
+ SYS_MutexUnLock(&usbNotifierMutex);
+ break;
+ case kIOMessageSystemWillPowerOn:
+ DebugLogA("PMPowerEventCallback: system will power on");
+ break;
+ default:
+ DebugLogB("PMPowerEventCallback: unknown event: %d", messageType);
+ break;
+ }
+
+}
+
+void PMPowerRegistrationThread() {
+
+ root_port = IORegisterForSystemPower (0,¬ify,PMPowerEventCallback,&anIterator);
+
+ if ( root_port == 0 ) {
+ printf("IORegisterForSystemPower failed\n");
+ return;
+ }
+
+ CFRunLoopAddSource(CFRunLoopGetCurrent(),
+ IONotificationPortGetRunLoopSource(notify),
+ kCFRunLoopDefaultMode);
+
+ CFRunLoopRun();
+}
+
+ULONG PMRegisterForPowerEvents()
+{
+ LONG rv;
+ DebugLogA("PMRegisterForPowerEvents");
+ rv = SYS_ThreadCreate(&pmgmtThread, THREAD_ATTR_DEFAULT, (LPVOID) PMPowerRegistrationThread, NULL);
+ return 0;
+}
+
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * prothandler.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 2004
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: prothandler.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles protocol defaults, PTS, etc.
+ */
+
+#include "config.h"
+#include <string.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "ifdhandler.h"
+#include "debuglog.h"
+#include "readerfactory.h"
+#include "prothandler.h"
+#include "atrhandler.h"
+#include "ifdwrapper.h"
+#include "eventhandler.h"
+
+/*
+ * Function: PHGetDefaultProtocol Purpose : To get the default protocol
+ * used immediately after reset. This protocol is returned from the
+ * function.
+ */
+
+UCHAR PHGetDefaultProtocol(const unsigned char *pucAtr, DWORD dwLength)
+{
+ SMARTCARD_EXTENSION sSmartCard;
+
+ /*
+ * Zero out everything
+ */
+ memset(&sSmartCard, 0x00, sizeof(SMARTCARD_EXTENSION));
+
+ if (ATRDecodeAtr(&sSmartCard, pucAtr, dwLength))
+ return sSmartCard.CardCapabilities.CurrentProtocol;
+ else
+ return 0x00;
+}
+
+/*
+ * Function: PHGetAvailableProtocols Purpose : To get the protocols
+ * supported by the card. These protocols are returned from the function
+ * as bit masks.
+ */
+
+UCHAR PHGetAvailableProtocols(const unsigned char *pucAtr, DWORD dwLength)
+{
+ SMARTCARD_EXTENSION sSmartCard;
+
+ /*
+ * Zero out everything
+ */
+ memset(&sSmartCard, 0x00, sizeof(SMARTCARD_EXTENSION));
+
+ if (ATRDecodeAtr(&sSmartCard, pucAtr, dwLength))
+ return sSmartCard.CardCapabilities.AvailableProtocols;
+ else
+ return 0x00;
+}
+
+/*
+ * Function: PHSetProtocol Purpose : To determine which protocol to use.
+ * SCardConnect has a DWORD dwPreferredProtocols that is a bitmask of what
+ * protocols to use. Basically, if T=N where N is not zero will be used
+ * first if it is available in ucAvailable. Otherwise it will always
+ * default to T=0.
+ *
+ * IFDSetPTS() is _always_ called so that the driver can initialise its data
+ */
+
+DWORD PHSetProtocol(struct ReaderContext * rContext,
+ DWORD dwPreferred, UCHAR ucAvailable, UCHAR ucDefault)
+{
+ DWORD protocol;
+ LONG rv;
+ UCHAR ucChosen;
+
+ /* App has specified no protocol */
+ if (dwPreferred == 0)
+ return SET_PROTOCOL_WRONG_ARGUMENT;
+
+ /* requested protocol is not available */
+ if (! (dwPreferred & ucAvailable))
+ {
+ /* Note:
+ * dwPreferred must be either SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1
+ * if dwPreferred == SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 the test
+ * (SCARD_PROTOCOL_T0 == dwPreferred) will not work as expected
+ * and the debug message will not be correct.
+ *
+ * This case may only occur if
+ * dwPreferred == SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1
+ * and ucAvailable == 0 since we have (dwPreferred & ucAvailable) == 0
+ * and the case ucAvailable == 0 should never occur (the card is at
+ * least T=0 or T=1)
+ */
+ Log2(PCSC_LOG_ERROR, "Protocol T=%d requested but unsupported by the card",
+ (SCARD_PROTOCOL_T0 == dwPreferred) ? 0 : 1);
+ return SET_PROTOCOL_WRONG_ARGUMENT;
+ }
+
+ /* set default value */
+ protocol = ucDefault;
+
+ /* keep only the available protocols */
+ dwPreferred &= ucAvailable;
+
+ /* we try to use T=1 first */
+ if (dwPreferred & SCARD_PROTOCOL_T1)
+ ucChosen = SCARD_PROTOCOL_T1;
+ else
+ if (dwPreferred & SCARD_PROTOCOL_T0)
+ ucChosen = SCARD_PROTOCOL_T0;
+ else
+ /* App wants unsupported protocol */
+ return SET_PROTOCOL_WRONG_ARGUMENT;
+
+ Log2(PCSC_LOG_INFO, "Attempting PTS to T=%d",
+ (SCARD_PROTOCOL_T0 == ucChosen ? 0 : 1));
+ rv = IFDSetPTS(rContext, ucChosen, 0x00, 0x00, 0x00, 0x00);
+
+ if (IFD_SUCCESS == rv)
+ protocol = ucChosen;
+ else
+ if (IFD_NOT_SUPPORTED == rv)
+ Log2(PCSC_LOG_INFO, "PTS not supported by driver, using T=%d",
+ (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
+ else
+ if (IFD_PROTOCOL_NOT_SUPPORTED == rv)
+ Log2(PCSC_LOG_INFO, "PTS protocol not supported, using T=%d",
+ (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
+ else
+ {
+ Log3(PCSC_LOG_INFO, "PTS failed (%d), using T=%d", rv,
+ (SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);
+
+ /* ISO 7816-3:1997 ch. 7.2 PPS protocol page 14
+ * - If the PPS exchange is unsuccessful, then the interface device
+ * shall either reset or reject the card.
+ */
+ return SET_PROTOCOL_PPS_FAILED;
+ }
+
+ return protocol;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/prothandler.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * prothandler.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 2004
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: prothandler.h 1421 2005-04-12 12:09:21Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles protocol defaults, PTS, etc.
+ */
+
+#ifndef __prothandler_h__
+#define __prothandler_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ UCHAR PHGetDefaultProtocol(const unsigned char *, DWORD);
+ UCHAR PHGetAvailableProtocols(const unsigned char *, DWORD);
+ DWORD PHSetProtocol(struct ReaderContext *, DWORD, UCHAR, UCHAR);
+
+#define SET_PROTOCOL_WRONG_ARGUMENT -1
+#define SET_PROTOCOL_PPS_FAILED -2
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __prothandler_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * reader.cpp
+ * SmartCardServices
+*/
+
+#include "reader.h"
+#include "eventhandler.h"
+#include "pcsclite.h"
+#include <security_utilities/debugging.h>
+
+static PCSCD::Readers *mReaders;
+
+namespace PCSCD {
+
+
+Readers::Readers()
+{
+}
+
+Readers::~Readers()
+{
+}
+
+bool Readers::find(const char *name, XReaderContext &rc) const
+{
+ return false;
+}
+
+bool Readers::find(uint32_t port, const char *name, XReaderContext &rc) const
+{
+ return false;
+}
+
+bool Readers::find(uint32_t id, XReaderContext &rc) const
+{
+ return false;
+}
+
+
+} // end namespace PCSCD
+
+#pragma mark ---------- C Interface ----------
+
+LONG XRFAllocateReaderSpace(DWORD dwAllocNum)
+{
+ try
+ {
+ mReaders = new PCSCD::Readers();
+ }
+ catch (...)
+ {
+ secdebug("pcscd", "failed to allocate Readers");
+ return -1;
+ }
+ return EHInitializeEventStructures();
+}
+
+LONG XRFReaderInfo(LPSTR lpcReader, PREADER_CONTEXT *sReader)
+{
+ // Find a reader given a name
+ PCSCD::XReaderContext rc; //>>>> use iterator instead
+ if (!sReader)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (!mReaders->find(lpcReader, rc))
+ return SCARD_E_UNKNOWN_READER;
+
+ *sReader = &rc; //>>>> WRONG - temporary var
+ return SCARD_S_SUCCESS;
+}
+
+LONG XRFReaderInfoNamePort(DWORD dwPort, LPSTR lpcReader, PREADER_CONTEXT *sReader)
+{
+ // Find a reader given a name
+ PCSCD::XReaderContext rc;
+ if (!sReader)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (!mReaders->find(dwPort, lpcReader, rc))
+ return SCARD_E_UNKNOWN_READER;
+
+ *sReader = &rc; //>>>> WRONG - temporary var
+ return SCARD_S_SUCCESS;
+}
+
+LONG XRFReaderInfoById(DWORD dwIdentity, PREADER_CONTEXT * sReader)
+{
+ // Find a reader given a handle
+ PCSCD::XReaderContext rc;
+ if (!sReader)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (!mReaders->find(dwIdentity, rc))
+ return SCARD_E_INVALID_VALUE;
+
+ *sReader = &rc; //>>>> WRONG - temporary var
+ return SCARD_S_SUCCESS;
+}
+
+LONG XRFCheckSharing(DWORD hCard)
+{
+ PCSCD::XReaderContext rc;
+ if (!mReaders->find(hCard, rc))
+ return SCARD_E_INVALID_VALUE;
+
+ return (rc.dwLockId == 0 || rc.dwLockId == hCard)?SCARD_S_SUCCESS:SCARD_E_SHARING_VIOLATION;
+}
+
+LONG XRFLockSharing(DWORD hCard)
+{
+ PCSCD::XReaderContext rc;
+ if (!mReaders->find(hCard, rc))
+ return SCARD_E_INVALID_VALUE;
+
+ if (rc.dwLockId != 0 && rc.dwLockId != hCard)
+ {
+ secdebug("pcscd", "XRFLockSharing: Lock ID invalid: %d", rc.dwLockId);
+ return SCARD_E_SHARING_VIOLATION;
+ }
+
+ EHSetSharingEvent(&rc, 1);
+ rc.dwLockId = hCard;
+ return SCARD_S_SUCCESS;
+}
+
+LONG XRFUnlockSharing(DWORD hCard)
+{
+ PCSCD::XReaderContext rc;
+ if (!mReaders->find(hCard, rc))
+ return SCARD_E_INVALID_VALUE;
+
+ if (rc.dwLockId != 0 && rc.dwLockId != hCard)
+ {
+ secdebug("pcscd", "XRFUnlockSharing: Lock ID invalid: %d", rc.dwLockId);
+ return SCARD_E_SHARING_VIOLATION;
+ }
+
+ EHSetSharingEvent(&rc, 0);
+ rc.dwLockId = 0;
+ return SCARD_S_SUCCESS;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/reader.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * reader.h
+ * SmartCardServices
+ */
+
+#ifndef _H_PCSCD_READER
+#define _H_PCSCD_READER
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "readerfactory.h"
+#include <security_utilities/refcount.h>
+#include <security_cdsa_utilities/handleobject.h>
+#include <map>
+
+#if 0
+ struct ReaderContext
+ {
+ char lpcReader[MAX_READERNAME]; /* Reader Name */
+ char lpcLibrary[MAX_LIBNAME]; /* Library Path */
+ PCSCLITE_THREAD_T pthThread; /* Event polling thread */
+ PCSCLITE_MUTEX_T mMutex; /* Mutex for this connection */
+ RDR_CAPABILITIES psCapabilites; /* Structure of reader
+ capabilities */
+ PROT_OPTIONS psProtOptions; /* Structure of protocol options */
+ RDR_CLIHANDLES psHandles[PCSCLITE_MAX_CONTEXTS];
+ /* Structure of connected handles */
+ FCT_MAP psFunctions; /* Structure of function pointers */
+ UCHAR ucAtr[MAX_ATR_SIZE]; /* Atr for inserted card */
+ DWORD dwAtrLen; /* Size of the ATR */
+ LPVOID vHandle; /* Dlopen handle */
+ DWORD dwVersion; /* IFD Handler version number */
+ DWORD dwPort; /* Port ID */
+ DWORD dwProtocol; /* Currently used protocol */
+ DWORD dwSlot; /* Current Reader Slot */
+ DWORD dwBlockStatus; /* Current blocking status */
+ DWORD dwStatus; /* Current Status Mask */
+ DWORD dwLockId; /* Lock Id */
+ DWORD dwIdentity; /* Shared ID High Nibble */
+ DWORD dwContexts; /* Number of open contexts */
+ DWORD dwPublicID; /* Public id of public state struct */
+ PDWORD dwFeeds; /* Number of shared client to lib */
+ };
+#endif
+
+#if defined(__cplusplus)
+
+namespace PCSCD {
+
+//
+// The server object itself. This is the "go to" object for anyone who wants
+// to access the server's global state. It runs the show.
+// There is only one Server, and its name is Server::active().
+//
+
+//
+// A PODWrapper for the PCSC READER_CONTEXT structure
+//
+class XReaderContext : public PodWrapper<XReaderContext, READER_CONTEXT>
+{
+public:
+ void set(const char *name, unsigned long known = SCARD_STATE_UNAWARE);
+
+ const char *name() const { return lpcReader; }
+// void name(const char *s) { szReader = s; }
+
+// unsigned long lastKnown() const { return dwStatus; }
+ void lastKnown(unsigned long s);
+
+ unsigned long state() const { return 0; } //fix
+ bool state(unsigned long it) const { return state() & it; }
+ bool changed() const { return state(SCARD_STATE_CHANGED); }
+
+// template <class T>
+// T * &userData() { return reinterpret_cast<T * &>(pvUserData); }
+
+ // DataOid access to the ATR data
+// const void *data() const { return ucAtr; }
+// size_t length() const { return dwAtrLen; }
+ void setATR(const void *atr, size_t size);
+
+ IFDUMP(void dump());
+};
+
+
+class Reader : public HandleObject, public RefCount
+{
+public:
+ Reader(const char *bootstrapName);
+ ~Reader();
+private:
+ // mach bootstrap registration name
+ std::string mBootstrapName;
+ mutable Mutex mLock;
+};
+
+class Readers
+{
+public:
+ Readers();
+ ~Readers();
+
+ typedef std::map<uint32_t, RefPointer<PCSCD::Reader> > ReaderMap;
+ ReaderMap mReaders;
+
+ bool find(uint32_t id, XReaderContext &rc) const;
+ bool find(const char *name, XReaderContext &rc) const;
+ bool find(uint32_t port, const char *name, XReaderContext &rc) const;
+
+ mutable Mutex mReaderMapLock;
+
+ void insert(pair<uint32_t, RefPointer<PCSCD::Reader> > readerpair) { StLock<Mutex> _(mReaderMapLock); mReaders.insert(readerpair); }
+ void remove(ReaderMap::iterator it) { StLock<Mutex> _(mReaderMapLock); mReaders.erase(it); }
+
+private:
+ mutable Mutex mLock;
+};
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif //_H_PCSCD_READER
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1606 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * readerfactory.c
+ * SmartCardServices
+ */
+
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : readerfactory.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 7/27/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This keeps track of a list of currently
+ available reader structures.
+
+$Id: readerfactory.c,v 1.3 2004/10/14 20:33:35 mb Exp $
+
+********************************************************************/
+
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <fcntl.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "ifdhandler.h"
+#include "debuglog.h"
+#include "thread_generic.h"
+#include "readerfactory.h"
+#include "dyn_generic.h"
+#include "sys_generic.h"
+#include "eventhandler.h"
+#include "ifdwrapper.h"
+#include "readerState.h"
+
+#include <security_utilities/debugging.h>
+
+/*
+ 64 bit
+ */
+
+#include <mach/machine.h>
+#include <sys/sysctl.h>
+
+static cpu_type_t architectureForPid(pid_t pid);
+
+#ifndef PCSCLITE_HP_BASE_PORT
+#define PCSCLITE_HP_BASE_PORT 0x200000
+#endif /* PCSCLITE_HP_BASE_PORT */
+
+static LONG RFLoadReader(PREADER_CONTEXT);
+static LONG RFUnBindFunctions(PREADER_CONTEXT);
+static LONG RFUnloadReader(PREADER_CONTEXT);
+
+static PREADER_CONTEXT sReadersContexts[PCSCLITE_MAX_READERS_CONTEXTS];
+static DWORD dwNumReadersContexts = 0;
+static DWORD lastLockID = 0;
+static PCSCLITE_MUTEX_T sReadersContextsLock = NULL;
+
+static int ReaderContextConstructor(PREADER_CONTEXT ctx, LPCSTR lpcReader,
+ DWORD dwPort, LPCSTR lpcLibrary, LPCSTR lpcDevice);
+static void ReaderContextDestructor(PREADER_CONTEXT ctx);
+static void ReaderContextFree(PREADER_CONTEXT ctx);
+static void ReaderContextClear(PREADER_CONTEXT ctx);
+static int ReaderContextInsert(PREADER_CONTEXT ctx);
+static int ReaderContextRemove(PREADER_CONTEXT ctx);
+static int ReaderContextCheckDuplicateReader(LPCSTR lpcReader, DWORD dwPort);
+static int ReaderSlotCount(PREADER_CONTEXT ctx);
+static BOOL ReaderDriverIsThreadSafe(PREADER_CONTEXT ctx, BOOL testSlot);
+static BOOL ReaderNameMatchForIndex(DWORD dwPort, LPCSTR lpcReader, int index);
+static void ReaderContextDuplicateSlot(PREADER_CONTEXT ctxBase, PREADER_CONTEXT ctxSlot, int slotNumber, BOOL baseIsThreadSafe);
+static int ReaderCheckForClone(PREADER_CONTEXT ctx, LPCSTR lpcReader,
+ DWORD dwPort, LPCSTR lpcLibrary);
+
+static int ReaderCheckArchitecture(LPCSTR lpcLibrary);
+static cpu_type_t architectureForPid(pid_t pid);
+static int architectureMatch(const char *name);
+
+extern int DBUpdateReaders(char *readerconf);
+
+
+LONG RFAllocateReaderSpace()
+{
+ int i;
+
+ sReadersContextsLock = (PCSCLITE_MUTEX_T) malloc(sizeof(PCSCLITE_MUTEX));
+ SYS_MutexInit(sReadersContextsLock);
+
+ /*
+ * Allocate each reader structure
+ */
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ sReadersContexts[i] = (PREADER_CONTEXT) calloc(1, sizeof(READER_CONTEXT));
+
+ /*
+ * Create public event structures
+ */
+ return EHInitializeEventStructures();
+}
+
+LONG RFAddReader(LPSTR lpcReader, DWORD dwPort, LPSTR lpcLibrary, LPSTR lpcDevice)
+{
+ int slotCount;
+ LONG rv = SCARD_E_NO_MEMORY;
+ int slot;
+ PREADER_CONTEXT baseContext = NULL;
+
+ if ((lpcReader == NULL) || (lpcLibrary == NULL) || (lpcDevice == NULL))
+ return SCARD_E_INVALID_VALUE;
+
+ /* Reader name too long? */
+ if (strlen(lpcReader) >= MAX_READERNAME)
+ {
+ Log3(PCSC_LOG_ERROR, "Reader name too long: %d chars instead of max %d",
+ strlen(lpcReader), MAX_READERNAME);
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ /* Library name too long? */
+ if (strlen(lpcLibrary) >= MAX_LIBNAME)
+ {
+ Log3(PCSC_LOG_ERROR, "Library name too long: %d chars instead of max %d",
+ strlen(lpcLibrary), MAX_LIBNAME);
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ /* Device name too long? */
+ if (strlen(lpcDevice) >= MAX_DEVICENAME)
+ {
+ Log3(PCSC_LOG_ERROR, "Device name too long: %d chars instead of max %d",
+ strlen(lpcDevice), MAX_DEVICENAME);
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ rv = ReaderContextCheckDuplicateReader(lpcReader, dwPort);
+ if (rv)
+ return rv;
+
+ // Make sure we have an empty slot to put the reader structure
+ rv = ReaderContextInsert(NULL);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ // Allocate a temporary reader context struct
+ baseContext = (PREADER_CONTEXT) calloc(1, sizeof(READER_CONTEXT));
+
+ rv = ReaderContextConstructor(baseContext, lpcReader, dwPort, lpcLibrary, lpcDevice);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ rv = ReaderCheckForClone(baseContext, lpcReader, dwPort, lpcLibrary);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ rv = ReaderCheckArchitecture(lpcLibrary);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ rv = RFInitializeReader(baseContext);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ rv = ReaderContextInsert(baseContext);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ rv = EHSpawnEventHandler(baseContext);
+ if (rv != SCARD_S_SUCCESS)
+ goto xit;
+
+ slotCount = ReaderSlotCount(baseContext);
+ if (slotCount <= 1)
+ return SCARD_S_SUCCESS;
+
+ /*
+ * Check the number of slots and create a different
+ * structure for each one accordingly
+ */
+
+ BOOL baseIsThreadSafe = ReaderDriverIsThreadSafe(baseContext, 1);
+
+ for (slot = 1; slot < slotCount; slot++)
+ {
+ // Make sure we have an empty slot to put the reader structure
+ // If not, we remove the whole reader
+ rv = ReaderContextInsert(NULL);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ rv = RFRemoveReader(lpcReader, dwPort);
+ return rv;
+ }
+
+ // Allocate a temporary reader context struct
+ PREADER_CONTEXT ctxSlot = (PREADER_CONTEXT) calloc(1, sizeof(READER_CONTEXT));
+
+ rv = ReaderContextConstructor(ctxSlot, lpcReader, dwPort, lpcLibrary, lpcDevice);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ ReaderContextDestructor(ctxSlot);
+ free(ctxSlot);
+ return rv;
+ }
+
+ ReaderContextDuplicateSlot(baseContext, ctxSlot, slot, baseIsThreadSafe);
+
+ rv = RFInitializeReader(ctxSlot);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "%s init failed.", lpcReader);
+ ReaderContextDestructor(ctxSlot);
+ free(ctxSlot);
+ return rv;
+ }
+
+ rv = ReaderContextInsert(ctxSlot);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = EHSpawnEventHandler(ctxSlot);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+ EHSpawnEventHandler(ctxSlot);
+ }
+
+xit:
+ if (rv != SCARD_S_SUCCESS)
+ {
+ // Cannot connect to reader, so exit gracefully
+ Log3(PCSC_LOG_ERROR, "RFAddReader: %s init failed: %d", lpcReader, rv);
+ ReaderContextDestructor(baseContext);
+ free(baseContext);
+ }
+
+ return rv;
+}
+
+LONG RFRemoveReader(LPSTR lpcReader, DWORD dwPort)
+{
+ LONG rv;
+ PREADER_CONTEXT tmpContext = NULL;
+
+ if (lpcReader == 0)
+ return SCARD_E_INVALID_VALUE;
+
+ secdebug("pcscd", "RFRemoveReader: removing %s", lpcReader);
+ while ((rv = RFReaderInfoNamePort(dwPort, lpcReader, &tmpContext)) == SCARD_S_SUCCESS)
+ {
+ // Try to destroy the thread
+ rv = EHDestroyEventHandler(tmpContext);
+
+ rv = RFUnInitializeReader(tmpContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ ReaderContextRemove(tmpContext);
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFSetReaderName(PREADER_CONTEXT rContext, LPCSTR readerName,
+ LPCSTR libraryName, DWORD dwPort, DWORD dwSlot)
+{
+ LONG parent = -1; /* reader number of the parent of the clone */
+ DWORD valueLength;
+ int currentDigit = -1;
+ int supportedChannels = 0;
+ int usedDigits[PCSCLITE_MAX_READERS_CONTEXTS] = {0,};
+ int i;
+
+ if ((0 == dwSlot) && (dwNumReadersContexts != 0))
+ {
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (sReadersContexts[i] == NULL)
+ continue;
+ if ((sReadersContexts[i])->vHandle != 0)
+ {
+ if (strcmp((sReadersContexts[i])->lpcLibrary, libraryName) == 0)
+ {
+ UCHAR tagValue[1];
+ LONG ret;
+
+ /*
+ * Ask the driver if it supports multiple channels
+ */
+ valueLength = sizeof(tagValue);
+ ret = IFDGetCapabilities((sReadersContexts[i]),
+ TAG_IFD_SIMULTANEOUS_ACCESS,
+ &valueLength, tagValue);
+
+ if ((ret == IFD_SUCCESS) && (valueLength == 1) &&
+ (tagValue[0] > 1))
+ {
+ supportedChannels = tagValue[0];
+ Log2(PCSC_LOG_INFO,
+ "Support %d simultaneous readers", tagValue[0]);
+ }
+ else
+ supportedChannels = 1;
+
+ /*
+ * Check to see if it is a hotplug reader and
+ * different
+ */
+ if (((((sReadersContexts[i])->dwPort & 0xFFFF0000) ==
+ PCSCLITE_HP_BASE_PORT)
+ && ((sReadersContexts[i])->dwPort != dwPort))
+ || (supportedChannels > 1))
+ {
+ char *lpcReader = sReadersContexts[i]->lpcReader;
+
+ /*
+ * tells the caller who the parent of this
+ * clone is so it can use it's shared
+ * resources like mutex/etc.
+ */
+ parent = i;
+
+ /*
+ * If the same reader already exists and it is
+ * hotplug then we must look for others and
+ * enumerate the readername
+ */
+ currentDigit = strtol(lpcReader + strlen(lpcReader) - 5, NULL, 16);
+
+ /*
+ * This spot is taken
+ */
+ usedDigits[currentDigit] = 1;
+ }
+ }
+ }
+ }
+
+ }
+
+ /* default value */
+ i = 0;
+
+ /* Other identical readers exist on the same bus */
+ if (currentDigit != -1)
+ {
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ /* get the first free digit */
+ if (usedDigits[i] == 0)
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ Log2(PCSC_LOG_ERROR, "Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
+ return -2;
+ }
+
+ if (i >= supportedChannels)
+ {
+ Log3(PCSC_LOG_ERROR, "Driver %s does not support more than "
+ "%d reader(s). Maybe the driver should support "
+ "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
+ return -2;
+ }
+ }
+
+ sprintf(rContext->lpcReader, "%s %02X %02X", readerName, i, dwSlot);
+
+ /*
+ * Set the slot in 0xDDDDCCCC
+ */
+ rContext->dwSlot = (i << 16) + dwSlot;
+
+ return parent;
+}
+
+LONG RFReaderInfo(LPSTR lpcReader, PREADER_CONTEXT * sReader)
+{
+ int i;
+ LONG rv = SCARD_E_UNKNOWN_READER;
+
+ if (lpcReader == 0)
+ return SCARD_E_UNKNOWN_READER;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if ((sReadersContexts[i]!=NULL) && ((sReadersContexts[i])->vHandle != 0))
+ {
+ if (strcmp(lpcReader, (sReadersContexts[i])->lpcReader) == 0)
+ {
+ *sReader = sReadersContexts[i];
+ rv = SCARD_S_SUCCESS;
+ break;
+ }
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ return rv;
+}
+
+LONG RFReaderInfoNamePort(DWORD dwPort, LPSTR lpcReader,
+ PREADER_CONTEXT * sReader)
+{
+ int ix;
+ LONG rv = SCARD_E_INVALID_VALUE;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (ix = 0; ix < PCSCLITE_MAX_READERS_CONTEXTS; ix++)
+ {
+ if ((sReadersContexts[ix]!=NULL) && ((sReadersContexts[ix])->vHandle != 0) &&
+ ReaderNameMatchForIndex(dwPort, lpcReader, ix))
+ {
+ *sReader = sReadersContexts[ix];
+ rv = SCARD_S_SUCCESS;
+ break;
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ return rv;
+}
+
+LONG RFReaderInfoById(DWORD dwIdentity, PREADER_CONTEXT * sReader)
+{
+ int i;
+ LONG rv = SCARD_E_INVALID_VALUE;
+
+ /*
+ * Strip off the lower nibble and get the identity
+ */
+ dwIdentity = dwIdentity >> (sizeof(DWORD) / 2) * 8;
+ dwIdentity = dwIdentity << (sizeof(DWORD) / 2) * 8;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if ((sReadersContexts[i]!=NULL) && (dwIdentity == (sReadersContexts[i])->dwIdentity))
+ {
+ *sReader = sReadersContexts[i];
+ rv = SCARD_S_SUCCESS;
+ break;
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ return rv;
+}
+
+static LONG RFLoadReader(PREADER_CONTEXT rContext)
+{
+ if (rContext->vHandle != 0)
+ {
+ Log1(PCSC_LOG_ERROR, "Warning library pointer not NULL");
+ /*
+ * Another reader exists with this library loaded
+ */
+ return SCARD_S_SUCCESS;
+ }
+
+ return DYN_LoadLibrary(&rContext->vHandle, rContext->lpcLibrary);
+}
+
+LONG RFBindFunctions(PREADER_CONTEXT rContext)
+{
+ int rv1, rv2, rv3;
+ void *f;
+
+ /*
+ * Use this function as a dummy to determine the IFD Handler version
+ * type 1.0/2.0/3.0. Suppress error messaging since it can't be 1.0,
+ * 2.0 and 3.0.
+ */
+
+ Log1(PCSC_LOG_INFO, "Binding driver functions");
+
+// DebugLogSuppress(DEBUGLOG_IGNORE_ENTRIES);
+
+ rv1 = DYN_GetAddress(rContext->vHandle, &f, "IO_Create_Channel");
+ rv2 = DYN_GetAddress(rContext->vHandle, &f, "IFDHCreateChannel");
+ rv3 = DYN_GetAddress(rContext->vHandle, &f, "IFDHCreateChannelByName");
+
+// DebugLogSuppress(DEBUGLOG_LOG_ENTRIES);
+
+ if (rv1 != SCARD_S_SUCCESS && rv2 != SCARD_S_SUCCESS && rv3 != SCARD_S_SUCCESS)
+ {
+ /*
+ * Neither version of the IFD Handler was found - exit
+ */
+ Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing");
+
+ exit(1);
+ } else if (rv1 == SCARD_S_SUCCESS)
+ {
+ /*
+ * Ifd Handler 1.0 found
+ */
+ rContext->dwVersion = IFD_HVERSION_1_0;
+ } else if (rv3 == SCARD_S_SUCCESS)
+ {
+ /*
+ * Ifd Handler 3.0 found
+ */
+ rContext->dwVersion = IFD_HVERSION_3_0;
+ }
+ else
+ {
+ /*
+ * Ifd Handler 2.0 found
+ */
+ rContext->dwVersion = IFD_HVERSION_2_0;
+ }
+
+ /*
+ * The following binds version 1.0 of the IFD Handler specs
+ */
+
+ if (rContext->dwVersion == IFD_HVERSION_1_0)
+ {
+ Log1(PCSC_LOG_INFO, "Loading IFD Handler 1.0");
+
+#define GET_ADDRESS_OPTIONALv1(field, function, code) \
+{ \
+ void *f1 = NULL; \
+ if (SCARD_S_SUCCESS != DYN_GetAddress(rContext->vHandle, &f1, "IFD_" #function)) \
+ { \
+ code \
+ } \
+ rContext->psFunctions.psFunctions_v1.pvf ## field = f1; \
+}
+
+#define GET_ADDRESSv1(field, function) \
+ GET_ADDRESS_OPTIONALv1(field, function, \
+ Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #function ); \
+ exit(1); )
+
+ DYN_GetAddress(rContext->vHandle, &f, "IO_Create_Channel");
+ rContext->psFunctions.psFunctions_v1.pvfCreateChannel = f;
+
+ if (SCARD_S_SUCCESS != DYN_GetAddress(rContext->vHandle, &f,
+ "IO_Close_Channel"))
+ {
+ Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing");
+ exit(1);
+ }
+ rContext->psFunctions.psFunctions_v1.pvfCloseChannel = f;
+
+ GET_ADDRESSv1(GetCapabilities, Get_Capabilities)
+ GET_ADDRESSv1(SetCapabilities, Set_Capabilities)
+ GET_ADDRESSv1(PowerICC, Power_ICC)
+ GET_ADDRESSv1(TransmitToICC, Transmit_to_ICC)
+ GET_ADDRESSv1(ICCPresence, Is_ICC_Present)
+
+ GET_ADDRESS_OPTIONALv1(SetProtocolParameters, Set_Protocol_Parameters, )
+ }
+ else if (rContext->dwVersion == IFD_HVERSION_2_0)
+ {
+ /*
+ * The following binds version 2.0 of the IFD Handler specs
+ */
+
+#define GET_ADDRESS_OPTIONALv2(s, code) \
+{ \
+ void *f1 = NULL; \
+ if (SCARD_S_SUCCESS != DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s)) \
+ { \
+ code \
+ } \
+ rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
+}
+
+#define GET_ADDRESSv2(s) \
+ GET_ADDRESS_OPTIONALv2(s, \
+ Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
+ exit(1); )
+
+ Log1(PCSC_LOG_INFO, "Loading IFD Handler 2.0");
+
+ GET_ADDRESSv2(CreateChannel)
+ GET_ADDRESSv2(CloseChannel)
+ GET_ADDRESSv2(GetCapabilities)
+ GET_ADDRESSv2(SetCapabilities)
+ GET_ADDRESSv2(PowerICC)
+ GET_ADDRESSv2(TransmitToICC)
+ GET_ADDRESSv2(ICCPresence)
+ GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
+
+ GET_ADDRESSv2(Control)
+ }
+ else if (rContext->dwVersion == IFD_HVERSION_3_0)
+ {
+ /*
+ * The following binds version 3.0 of the IFD Handler specs
+ */
+
+#define GET_ADDRESS_OPTIONALv3(s, code) \
+{ \
+ void *f1 = NULL; \
+ if (SCARD_S_SUCCESS != DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s)) \
+ { \
+ code \
+ } \
+ rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
+}
+
+#define GET_ADDRESSv3(s) \
+ GET_ADDRESS_OPTIONALv3(s, \
+ Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
+ exit(1); )
+
+ Log1(PCSC_LOG_INFO, "Loading IFD Handler 3.0");
+
+ GET_ADDRESSv2(CreateChannel)
+ GET_ADDRESSv2(CloseChannel)
+ GET_ADDRESSv2(GetCapabilities)
+ GET_ADDRESSv2(SetCapabilities)
+ GET_ADDRESSv2(PowerICC)
+ GET_ADDRESSv2(TransmitToICC)
+ GET_ADDRESSv2(ICCPresence)
+ GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
+
+ GET_ADDRESSv3(CreateChannelByName)
+ GET_ADDRESSv3(Control)
+ }
+ else
+ {
+ /*
+ * Who knows what could have happenned for it to get here.
+ */
+ Log1(PCSC_LOG_CRITICAL, "IFD Handler not 1.0/2.0 or 3.0");
+ exit(1);
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+static LONG RFUnBindFunctions(PREADER_CONTEXT rContext)
+{
+ /*
+ * Zero out everything
+ */
+
+ Log1(PCSC_LOG_INFO, "Unbinding driver functions");
+ memset(&rContext->psFunctions, 0, sizeof(rContext->psFunctions));
+
+ return SCARD_S_SUCCESS;
+}
+
+static LONG RFUnloadReader(PREADER_CONTEXT rContext)
+{
+ /*
+ * Make sure no one else is using this library
+ */
+
+ Log1(PCSC_LOG_INFO, "Unloading reader driver.");
+ if (*rContext->pdwFeeds == 1)
+ {
+ Log1(PCSC_LOG_INFO, "--- closing dynamic library");
+ DYN_CloseLibrary(&rContext->vHandle);
+ }
+
+ rContext->vHandle = 0;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFCheckSharing(DWORD hCard)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ if (rContext->dwLockId == 0 || rContext->dwLockId == hCard)
+ return SCARD_S_SUCCESS;
+ else
+ {
+ secdebug("pcscd", "RFCheckSharing: sharing violation, dwLockId: 0x%02X", rContext->dwLockId);
+ return SCARD_E_SHARING_VIOLATION;
+ }
+}
+
+LONG RFLockSharing(DWORD hCard)
+{
+ PREADER_CONTEXT rContext = NULL;
+
+ RFReaderInfoById(hCard, &rContext);
+
+ if (RFCheckSharing(hCard) == SCARD_S_SUCCESS)
+ {
+ EHSetSharingEvent(rContext, 1);
+ rContext->dwLockId = hCard;
+ }
+ else
+ return SCARD_E_SHARING_VIOLATION;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFUnlockSharing(DWORD hCard)
+{
+ PREADER_CONTEXT rContext = NULL;
+ LONG rv;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFCheckSharing(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ EHSetSharingEvent(rContext, 0);
+ rContext->dwLockId = 0;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFUnblockContext(SCARDCONTEXT hContext)
+{
+ int i;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ if (sReadersContexts[i])
+ (sReadersContexts[i])->dwBlockStatus = hContext;
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFUnblockReader(PREADER_CONTEXT rContext)
+{
+ rContext->dwBlockStatus = BLOCK_STATUS_RESUME;
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFInitializeReader(PREADER_CONTEXT rContext)
+{
+ LONG rv;
+
+ /*
+ * Spawn the event handler thread
+ */
+ Log3(PCSC_LOG_INFO, "Attempting startup of %s using %s",
+ rContext->lpcReader, rContext->lpcLibrary);
+
+ /******************************************/
+ /*
+ * This section loads the library
+ */
+ /******************************************/
+ rv = RFLoadReader(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "RFLoadReader failed: %X", rv);
+ return rv;
+ }
+
+ /*******************************************/
+ /*
+ * This section binds the functions
+ */
+ /*******************************************/
+ rv = RFBindFunctions(rContext);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "RFBindFunctions failed: %X", rv);
+ RFUnloadReader(rContext);
+ return rv;
+ }
+
+ /*******************************************/
+ /*
+ * This section tries to open the port
+ */
+ /*******************************************/
+
+ rv = IFDOpenIFD(rContext);
+
+ if (rv != IFD_SUCCESS)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Open Port %X Failed (%s)",
+ rContext->dwPort, rContext->lpcDevice);
+ RFUnBindFunctions(rContext);
+ RFUnloadReader(rContext);
+ return SCARD_E_INVALID_TARGET;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFUnInitializeReader(PREADER_CONTEXT rContext)
+{
+ Log2(PCSC_LOG_INFO, "Attempting shutdown of %s.",
+ rContext->lpcReader);
+
+ /*
+ * Close the port, unbind the functions, and unload the library
+ */
+
+ /*
+ * If the reader is getting uninitialized then it is being unplugged
+ * so I can't send a IFDPowerICC call to it
+ *
+ * IFDPowerICC( rContext, IFD_POWER_DOWN, Atr, &AtrLen );
+ */
+ IFDCloseIFD(rContext);
+ RFUnBindFunctions(rContext);
+ RFUnloadReader(rContext);
+
+ return SCARD_S_SUCCESS;
+}
+
+SCARDHANDLE RFCreateReaderHandle(PREADER_CONTEXT rContext)
+{
+ USHORT randHandle;
+
+ /*
+ * Create a random handle with 16 bits check to see if it already is
+ * used.
+ */
+ randHandle = SYS_Random(SYS_GetSeed(), 10, 65000);
+
+ while (1)
+ {
+ int i;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if ((sReadersContexts[i]!=NULL) && ((sReadersContexts[i])->vHandle != 0))
+ {
+ int j;
+
+ for (j = 0; j < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; j++)
+ {
+ if ((rContext->dwIdentity + randHandle) ==
+ (sReadersContexts[i])->psHandles[j].hCard)
+ {
+ /*
+ * Get a new handle and loop again
+ */
+ randHandle = SYS_Random(randHandle, 10, 65000);
+ continue;
+ }
+ }
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ /*
+ * Once the for loop is completed w/o restart a good handle was
+ * found and the loop can be exited.
+ */
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ break;
+ }
+
+ return rContext->dwIdentity + randHandle;
+}
+
+LONG RFFindReaderHandle(SCARDHANDLE hCard)
+{
+ int i;
+ LONG rv = SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if ((sReadersContexts[i]!=NULL) && ((sReadersContexts[i])->vHandle != 0))
+ {
+ int j;
+
+ for (j = 0; j < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; j++)
+ {
+ if (hCard == (sReadersContexts[i])->psHandles[j].hCard)
+ {
+ rv = SCARD_S_SUCCESS;
+ goto xit;
+ }
+ }
+ }
+ }
+xit:
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ return rv;
+}
+
+LONG RFDestroyReaderHandle(SCARDHANDLE hCard)
+{
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFAddReaderHandle(PREADER_CONTEXT rContext, SCARDHANDLE hCard)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
+ {
+ if (rContext->psHandles[i].hCard == 0)
+ {
+ rContext->psHandles[i].hCard = hCard;
+ rContext->psHandles[i].dwEventStatus = 0;
+ break;
+ }
+ }
+
+ if (i == PCSCLITE_MAX_READER_CONTEXT_CHANNELS)
+ /* List is full */
+ return SCARD_E_INSUFFICIENT_BUFFER;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFRemoveReaderHandle(PREADER_CONTEXT rContext, SCARDHANDLE hCard)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
+ {
+ if (rContext->psHandles[i].hCard == hCard)
+ {
+ rContext->psHandles[i].hCard = 0;
+ rContext->psHandles[i].dwEventStatus = 0;
+ break;
+ }
+ }
+
+ if (i == PCSCLITE_MAX_READER_CONTEXT_CHANNELS)
+ /* Not Found */
+ return SCARD_E_INVALID_HANDLE;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFSetReaderEventState(PREADER_CONTEXT rContext, DWORD dwEvent)
+{
+ int i;
+
+ /*
+ * Set all the handles for that reader to the event
+ */
+ for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
+ {
+ if (rContext->psHandles[i].hCard != 0)
+ rContext->psHandles[i].dwEventStatus = dwEvent;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFCheckReaderEventState(PREADER_CONTEXT rContext, SCARDHANDLE hCard)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
+ {
+ if (rContext->psHandles[i].hCard == hCard)
+ {
+ if (rContext->psHandles[i].dwEventStatus == SCARD_REMOVED)
+ return SCARD_W_REMOVED_CARD;
+ else
+ {
+ if (rContext->psHandles[i].dwEventStatus == SCARD_RESET)
+ return SCARD_W_RESET_CARD;
+ else
+ {
+ if (rContext->psHandles[i].dwEventStatus == 0)
+ return SCARD_S_SUCCESS;
+ else
+ return SCARD_E_INVALID_VALUE;
+ }
+ }
+ }
+ }
+
+ return SCARD_E_INVALID_HANDLE;
+}
+
+LONG RFClearReaderEventState(PREADER_CONTEXT rContext, SCARDHANDLE hCard)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
+ {
+ if (rContext->psHandles[i].hCard == hCard)
+ rContext->psHandles[i].dwEventStatus = 0;
+ }
+
+ if (i == PCSCLITE_MAX_READER_CONTEXT_CHANNELS)
+ /* Not Found */
+ return SCARD_E_INVALID_HANDLE;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG RFCheckReaderStatus(PREADER_CONTEXT rContext)
+{
+ LONG rx = 0;
+ rx = ((rContext == NULL) || (rContext->readerState == NULL) ||
+ (SharedReaderState_State(rContext->readerState) & SCARD_UNKNOWN))?SCARD_E_READER_UNAVAILABLE:SCARD_S_SUCCESS;
+ return rx;
+}
+
+void RFCleanupReaders(int shouldExit)
+{
+ int i;
+
+ Log1(PCSC_LOG_INFO, "entering cleaning function");
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if ((sReadersContexts[i]!=NULL) && (sReadersContexts[i]->vHandle != 0))
+ {
+ LONG rv;
+ char lpcStripReader[MAX_READERNAME];
+
+ Log2(PCSC_LOG_INFO, "Stopping reader: %s",
+ sReadersContexts[i]->lpcReader);
+
+ strncpy(lpcStripReader, (sReadersContexts[i])->lpcReader,
+ sizeof(lpcStripReader));
+ /*
+ * strip the 6 last char ' 00 00'
+ */
+ lpcStripReader[strlen(lpcStripReader) - 6] = '\0';
+
+ rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->dwPort);
+
+ if (rv != SCARD_S_SUCCESS)
+ Log2(PCSC_LOG_ERROR, "RFRemoveReader error: 0x%08X", rv);
+ }
+ }
+
+ secdebug("pcscd", "RFCleanupReaders: exiting cleaning function");
+ /*
+ * exit() will call at_exit()
+ */
+
+ if (shouldExit)
+ exit(0);
+}
+
+int RFStartSerialReaders(const char *readerconf)
+{
+ return DBUpdateReaders((char *)readerconf);
+}
+
+void RFReCheckReaderConf(void)
+{
+}
+
+void RFSuspendAllReaders()
+{
+ int ix;
+ secdebug("pcscd", "RFSuspendAllReaders");
+ Log1(PCSC_LOG_DEBUG, "zzzzz zzzzz zzzzz zzzzz RFSuspendAllReaders zzzzz zzzzz zzzzz zzzzz ");
+
+ // @@@ We still need code to mark state first as "trying to sleep", in case
+ // not all of it gets done before we sleep
+ for (ix = 0; ix < PCSCLITE_MAX_READERS_CONTEXTS; ix++)
+ {
+ if ((sReadersContexts[ix]!=NULL) && ((sReadersContexts[ix])->vHandle != 0))
+ {
+ EHDestroyEventHandler(sReadersContexts[ix]);
+ IFDCloseIFD(sReadersContexts[ix]);
+ }
+ }
+}
+
+void RFAwakeAllReaders(void)
+{
+ LONG rv = IFD_SUCCESS;
+ int i;
+
+ secdebug("pcscd", "RFAwakeAllReaders");
+ Log1(PCSC_LOG_DEBUG, "----- ----- ----- ----- RFAwakeAllReaders ----- ----- ----- ----- ");
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (sReadersContexts[i]==NULL)
+ continue;
+ /* If the library is loaded and the event handler is not running */
+ if ( ((sReadersContexts[i])->vHandle != 0) &&
+ ((sReadersContexts[i])->pthThread == 0) )
+ {
+ int jx;
+ int alreadyInitializedFlag = 0;
+
+ // If a clone of this already did the initialization,
+ // set flag so we don't do again
+ for (jx=0; jx < i; jx++)
+ {
+ if (((sReadersContexts[jx])->vHandle == (sReadersContexts[i])->vHandle)&&
+ ((sReadersContexts[jx])->dwPort == (sReadersContexts[i])->dwPort))
+ {
+ alreadyInitializedFlag = 1;
+ }
+ }
+
+ if (!alreadyInitializedFlag)
+ {
+ SYS_USleep(100000L); // 0.1s (in microseconds)
+ rv = IFDOpenIFD(sReadersContexts[i]);
+ }
+
+ RFSetReaderEventState(sReadersContexts[i], SCARD_RESET);
+ if (rv != IFD_SUCCESS)
+ {
+ Log3(PCSC_LOG_ERROR, "Open Port %X Failed (%s)",
+ (sReadersContexts[i])->dwPort, (sReadersContexts[i])->lpcDevice);
+ Log2(PCSC_LOG_ERROR, " with error 0x%08X", rv);
+ continue;
+ }
+
+ EHSpawnEventHandler(sReadersContexts[i]);
+ }
+ }
+}
+
+#pragma mark ---------- Context Share Lock Tracking ----------
+
+void ReaderContextLock(PREADER_CONTEXT rContext)
+{
+ if (rContext)
+ {
+ secdebug("pcscd", "===> ReaderContextLock [was: %02X]", rContext->dwLockId);
+ rContext->dwLockId = 0xFFFF;
+ lastLockID = -3; // something different
+ }
+}
+
+void ReaderContextUnlock(PREADER_CONTEXT rContext)
+{
+ if (rContext)
+ {
+ secdebug("pcscd", "<=== ReaderContextUnlock [was: %02X]", rContext->dwLockId);
+ rContext->dwLockId = 0;
+ lastLockID = -2; // something different
+ }
+}
+
+int ReaderContextIsLocked(PREADER_CONTEXT rContext)
+{
+ if (rContext)
+ {
+ if (rContext->dwLockId && (rContext->dwLockId != lastLockID)) // otherwise too many messages
+ {
+ lastLockID = rContext->dwLockId;
+ secdebug("pcscd", ".... ReaderContextLock state: %02X", rContext->dwLockId);
+ }
+ return (rContext->dwLockId == 0xFFFF)?1:0;
+ }
+ else
+ return 0;
+}
+
+#pragma mark ---------- Reader Context Management ----------
+
+static int ReaderContextConstructor(PREADER_CONTEXT ctx, LPCSTR lpcReader,
+ DWORD dwPort, LPCSTR lpcLibrary, LPCSTR lpcDevice)
+{
+ // We assume the struct was created with a calloc, so we don't call ReaderContextClear
+ if (!ctx)
+ return SCARD_E_NO_MEMORY;
+
+ strlcpy(ctx->lpcLibrary, lpcLibrary, sizeof(ctx->lpcLibrary));
+ strlcpy(ctx->lpcDevice, lpcDevice, sizeof(ctx->lpcDevice));
+ ctx->dwPort = dwPort;
+
+ /*
+ Initialize pdwFeeds to 1, otherwise multiple cloned readers will cause
+ pcscd to crash when RFUnloadReader unloads the driver library
+ and there are still devices attached using it
+ */
+ ctx->pdwFeeds = malloc(sizeof(DWORD));
+ *ctx->pdwFeeds = 1;
+
+ ctx->mMutex = (PCSCLITE_MUTEX_T) malloc(sizeof(PCSCLITE_MUTEX));
+ SYS_MutexInit(ctx->mMutex);
+
+ ctx->pdwMutex = malloc(sizeof(DWORD));
+ *ctx->pdwMutex = 1;
+
+ return SCARD_S_SUCCESS;
+}
+
+static int ReaderCheckForClone(PREADER_CONTEXT ctx, LPCSTR lpcReader,
+ DWORD dwPort, LPCSTR lpcLibrary)
+{
+ // Check and set the readername to see if it must be enumerated
+ // A parentNode of -2 or less indicates fatal error
+
+ LONG parentNode = RFSetReaderName(ctx, lpcReader, lpcLibrary, dwPort, 0);
+ if (parentNode < -1)
+ return SCARD_E_NO_MEMORY;
+
+ // If a clone to this reader exists take some values from that clone
+ if ((parentNode >= 0) && (parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
+ && sReadersContexts[parentNode])
+ {
+ SYS_MutexLock(sReadersContextsLock);
+ ctx->pdwFeeds = (sReadersContexts[parentNode])->pdwFeeds;
+ *ctx->pdwFeeds += 1;
+ ctx->vHandle = (sReadersContexts[parentNode])->vHandle;
+ ctx->mMutex = (sReadersContexts[parentNode])->mMutex;
+ ctx->pdwMutex = (sReadersContexts[parentNode])->pdwMutex;
+ SYS_MutexUnLock(sReadersContextsLock);
+
+ if (0 && ReaderDriverIsThreadSafe(sReadersContexts[parentNode], 0))
+ {
+ ctx->mMutex = 0;
+ ctx->pdwMutex = NULL;
+ }
+ else
+ *ctx->pdwMutex += 1;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+static void ReaderContextDestructor(PREADER_CONTEXT ctx)
+{
+ ReaderContextFree(ctx);
+}
+
+static void ReaderContextFree(PREADER_CONTEXT ctx)
+{
+ if (!ctx)
+ return;
+
+ // Destroy and free the mutex
+ if (ctx->pdwMutex)
+ {
+ if (*ctx->pdwMutex == 1)
+ {
+ SYS_MutexDestroy(ctx->mMutex);
+ free(ctx->mMutex);
+ }
+ *ctx->pdwMutex -= 1;
+ }
+
+ // Destroy and free the mutex counter
+ if (ctx->pdwMutex && (*ctx->pdwMutex == 0))
+ {
+ free(ctx->pdwMutex);
+ ctx->pdwMutex = NULL;
+ }
+
+ if (ctx->pdwFeeds)
+ {
+ *ctx->pdwFeeds -= 1;
+ if (*ctx->pdwFeeds == 0)
+ {
+ free(ctx->pdwFeeds);
+ ctx->pdwFeeds = NULL;
+ }
+ }
+
+ // zero out everything else
+ ReaderContextClear(ctx);
+}
+
+static void ReaderContextClear(PREADER_CONTEXT ctx)
+{
+ // This assumes that ReaderContextFree has already been called if necessary
+ if (ctx)
+ memset(ctx, 0, sizeof(READER_CONTEXT));
+}
+
+static int ReaderContextInsert(PREADER_CONTEXT ctx)
+{
+ // Find an empty slot to put the reader structure, and copy it in
+ // If NULL is passed in, just return whether a spot is available or not
+
+ int ix, rv = SCARD_E_NO_MEMORY;
+
+ SYS_MutexLock(sReadersContextsLock);
+ for (ix = 0; ix < PCSCLITE_MAX_READERS_CONTEXTS; ix++)
+ {
+ if ((sReadersContexts[ix] == NULL) || (sReadersContexts[ix])->vHandle == 0)
+ {
+ if (ctx)
+ {
+ if (sReadersContexts[ix])
+ free(sReadersContexts[ix]);
+ sReadersContexts[ix] = ctx;
+ (sReadersContexts[ix])->dwIdentity = (ix + 1) << (sizeof(DWORD) / 2) * 8;
+ dwNumReadersContexts += 1;
+ }
+ rv = SCARD_S_SUCCESS;
+ break;
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+ return rv;
+}
+
+static int ReaderContextRemove(PREADER_CONTEXT ctx)
+{
+ int ix, rv = SCARD_E_UNKNOWN_READER;
+ PREADER_CONTEXT ctxToRemove = NULL;
+ DWORD dwPort = ctx->dwPort;
+ LPSTR lpcReader = ctx->lpcReader;
+ SYS_MutexLock(sReadersContextsLock);
+ for (ix = 0; ix < PCSCLITE_MAX_READERS_CONTEXTS; ix++)
+ {
+ if (!ReaderNameMatchForIndex(dwPort, lpcReader, ix))
+ continue;
+
+ ctxToRemove = sReadersContexts[ix];
+ sReadersContexts[ix] = NULL;
+ dwNumReadersContexts -= 1;
+ rv = SCARD_S_SUCCESS;
+ break;
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+ // We can do this cleanup outside the lock
+ if (ctxToRemove)
+ {
+ ReaderContextDestructor(ctxToRemove);
+ free(ctxToRemove);
+ }
+ return rv;
+}
+
+static int ReaderContextCheckDuplicateReader(LPCSTR lpcReader, DWORD dwPort)
+{
+ // Readers with the same name and same port cannot be used
+
+ if (dwNumReadersContexts == 0)
+ return SCARD_S_SUCCESS;
+
+ int ix, rv = SCARD_S_SUCCESS;
+ SYS_MutexLock(sReadersContextsLock);
+ for (ix = 0; ix < PCSCLITE_MAX_READERS_CONTEXTS; ix++)
+ {
+ if ((sReadersContexts[ix]==NULL) || ((sReadersContexts[ix])->vHandle == 0))
+ continue;
+
+ if (ReaderNameMatchForIndex(dwPort, lpcReader, ix))
+ {
+ Log1(PCSC_LOG_ERROR, "Duplicate reader found.");
+ rv = SCARD_E_DUPLICATE_READER;
+ break;
+ }
+ }
+ SYS_MutexUnLock(sReadersContextsLock);
+ return rv;
+}
+
+static int ReaderSlotCount(PREADER_CONTEXT ctx)
+{
+ // Call on the driver to see if there are multiple slots
+ // If we encounter errors, pretend it is just a single slot reader
+
+ UCHAR ucGetData[1];
+ DWORD dwGetSize = sizeof(ucGetData);
+ int rv = IFDGetCapabilities(ctx, TAG_IFD_SLOTS_NUMBER, &dwGetSize, ucGetData);
+
+ //Reader does not have this defined, so assume a single slot
+ if (rv != IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
+ return 1;
+
+ // Reader has this defined and it only has one slot
+ if (rv == IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
+ return 1;
+
+ return (int)ucGetData[0];
+}
+
+static BOOL ReaderDriverIsThreadSafe(PREADER_CONTEXT ctx, BOOL testSlot)
+{
+ // Call on the driver to see if it is thread safe
+ UCHAR ucThread[1];
+ DWORD dwGetSize = sizeof(ucThread);
+ int rv = IFDGetCapabilities(ctx, testSlot?TAG_IFD_SLOT_THREAD_SAFE:TAG_IFD_THREAD_SAFE,
+ &dwGetSize, ucThread);
+ if (rv == IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
+ {
+ Log1(PCSC_LOG_INFO, "Driver is thread safe");
+ return 1;
+ }
+ else
+ {
+ Log1(PCSC_LOG_INFO, "Driver is not thread safe");
+ return 0;
+ }
+}
+
+static BOOL ReaderNameMatchForIndex(DWORD dwPort, LPCSTR lpcReader, int index)
+{
+ // "index" is index in sReadersContexts
+ char lpcStripReader[MAX_READERNAME];
+ int tmplen;
+
+ if (sReadersContexts[index]==NULL)
+ return 0;
+
+ strncpy(lpcStripReader, (sReadersContexts[index])->lpcReader, sizeof(lpcStripReader));
+ tmplen = strlen(lpcStripReader);
+ lpcStripReader[tmplen - 6] = 0;
+
+ return ((strcmp(lpcReader, lpcStripReader) == 0) && (dwPort == (sReadersContexts[index])->dwPort))?1:0;
+}
+
+static void ReaderContextDuplicateSlot(PREADER_CONTEXT ctxBase, PREADER_CONTEXT ctxSlot, int slotNumber, BOOL baseIsThreadSafe)
+{
+ // Copy the previous reader name and set the slot number
+ // The slot number for the base is 0
+
+ int ix;
+ char *tmpReader = ctxSlot->lpcReader;
+ strlcpy(tmpReader, ctxBase->lpcReader, sizeof(ctxSlot->lpcReader));
+ sprintf(tmpReader + strlen(tmpReader) - 2, "%02X", slotNumber);
+
+ strlcpy(ctxSlot->lpcLibrary, ctxBase->lpcLibrary, sizeof(ctxSlot->lpcLibrary));
+ strlcpy(ctxSlot->lpcDevice, ctxBase->lpcDevice, sizeof(ctxSlot->lpcDevice));
+
+ ctxSlot->dwVersion = ctxBase->dwVersion;
+ ctxSlot->dwPort = ctxBase->dwPort;
+ ctxSlot->vHandle = ctxBase->vHandle;
+ ctxSlot->mMutex = ctxBase->mMutex;
+ ctxSlot->pdwMutex = ctxBase->pdwMutex;
+ ctxSlot->dwSlot = ctxBase->dwSlot + slotNumber;
+
+ ctxSlot->pdwFeeds = ctxBase->pdwFeeds;
+
+ *ctxSlot->pdwFeeds += 1;
+
+ ctxSlot->dwBlockStatus = 0;
+ ctxSlot->dwContexts = 0;
+ ctxSlot->dwLockId = 0;
+ ctxSlot->readerState = NULL;
+ ctxSlot->dwIdentity = (slotNumber + 1) << (sizeof(DWORD) / 2) * 8;
+
+ for (ix = 0; ix < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; ix++)
+ ctxSlot->psHandles[ix].hCard = 0;
+
+ if (!ctxSlot->pdwMutex)
+ ctxSlot->pdwMutex = malloc(sizeof(DWORD));
+ if (baseIsThreadSafe)
+ {
+ ctxSlot->mMutex = malloc(sizeof(PCSCLITE_MUTEX));
+ SYS_MutexInit(ctxSlot->mMutex);
+ *ctxSlot->pdwMutex = 1;
+ }
+ else
+ *ctxSlot->pdwMutex += 1;
+}
+
+#pragma mark ---------- 64 bit routines ----------
+
+/*
+ This section contains code needed to determine which architecture we are on.
+ */
+
+#include <spawn.h>
+#include <err.h>
+#include <CoreFoundation/CFBundle.h>
+#include <CoreFoundation/CFNumber.h>
+#include <signal.h>
+
+extern char **environ;
+extern char **globalArgv;
+
+static cpu_type_t architectureForPid(pid_t pid)
+{
+ // pid_t mypid = getpid(); // current process
+
+ cpu_type_t cpuType = CPU_TYPE_ANY;
+ int mib[CTL_MAXNAME]={0,};
+ size_t len = CTL_MAXNAME;
+ if (sysctlnametomib("sysctl.proc_cputype", mib, &len) != -1)
+ {
+ mib[len] = pid;
+ len++;
+
+ size_t cputypelen = sizeof(cpuType);
+ if (sysctl(mib, len, &cpuType, &cputypelen, 0, 0) == -1)
+ {
+ cpuType = CPU_TYPE_ANY;
+ }
+ }
+ return cpuType;
+}
+
+static int ReaderCheckArchitecture(LPCSTR lpcLibrary)
+{
+#if MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
+ /*
+ Get architecture for current process. If we are already in 32-bit mode,
+ just keep going to avoid reswpaning ourselves over and over again.
+ */
+ cpu_type_t cputype = architectureForPid(getpid());
+ if (! (cputype & CPU_ARCH_ABI64))
+ return SCARD_S_SUCCESS;
+
+ /*
+ Check to see if the driver has an architecture that matches how we are
+ running now. If it doesn't, we will try to relaunch in 32 bit mode.
+ */
+ if (architectureMatch(lpcLibrary))
+ return SCARD_S_SUCCESS;
+
+ pid_t pid = getpid();
+
+ Log2(PCSC_LOG_INFO, "Send respawn signal to pcscd (pid=%d)", pid);
+ if (kill(pid, SIGUSR2) < 0)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Can't signal pcscd (pid=%d): %s",
+ pid, strerror(errno));
+ }
+ void *value_ptr;
+ pthread_exit(value_ptr);
+ return SCARD_E_SERVICE_STOPPED;
+#else
+ return SCARD_S_SUCCESS;
+#endif
+}
+
+static int architectureMatch(const char *name)
+{
+ int rx = false;
+ const Boolean isDirectory = true;
+ cpu_type_t cputype;
+ CFArrayRef pluginArchitectures = NULL;
+
+ CFURLRef exurl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
+ CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8), kCFURLPOSIXPathStyle, isDirectory);
+ if (!exurl)
+ return false;
+
+ CFBundleRef theBundle = CFBundleCreate(kCFAllocatorDefault, exurl);
+ if (theBundle == NULL)
+ goto xit;
+
+ pluginArchitectures = CFBundleCopyExecutableArchitectures(theBundle);
+ if (pluginArchitectures == NULL)
+ goto xit;
+
+ cputype = architectureForPid(getpid());
+
+ int ix;
+ for (ix = CFArrayGetCount(pluginArchitectures); --ix >= 0; )
+ {
+ CFNumberRef cfarch = (CFNumberRef)CFArrayGetValueAtIndex(pluginArchitectures, ix);
+ UInt32 arch;
+ CFNumberGetValue(cfarch, kCFNumberSInt32Type, &arch);
+ if (cputype == arch)
+ {
+ rx = true;
+ break;
+ }
+ }
+
+xit:
+
+ if (exurl)
+ CFRelease(exurl);
+ if (theBundle)
+ CFRelease(theBundle);
+ if (pluginArchitectures)
+ CFRelease(pluginArchitectures);
+
+ return rx;
+}
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerfactory.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,256 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * readerfactory.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ * Copyright (C) 2004
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: readerfactory.h 2330 2007-01-11 16:54:16Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This keeps track of a list of currently available reader structures.
+ */
+
+#ifndef __readerfactory_h__
+#define __readerfactory_h__
+
+#include <inttypes.h>
+
+#include "thread_generic.h"
+#include "ifdhandler.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ char *pcFriendlyname;
+ char *pcDevicename;
+ char *pcLibpath;
+ int dwChannelId;
+ } SerialReader;
+
+ struct FctMap_V1
+ {
+ RESPONSECODE (*pvfCreateChannel)(DWORD);
+ RESPONSECODE (*pvfCloseChannel)(void);
+ RESPONSECODE (*pvfGetCapabilities)(DWORD, PUCHAR);
+ RESPONSECODE (*pvfSetCapabilities)(DWORD, PUCHAR);
+ RESPONSECODE (*pvfSetProtocolParameters)(DWORD, UCHAR, UCHAR, UCHAR,
+ UCHAR);
+ RESPONSECODE (*pvfPowerICC)(DWORD);
+ RESPONSECODE (*pvfTransmitToICC)(SCARD_IO_HEADER, PUCHAR, DWORD,
+ PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ RESPONSECODE (*pvfICCPresence)(void);
+ };
+
+ typedef struct FctMap_V1 FCT_MAP_V1, *PFCT_MAP_V1;
+
+ struct FctMap_V2
+ {
+ /* shared with API 3.0 */
+ RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
+ RESPONSECODE (*pvfCloseChannel)(DWORD);
+ RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
+ RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
+ RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
+ UCHAR, UCHAR);
+ RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
+ RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
+ DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ RESPONSECODE (*pvfICCPresence)(DWORD);
+
+ /* API v2.0 only */
+ RESPONSECODE (*pvfControl)(DWORD, PUCHAR, DWORD, PUCHAR, PDWORD);
+ };
+
+ typedef struct FctMap_V2 FCT_MAP_V2, *PFCT_MAP_V2;
+
+ struct FctMap_V3
+ {
+ /* the common fields SHALL be in the same order as in FctMap_V2 */
+ RESPONSECODE (*pvfCreateChannel)(DWORD, DWORD);
+ RESPONSECODE (*pvfCloseChannel)(DWORD);
+ RESPONSECODE (*pvfGetCapabilities)(DWORD, DWORD, PDWORD, PUCHAR);
+ RESPONSECODE (*pvfSetCapabilities)(DWORD, DWORD, DWORD, PUCHAR);
+ RESPONSECODE (*pvfSetProtocolParameters)(DWORD, DWORD, UCHAR, UCHAR,
+ UCHAR, UCHAR);
+ RESPONSECODE (*pvfPowerICC)(DWORD, DWORD, PUCHAR, PDWORD);
+ RESPONSECODE (*pvfTransmitToICC)(DWORD, SCARD_IO_HEADER, PUCHAR,
+ DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER);
+ RESPONSECODE (*pvfICCPresence)(DWORD);
+
+ /* API V3.0 only */
+ RESPONSECODE (*pvfControl)(DWORD, DWORD, LPCVOID, DWORD, LPVOID,
+ DWORD, LPDWORD);
+ RESPONSECODE (*pvfCreateChannelByName)(DWORD, LPSTR);
+ };
+
+ typedef struct FctMap_V3 FCT_MAP_V3, *PFCT_MAP_V3;
+
+ /*
+ * The following is not currently used but in place if needed
+ */
+
+ struct RdrCapabilities
+ {
+ DWORD dwAsynch_Supported; /* Asynchronous Support */
+ DWORD dwDefault_Clock; /* Default Clock Rate */
+ DWORD dwMax_Clock; /* Max Clock Rate */
+ DWORD dwDefault_Data_Rate; /* Default Data Rate */
+ DWORD dwMax_Data_Rate; /* Max Data Rate */
+ DWORD dwMax_IFSD; /* Maximum IFSD Size */
+ DWORD dwSynch_Supported; /* Synchronous Support */
+ DWORD dwPower_Mgmt; /* Power Mgmt Features */
+ DWORD dwCard_Auth_Devices; /* Card Auth Devices */
+ DWORD dwUser_Auth_Device; /* User Auth Devices */
+ DWORD dwMechanics_Supported; /* Machanics Supported */
+ DWORD dwVendor_Features; /* User Defined. */
+ };
+
+ typedef struct RdrCapabilities RDR_CAPABILITIES, *PRDR_CAPABILITIES;
+
+ struct ProtOptions
+ {
+ DWORD dwProtocol_Type; /* Protocol Type */
+ DWORD dwCurrent_Clock; /* Current Clock */
+ DWORD dwCurrent_F; /* Current F */
+ DWORD dwCurrent_D; /* Current D */
+ DWORD dwCurrent_N; /* Current N */
+ DWORD dwCurrent_W; /* Current W */
+ DWORD dwCurrent_IFSC; /* Current IFSC */
+ DWORD dwCurrent_IFSD; /* Current IFSD */
+ DWORD dwCurrent_BWT; /* Current BWT */
+ DWORD dwCurrent_CWT; /* Current CWT */
+ DWORD dwCurrent_EBC; /* Current EBC */
+ };
+
+ typedef struct ProtOptions PROT_OPTIONS, *PPROT_OPTIONS;
+
+ struct RdrCliHandles
+ {
+ SCARDHANDLE hCard; /* hCard for this connection */
+ DWORD dwEventStatus; /* Recent event that must be sent */
+ };
+
+ typedef struct RdrCliHandles RDR_CLIHANDLES, *PRDR_CLIHANDLES;
+
+ struct ReaderContext
+ {
+ char lpcReader[MAX_READERNAME]; /* Reader Name */
+ char lpcLibrary[MAX_LIBNAME]; /* Library Path */
+ char lpcDevice[MAX_DEVICENAME]; /* Device Name */
+ PCSCLITE_THREAD_T pthThread; /* Event polling thread */
+ PCSCLITE_MUTEX_T mMutex; /* Mutex for this connection */
+ RDR_CLIHANDLES psHandles[PCSCLITE_MAX_READER_CONTEXT_CHANNELS];
+ /* Structure of connected handles */
+ union
+ {
+ FCT_MAP_V1 psFunctions_v1; /* API V1.0 */
+ FCT_MAP_V2 psFunctions_v2; /* API V2.0 */
+ FCT_MAP_V3 psFunctions_v3; /* API V3.0 */
+ } psFunctions;
+
+ LPVOID vHandle; /* Dlopen handle */
+ DWORD dwVersion; /* IFD Handler version number */
+ DWORD dwPort; /* Port ID */
+ DWORD dwSlot; /* Current Reader Slot */
+ DWORD dwBlockStatus; /* Current blocking status */
+ DWORD dwLockId; /* Lock Id */
+ DWORD dwIdentity; /* Shared ID High Nibble */
+ int32_t dwContexts; /* Number of open contexts */
+ PDWORD pdwFeeds; /* Number of shared client to lib */
+ PDWORD pdwMutex; /* Number of client to mutex */
+
+ struct pubReaderStatesList *readerState; /* link to the reader state */
+ /* we can't use PREADER_STATE here since eventhandler.h can't be
+ * included because of circular dependencies */
+
+ /* these structures are unused */
+#if 0
+ RDR_CAPABILITIES psCapabilites; /* Structure of reader
+ capabilities */
+ PROT_OPTIONS psProtOptions; /* Structure of protocol options */
+#endif
+ };
+
+ typedef struct ReaderContext READER_CONTEXT, *PREADER_CONTEXT;
+
+ LONG RFAllocateReaderSpace(void);
+ LONG RFAddReader(LPSTR, DWORD, LPSTR, LPSTR);
+ LONG RFRemoveReader(LPSTR, DWORD);
+ LONG RFSetReaderName(PREADER_CONTEXT, LPCSTR, LPCSTR, DWORD, DWORD);
+ LONG RFListReaders(LPSTR, LPDWORD);
+ LONG RFReaderInfo(LPSTR, struct ReaderContext **);
+ LONG RFReaderInfoNamePort(DWORD, LPSTR, struct ReaderContext **);
+ LONG RFReaderInfoById(DWORD, struct ReaderContext **);
+ LONG RFCheckSharing(DWORD);
+ LONG RFLockSharing(DWORD);
+ LONG RFUnlockSharing(DWORD);
+ LONG RFUnblockReader(PREADER_CONTEXT);
+ LONG RFUnblockContext(SCARDCONTEXT);
+#if 0
+ LONG RFLoadReader(PREADER_CONTEXT);
+ LONG RFBindFunctions(PREADER_CONTEXT);
+ LONG RFUnBindFunctions(PREADER_CONTEXT);
+ LONG RFUnloadReader(PREADER_CONTEXT);
+#endif
+ LONG RFInitializeReader(PREADER_CONTEXT);
+ LONG RFUnInitializeReader(PREADER_CONTEXT);
+ SCARDHANDLE RFCreateReaderHandle(PREADER_CONTEXT);
+ LONG RFDestroyReaderHandle(SCARDHANDLE hCard);
+ LONG RFAddReaderHandle(PREADER_CONTEXT, SCARDHANDLE);
+ LONG RFFindReaderHandle(SCARDHANDLE);
+ LONG RFRemoveReaderHandle(PREADER_CONTEXT, SCARDHANDLE);
+ LONG RFSetReaderEventState(PREADER_CONTEXT, DWORD);
+ LONG RFCheckReaderEventState(PREADER_CONTEXT, SCARDHANDLE);
+ LONG RFClearReaderEventState(PREADER_CONTEXT, SCARDHANDLE);
+ LONG RFCheckReaderStatus(PREADER_CONTEXT);
+ void RFCleanupReaders(int);
+ int RFStartSerialReaders(const char *readerconf);
+ void RFReCheckReaderConf(void);
+ void RFSuspendAllReaders(void);
+ void RFAwakeAllReaders(void);
+
+ void ReaderContextLock(PREADER_CONTEXT rContext);
+ void ReaderContextUnlock(PREADER_CONTEXT rContext);
+ int ReaderContextIsLocked(PREADER_CONTEXT rContext);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2007 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * readerstate.cpp
+ * SmartCardServices
+*/
+
+#include "readerstate.h"
+#include "pcsclite.h"
+#include "eventhandler.h"
+#include <security_utilities/debugging.h>
+
+DWORD SharedReaderState_State(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xreaderState();
+}
+
+DWORD SharedReaderState_Protocol(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xcardProtocol();
+}
+
+DWORD SharedReaderState_Sharing(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->sharing();
+}
+
+size_t SharedReaderState_CardAtrLength(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xcardAtrLength();
+}
+
+LONG SharedReaderState_ReaderID(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xreaderID();
+}
+
+const unsigned char *SharedReaderState_CardAtr(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xcardAtr();
+}
+
+const char *SharedReaderState_ReaderName(READER_STATE *rs)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return srs->xreaderName();
+}
+
+int SharedReaderState_ReaderNameIsEqual(READER_STATE *rs, const char *otherName)
+{
+ if (otherName)
+ {
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ return (strcmp(otherName, srs->xreaderName()) == 0);
+ }
+ else
+ return 0;
+}
+
+void SharedReaderState_SetState(READER_STATE *rs, DWORD state)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ srs->xreaderState(state);
+}
+
+void SharedReaderState_SetProtocol(READER_STATE *rs, DWORD newprotocol)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ srs->xcardProtocol(newprotocol);
+}
+
+void SharedReaderState_SetCardAtrLength(READER_STATE *rs, size_t len)
+{
+ PCSCD::SharedReaderState *srs = PCSCD::SharedReaderState::overlay(rs);
+ srs->xcardAtrLength(len);
+}
+
+
+#pragma mark ---------- C Interface ----------
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/readerstate.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2007 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * readerstate.h
+ * SmartCardServices
+ */
+
+#ifndef _H_PCSCD_READER_STATE
+#define _H_PCSCD_READER_STATE
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "readerfactory.h"
+#include "eventhandler.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+DWORD SharedReaderState_State(READER_STATE *rs);
+DWORD SharedReaderState_Protocol(READER_STATE *rs);
+DWORD SharedReaderState_Sharing(READER_STATE *rs);
+size_t SharedReaderState_CardAtrLength(READER_STATE *rs);
+LONG SharedReaderState_ReaderID(READER_STATE *rs);
+const unsigned char *SharedReaderState_CardAtr(READER_STATE *rs);
+const char *SharedReaderState_ReaderName(READER_STATE *rs);
+int SharedReaderState_ReaderNameIsEqual(READER_STATE *rs, const char *otherName);
+void SharedReaderState_SetState(READER_STATE *rs, DWORD state);
+void SharedReaderState_SetProtocol(READER_STATE *rs, DWORD newprotocol);
+void SharedReaderState_SetCardAtrLength(READER_STATE *rs, size_t len);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#if defined(__cplusplus)
+
+#include <security_utilities/threading.h>
+
+namespace PCSCD {
+
+//
+// NB: We are using the fact that on our systems, mutexes provide read/write
+// memory barrier as a side effect to avoid having to flush the shared memory
+// region to disk
+//
+
+
+//
+// A PODWrapper for the PCSC ReaderState structure
+//
+class SharedReaderState : public PodWrapper<SharedReaderState, READER_STATE>
+{
+public:
+
+ LONG xreaderID() const { Atomic<int>::barrier(); return ntohl(readerID); }
+ void xreaderID(LONG rid) { Atomic<int>::barrier(); readerID = htonl(rid); }
+
+ DWORD xreaderState() const { Atomic<int>::barrier(); return ntohl(readerState); }
+ void xreaderState(DWORD state) { Atomic<int>::barrier(); readerState = htonl(state); }
+
+ DWORD sharing() const { Atomic<int>::barrier(); return ntohl(readerSharing); }
+ void sharing(DWORD sharing) { Atomic<int>::barrier(); readerSharing = htonl(sharing); }
+
+ DWORD xlockState() const { Atomic<int>::barrier(); return ntohl(lockState); }
+ void xlockState(DWORD state) { Atomic<int>::barrier(); lockState = htonl(state); }
+
+ DWORD xcardProtocol() const { Atomic<int>::barrier(); return ntohl(cardProtocol); }
+ void xcardProtocol(DWORD prot) { Atomic<int>::barrier(); cardProtocol = htonl(prot); }
+
+ // strings
+ const char *xreaderName() const { Atomic<int>::barrier(); return readerName; }
+ void xreaderName(const char *rname, size_t len = MAX_READERNAME) { Atomic<int>::barrier(); strlcpy(readerName, rname, len); }
+ size_t readerNameLength() const { return strlen(readerName); }
+ void xreaderNameClear() { Atomic<int>::barrier(); memset(readerName, 0, sizeof(readerName)); }
+
+ const unsigned char *xcardAtr() const { Atomic<int>::barrier(); return cardAtr; }
+ unsigned char *xcardAtr() { Atomic<int>::barrier(); return cardAtr; }
+ void xcardAtr(const unsigned char *atr, size_t len) { Atomic<int>::barrier();
+ memcpy((char *)&cardAtr[0], (const char *)atr, len); cardAtrLength = htonl(len); }
+ size_t xcardAtrLength() const { Atomic<int>::barrier(); return ntohl(cardAtrLength); }
+ void xcardAtrLength(DWORD len) { Atomic<int>::barrier(); cardAtrLength = htonl(len); }
+ void xcardAtrClear() { Atomic<int>::barrier(); memset(cardAtr, 0, sizeof(cardAtr)); }
+};
+
+
+
+} // end namespace PCSCD
+
+#endif /* __cplusplus__ */
+
+#endif //_H_PCSCD_READER_STATE
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_generic.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_generic.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_generic.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * sys_generic.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ *
+ * $Id: sys_generic.h 2264 2006-12-03 13:15:03Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles abstract system level calls.
+ */
+
+#ifndef __sys_generic_h__
+#define __sys_generic_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <sys/stat.h>
+
+ int SYS_Initialize(void);
+
+ int SYS_Mkdir(const char *, int);
+
+ int SYS_GetPID(void);
+
+ int SYS_Sleep(int);
+
+ int SYS_USleep(int);
+
+ int SYS_OpenFile(const char *, int, int);
+
+ int SYS_CloseFile(int);
+
+ int SYS_RemoveFile(const char *);
+
+ int SYS_Chmod(const char *, int);
+
+ int SYS_Chdir(const char *);
+
+ int SYS_GetUID(void);
+
+ int SYS_GetGID(void);
+
+ int SYS_ChangePermissions(const char *, int);
+
+ int SYS_SeekFile(int, int);
+
+ int SYS_ReadFile(int, char *, int);
+
+ int SYS_WriteFile(int, const char *, int);
+
+ int SYS_GetPageSize(void);
+
+ void *SYS_MemoryMap(int, int, int);
+
+ void *SYS_PublicMemoryMap(int, int, int);
+
+ void SYS_PublicMemoryUnmap(void *, int);
+
+ int SYS_MMapSynchronize(void *, int);
+
+ int SYS_Fork(void);
+
+ int SYS_Daemon(int, int);
+
+ int SYS_Stat(const char *pcFile, struct stat *psStatus);
+
+ int SYS_Fstat(int);
+
+ int SYS_Random(int, float, float);
+
+ int SYS_GetSeed();
+
+ void SYS_Exit(int);
+
+ int SYS_Unlink(const char *pcFile);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __sys_generic_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_macosx.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_macosx.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_macosx.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,374 @@
+/*
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : sys_unix.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 11/8/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This handles abstract system level calls.
+
+$Id: sys_macosx.cpp,v 1.5.40.1 2005/06/17 22:40:12 mb Exp $
+
+********************************************************************/
+
+#include <sys_generic.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <time.h>
+#include "pcscexport.h"
+#include "debug.h"
+
+#include "pcscdmonitor.h"
+#include <securityd_client/ssclient.h>
+//#include <security_utilities/debugging.h>
+
+#include "config.h"
+
+
+extern "C" {
+
+int SYS_Initialize()
+{
+ /*
+ * Nothing special for OS X and Linux
+ */
+ return 0;
+}
+
+/**
+ * @brief Attempts to create a directory with some permissions.
+ *
+ * @param[in] path Path of the directory to be created.
+ * @param[in] perms Permissions to the new directory.
+ *
+ * @return Eror code.
+ * @retval 0 Success.
+ * @retval -1 An error occurred.
+ */
+INTERNAL int SYS_Mkdir(const char *path, int perms)
+{
+ return mkdir(path, perms);
+}
+
+/**
+ * @brief Gets the running process's ID.
+ *
+ * @return PID.
+ */
+INTERNAL int SYS_GetPID(void)
+{
+ return getpid();
+}
+
+/**
+ * @brief Makes the current process sleep for some seconds.
+ *
+ * @param[in] iTimeVal Number of seconds to sleep.
+ */
+INTERNAL int SYS_Sleep(int iTimeVal)
+{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = iTimeVal;
+ mrqtp.tv_nsec = 0;
+
+ return nanosleep(&mrqtp, NULL);
+#else
+ return sleep(iTimeVal);
+#endif
+}
+
+/**
+ * @brief Makes the current process sleep for some microseconds.
+ *
+ * @param[in] iTimeVal Number of microseconds to sleep.
+ */
+INTERNAL int SYS_USleep(int iTimeVal)
+{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = iTimeVal/1000000;
+ mrqtp.tv_nsec = (iTimeVal - (mrqtp.tv_sec * 1000000)) * 1000;
+
+ return nanosleep(&mrqtp, NULL);
+#else
+ usleep(iTimeVal);
+ return iTimeVal;
+#endif
+}
+
+/**
+ * @brief Opens/creates a file.
+ *
+ * @param[in] pcFile path to the file.
+ * @param[in] flags Open and read/write choices.
+ * @param[in] mode Permissions to the file.
+ *
+ * @return File descriptor.
+ * @retval >0 The file descriptor.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_OpenFile(const char *pcFile, int flags, int mode)
+{
+ return open(pcFile, flags, mode);
+}
+
+/**
+ * @brief Opens/creates a file.
+ *
+ * @param[in] iHandle File descriptor.
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_CloseFile(int iHandle)
+{
+ return close(iHandle);
+}
+
+/**
+ * @brief Removes a file.
+ *
+ * @param[in] pcFile path to the file.
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_RemoveFile(const char *pcFile)
+{
+ return remove(pcFile);
+}
+
+INTERNAL int SYS_Chmod(const char *path, int mode)
+{
+ return chmod(path, mode);
+}
+
+INTERNAL int SYS_Chdir(const char *path)
+{
+ return chdir(path);
+}
+
+int SYS_Mkfifo(const char *path, int mode)
+{
+ return mkfifo(path, mode);
+}
+
+int SYS_Mknod(const char *path, int mode, int dev)
+{
+ return mknod(path, mode, dev);
+}
+
+int SYS_GetUID()
+{
+ return getuid();
+}
+
+INTERNAL int SYS_GetGID(void)
+{
+ return getgid();
+}
+
+INTERNAL int SYS_SeekFile(int iHandle, int iSeekLength)
+{
+ int iOffset;
+ iOffset = lseek(iHandle, iSeekLength, SEEK_SET);
+ return iOffset;
+}
+
+INTERNAL int SYS_ReadFile(int iHandle, char *pcBuffer, int iLength)
+{
+ return read(iHandle, pcBuffer, iLength);
+}
+
+INTERNAL int SYS_WriteFile(int iHandle, const char *pcBuffer, int iLength)
+{
+ return write(iHandle, pcBuffer, iLength);
+}
+
+/**
+ * @brief Gets the memory page size.
+ *
+ * The page size is used when calling the \c SYS_MemoryMap() and
+ * \c SYS_PublicMemoryMap() functions.
+ *
+ * @return Number of bytes per page.
+ */
+INTERNAL int SYS_GetPageSize(void)
+{
+ return getpagesize();
+}
+
+/**
+ * @brief Map the file \p iFid in memory for reading and writing.
+ *
+ * @param[in] iSize Size of the memmory mapped.
+ * @param[in] iFid File which will be mapped in memory.
+ * @param[in] iOffset Start point of the file to be mapped in memory.
+ *
+ * @return Address of the memory map.
+ * @retval MAP_FAILED in case of error
+ */
+INTERNAL void *SYS_MemoryMap(int iSize, int iFid, int iOffset)
+{
+
+ void *vAddress;
+
+ vAddress = 0;
+ vAddress = mmap(0, iSize, PROT_READ | PROT_WRITE,
+ MAP_SHARED, iFid, iOffset);
+
+ /*
+ * Here are some common error types: switch( errno ) { case EINVAL:
+ * printf("EINVAL"); case EBADF: printf("EBADF"); break; case EACCES:
+ * printf("EACCES"); break; case EAGAIN: printf("EAGAIN"); break; case
+ * ENOMEM: printf("ENOMEM"); break; }
+ */
+
+ return vAddress;
+}
+
+/**
+ * @brief Map the file \p iFid in memory only for reading.
+ *
+ * @param[in] iSize Size of the memmory mapped.
+ * @param[in] iFid File which will be mapped in memory.
+ * @param[in] iOffset Start point of the file to be mapped in memory.
+ *
+ * @return Address of the memory map.
+ */
+INTERNAL void *SYS_PublicMemoryMap(int iSize, int iFid, int iOffset)
+{
+
+ void *vAddress;
+
+ vAddress = 0;
+ vAddress = mmap(0, iSize, PROT_READ, MAP_SHARED, iFid, iOffset);
+ if (vAddress == (void*)-1) /* mmap returns -1 on error */
+ {
+ Log2(PCSC_LOG_CRITICAL, "SYS_PublicMemoryMap() failed: %s",
+ strerror(errno));
+ vAddress = NULL;
+ }
+
+ return vAddress;
+}
+
+int SYS_MMapSynchronize(void *begin, int length)
+{
+ int rc = msync(begin, length, MS_SYNC | MS_INVALIDATE);
+
+ PCSCDMonitor::postNotification(SecurityServer::kNotificationPCSCStateChange);
+
+ return rc;
+}
+
+int SYS_MUnmap(void *begin, int length)
+{
+ return munmap(begin, length);
+}
+
+INTERNAL int SYS_Fork(void)
+{
+ return fork();
+}
+
+#ifdef HAVE_DAEMON
+int SYS_Daemon(int nochdir, int noclose)
+{
+ return daemon(nochdir, noclose);
+}
+#endif
+
+int SYS_Wait(int iPid, int iWait)
+{
+ return waitpid(-1, 0, WNOHANG);
+}
+
+INTERNAL int SYS_Stat(const char *pcFile, struct stat *psStatus)
+{
+ return stat(pcFile, psStatus);
+}
+
+int SYS_Fstat(int iFd)
+{
+ struct stat sStatus;
+ return fstat(iFd, &sStatus);
+}
+
+int SYS_Random(int iSeed, float fStart, float fEnd)
+{
+
+ int iRandNum = 0;
+
+ if (iSeed != 0)
+ {
+ srand(iSeed);
+ }
+
+ iRandNum = 1 + (int) (fEnd * rand() / (RAND_MAX + fStart));
+ srand(iRandNum);
+
+ return iRandNum;
+}
+
+INTERNAL int SYS_GetSeed(void)
+{
+ struct timeval tv;
+ struct timezone tz;
+ long myseed = 0;
+
+ tz.tz_minuteswest = 0;
+ tz.tz_dsttime = 0;
+ if (gettimeofday(&tv, &tz) == 0)
+ {
+ myseed = tv.tv_usec;
+ } else
+ {
+ myseed = (long) time(NULL);
+ }
+ return myseed;
+}
+
+INTERNAL void SYS_Exit(int iRetVal)
+{
+ _exit(iRetVal);
+}
+
+INTERNAL int SYS_Unlink(const char *pcFile)
+{
+ return unlink(pcFile);
+}
+
+} // extern "C"
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_unix.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_unix.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/sys_unix.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,404 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * sys_unix.c
+ * SmartCardServices
+ */
+
+/*
+ * This handles abstract system level calls.
+ *
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ *
+ * $Id: sys_unix.c 2353 2007-01-23 10:31:50Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles abstract system level calls.
+ */
+
+#include <sys_generic.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <time.h>
+#include <string.h>
+#include "debug.h"
+
+#include "config.h"
+#include "pcscexport.h"
+
+#include <security_utilities/debugging.h>
+
+/**
+ * @brief Make system wide initialization.
+ *
+ * @return Eror code.
+ * @retval 0 Success.
+ */
+INTERNAL int SYS_Initialize(void)
+{
+ /*
+ * Nothing special for OS X and Linux
+ */
+ return 0;
+}
+
+/**
+ * @brief Attempts to create a directory with some permissions.
+ *
+ * @param[in] path Path of the directory to be created.
+ * @param[in] perms Permissions to the new directory.
+ *
+ * @return Eror code.
+ * @retval 0 Success.
+ * @retval -1 An error occurred.
+ */
+INTERNAL int SYS_Mkdir(const char *path, int perms)
+{
+ return mkdir(path, perms);
+}
+
+/**
+ * @brief Gets the running process's ID.
+ *
+ * @return PID.
+ */
+INTERNAL int SYS_GetPID(void)
+{
+ return getpid();
+}
+
+/**
+ * @brief Makes the current process sleep for some seconds.
+ *
+ * @param[in] iTimeVal Number of seconds to sleep.
+ */
+INTERNAL int SYS_Sleep(int iTimeVal)
+{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = iTimeVal;
+ mrqtp.tv_nsec = 0;
+
+ return nanosleep(&mrqtp, NULL);
+#else
+ return sleep(iTimeVal);
+#endif
+}
+
+/**
+ * @brief Makes the current process sleep for some microseconds.
+ *
+ * @param[in] iTimeVal Number of microseconds to sleep.
+ */
+INTERNAL int SYS_USleep(int iTimeVal)
+{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = iTimeVal/1000000;
+ mrqtp.tv_nsec = (iTimeVal - (mrqtp.tv_sec * 1000000)) * 1000;
+
+ return nanosleep(&mrqtp, NULL);
+#else
+ usleep(iTimeVal);
+ return iTimeVal;
+#endif
+}
+
+/**
+ * @brief Opens/creates a file.
+ *
+ * @param[in] pcFile path to the file.
+ * @param[in] flags Open and read/write choices.
+ * @param[in] mode Permissions to the file.
+ *
+ * @return File descriptor.
+ * @retval >0 The file descriptor.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_OpenFile(const char *pcFile, int flags, int mode)
+{
+ return open(pcFile, flags, mode);
+}
+
+/**
+ * @brief Opens/creates a file.
+ *
+ * @param[in] iHandle File descriptor.
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_CloseFile(int iHandle)
+{
+ return close(iHandle);
+}
+
+/**
+ * @brief Removes a file.
+ *
+ * @param[in] pcFile path to the file.
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_RemoveFile(const char *pcFile)
+{
+ return remove(pcFile);
+}
+
+INTERNAL int SYS_Chmod(const char *path, int mode)
+{
+ return chmod(path, mode);
+}
+
+INTERNAL int SYS_Chdir(const char *path)
+{
+ return chdir(path);
+}
+
+INTERNAL int SYS_GetUID(void)
+{
+ return getuid();
+}
+
+INTERNAL int SYS_GetGID(void)
+{
+ return getgid();
+}
+
+INTERNAL int SYS_SeekFile(int iHandle, int iSeekLength)
+{
+ int iOffset;
+ iOffset = lseek(iHandle, iSeekLength, SEEK_SET);
+ return iOffset;
+}
+
+INTERNAL int SYS_ReadFile(int iHandle, char *pcBuffer, int iLength)
+{
+ return read(iHandle, pcBuffer, iLength);
+}
+
+INTERNAL int SYS_WriteFile(int iHandle, const char *pcBuffer, int iLength)
+{
+ return write(iHandle, pcBuffer, iLength);
+}
+
+/**
+ * @brief Gets the memory page size.
+ *
+ * The page size is used when calling the \c SYS_MemoryMap() and
+ * \c SYS_PublicMemoryMap() functions.
+ *
+ * @return Number of bytes per page.
+ */
+INTERNAL int SYS_GetPageSize(void)
+{
+ return getpagesize();
+}
+
+/**
+ * @brief Map the file \p iFid in memory for reading and writing.
+ *
+ * @param[in] iSize Size of the memmory mapped.
+ * @param[in] iFid File which will be mapped in memory.
+ * @param[in] iOffset Start point of the file to be mapped in memory.
+ *
+ * @return Address of the memory map.
+ * @retval MAP_FAILED in case of error
+ */
+INTERNAL void *SYS_MemoryMap(int iSize, int iFid, int iOffset)
+{
+
+ void *vAddress;
+
+ vAddress = 0;
+ vAddress = mmap(0, iSize, PROT_READ | PROT_WRITE,
+ MAP_SHARED, iFid, iOffset);
+
+ /*
+ * Here are some common error types: switch( errno ) { case EINVAL:
+ * printf("EINVAL"); case EBADF: printf("EBADF"); break; case EACCES:
+ * printf("EACCES"); break; case EAGAIN: printf("EAGAIN"); break; case
+ * ENOMEM: printf("ENOMEM"); break; }
+ */
+
+ return vAddress;
+}
+
+/**
+ * @brief Map the file \p iFid in memory only for reading.
+ *
+ * @param[in] iSize Size of the memmory mapped.
+ * @param[in] iFid File which will be mapped in memory.
+ * @param[in] iOffset Start point of the file to be mapped in memory.
+ *
+ * @return Address of the memory map.
+ */
+INTERNAL void *SYS_PublicMemoryMap(int iSize, int iFid, int iOffset)
+{
+
+ void *vAddress;
+
+ vAddress = 0;
+ vAddress = mmap(0, iSize, PROT_READ, MAP_SHARED, iFid, iOffset);
+ if (vAddress == (void*)-1) /* mmap returns -1 on error */
+ {
+ Log2(PCSC_LOG_CRITICAL, "SYS_PublicMemoryMap() failed: %s",
+ strerror(errno));
+ vAddress = NULL;
+ }
+
+ return vAddress;
+}
+
+/**
+ * @brief Unmap a memory segment
+ *
+ * @param ptr pointer returned by SYS_PublicMemoryMap()
+ * @param iSize size of the memory segment
+ */
+INTERNAL void SYS_PublicMemoryUnmap(void * ptr, int iSize)
+{
+ munmap(ptr, iSize);
+}
+
+/**
+ * @brief Writes the changes made in a memory map to the disk mapped file.
+ *
+ * @param[in] begin Start of the block to be written
+ * @param[in] length Lenght of the block to be written
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 An error ocurred.
+ */
+INTERNAL int SYS_MMapSynchronize(void *begin, int length)
+{
+ int flags = 0;
+
+#ifdef MS_INVALIDATE
+ flags |= MS_INVALIDATE;
+#endif
+ return msync(begin, length, MS_SYNC | flags);
+}
+
+INTERNAL int SYS_Fork(void)
+{
+ return fork();
+}
+
+/**
+ * @brief put the process to run in the background.
+ *
+ * @param[in] nochdir if zero, change the current directory to "/".
+ * @param[in] noclose if zero, redirect standard imput/output/error to /dev/nulll.
+ *
+ * @return error code.
+ * @retval 0 success.
+ * @retval -1 an error ocurred.
+ */
+INTERNAL int SYS_Daemon(int nochdir, int noclose)
+{
+#ifdef HAVE_DAEMON
+ return daemon(nochdir, noclose);
+}
+#endif
+
+int SYS_Wait(int iPid, int iWait)
+{
+ return waitpid(-1, 0, WNOHANG);
+}
+
+INTERNAL int SYS_Stat(const char *pcFile, struct stat *psStatus)
+{
+ return stat(pcFile, psStatus);
+}
+
+int SYS_Fstat(int iFd)
+{
+ struct stat sStatus;
+ return fstat(iFd, &sStatus);
+}
+
+int SYS_Random(int iSeed, float fStart, float fEnd)
+{
+
+ int iRandNum = 0;
+
+ if (iSeed != 0)
+ {
+ srand(iSeed);
+ }
+
+ iRandNum = 1 + (int) (fEnd * rand() / (RAND_MAX + fStart));
+ srand(iRandNum);
+
+ return iRandNum;
+}
+
+INTERNAL int SYS_GetSeed(void)
+{
+ struct timeval tv;
+ struct timezone tz;
+ long myseed = 0;
+
+ tz.tz_minuteswest = 0;
+ tz.tz_dsttime = 0;
+ if (gettimeofday(&tv, &tz) == 0)
+ {
+ myseed = tv.tv_usec;
+ } else
+ {
+ myseed = (long) time(NULL);
+ }
+ return myseed;
+}
+
+INTERNAL void SYS_Exit(int iRetVal)
+{
+ _exit(iRetVal);
+}
+
+INTERNAL int SYS_Unlink(const char *pcFile)
+{
+ return unlink(pcFile);
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/testpcsc.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/testpcsc.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/testpcsc.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : test.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 7/27/99
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This is a test program for pcsc-lite.
+
+********************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "pcsclite.h"
+#include "winscard.h"
+
+/*
+ * #define REPEAT_TEST 1
+ */
+
+int main(int argc, char **argv)
+{
+ SCARDHANDLE hCard;
+ SCARDCONTEXT hContext;
+ SCARD_READERSTATE_A rgReaderStates[1];
+ uint32_t dwReaderLen, dwState, dwProt, dwAtrLen;
+ // unsigned long dwSendLength, dwRecvLength;
+ uint32_t dwPref, dwReaders;
+ char *pcReaders, *mszReaders;
+ unsigned char pbAtr[MAX_ATR_SIZE];
+ const char *mszGroups;
+ long rv;
+ int i, p, iReader;
+ int iList[16];
+
+ int t = 0;
+
+ printf("\nMUSCLE PC/SC Lite Test Program\n\n");
+
+doInit:
+ printf("Testing SCardEstablishContext : ");
+ rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ return -1;
+ }
+
+ printf("Testing SCardGetStatusChange \n");
+ printf("Please insert a working reader : ");
+ rv = SCardGetStatusChange(hContext, INFINITE, 0, 0);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+ printf("Testing SCardListReaders : ");
+
+ mszGroups = 0;
+ rv = SCardListReaders(hContext, mszGroups, 0, &dwReaders);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+ mszReaders = (char *) malloc(sizeof(char) * dwReaders);
+ rv = SCardListReaders(hContext, mszGroups, mszReaders, &dwReaders);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+ /*
+ * Have to understand the multi-string here
+ */
+ p = 0;
+ for (i = 0; i < dwReaders - 1; i++)
+ {
+ ++p;
+ printf("Reader %02d: %s\n", p, &mszReaders[i]);
+ iList[p] = i;
+ while (mszReaders[++i] != 0) ;
+ }
+
+#ifdef REPEAT_TEST
+ if (t == 0)
+ {
+#endif
+
+ do
+ {
+ /* scanf doesn't provide a friendly way to 'throw away' the garbage input
+ * so we grab a line and then try to parse it */
+ size_t iScanLength;
+ char *sLine;
+ printf("Enter the reader number : ");
+ sLine = fgetln(stdin, &iScanLength);
+ if(sLine == NULL) /* EOF */
+ return 0;
+ /* Null terminate by replacing \n w/ \0*/
+ sLine[iScanLength - 1] = '\0';
+ iReader = atoi(sLine);
+ /* Since 0 is invalid input, no need to test errno */
+ if(iReader > p || iReader <= 0) {
+ printf("Invalid Value - try again\n");
+ }
+ }
+ while (iReader > p || iReader <= 0);
+
+#ifdef REPEAT_TEST
+ t = 1;
+ }
+#endif
+
+ rgReaderStates[0].szReader = &mszReaders[iList[iReader]];
+ rgReaderStates[0].dwCurrentState = SCARD_STATE_EMPTY;
+
+ printf("Waiting for card insertion \n");
+ rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
+
+ printf(" : %s\n",
+ pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+// printf(" context handle: %d [0x%08X]\n", hContext, hContext);
+ printf("Testing SCardConnect : ");
+ rv = SCardConnect(hContext, &mszReaders[iList[iReader]],
+ SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+ &hCard, &dwPref);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+ printf("Testing SCardStatus : ");
+
+ dwReaderLen = MAX_READERNAME;
+ pcReaders = (char *) malloc(sizeof(char) * MAX_READERNAME);
+ dwAtrLen = MAX_ATR_SIZE;
+
+ rv = SCardStatus(hCard, pcReaders, &dwReaderLen, &dwState, &dwProt,
+ pbAtr, &dwAtrLen);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ printf("Current Reader Name : %s\n", pcReaders);
+ printf("Current Reader State : 0x%X\n", dwState);
+ printf("Current Reader Protocol : 0x%X\n", dwProt - 1);
+ printf("Current Reader ATR Size : %d (0x%x)\n", dwAtrLen, dwAtrLen);
+ printf("Current Reader ATR Value : ");
+
+ for (i = 0; i < dwAtrLen; i++)
+ {
+ printf("%02X ", pbAtr[i]);
+ }
+ printf("\n");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardDisconnect(hCard, SCARD_RESET_CARD);
+ SCardReleaseContext(hContext);
+ }
+
+ printf("Testing SCardDisconnect : ");
+ rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ SCardReleaseContext(hContext);
+ return -1;
+ }
+
+ printf("Testing SCardReleaseContext : ");
+ rv = SCardReleaseContext(hContext);
+
+ printf("%s\n", pcsc_stringify_error(rv));
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ return -1;
+ }
+ if(t == 0) {
+ t = 1;
+ goto doInit;
+ }
+
+ printf("\n");
+ printf("PC/SC Test Completed Successfully !\n");
+
+ return 0;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_generic.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_generic.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_generic.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : thread_generic.h
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 3/24/00
+ License: Copyright (C) 2000 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This provides system specific thread calls.
+
+********************************************************************/
+
+#ifndef __thread_generic_h__
+#define __thread_generic_h__
+
+#include <pthread.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef WIN32
+#define PCSCLITE_THREAD_T HANDLE
+#define PCSCLITE_MUTEX CRITICAL_SECTION
+#define PCSCLITE_MUTEX_T CRITICAL_SECTION*
+#define PCSCLITE_THREAD_FUNCTION(f) void *(*f)(void *)
+#else
+#define PCSCLITE_THREAD_T pthread_t
+#define PCSCLITE_MUTEX pthread_mutex_t
+#define PCSCLITE_MUTEX_T pthread_mutex_t*
+#define PCSCLITE_THREAD_FUNCTION(f) void *(*f)(void *)
+#endif
+
+/* thread attributes */
+#define THREAD_ATTR_DEFAULT 0
+#define THREAD_ATTR_DETACHED 1
+
+ int SYS_MutexInit(PCSCLITE_MUTEX_T);
+ int SYS_MutexDestroy(PCSCLITE_MUTEX_T);
+ int SYS_MutexLock(PCSCLITE_MUTEX_T);
+ int SYS_MutexUnLock(PCSCLITE_MUTEX_T);
+ int SYS_ThreadCreate(PCSCLITE_THREAD_T *, int, PCSCLITE_THREAD_FUNCTION( ), LPVOID);
+ int SYS_ThreadCancel(PCSCLITE_THREAD_T *);
+ int SYS_ThreadDetach(PCSCLITE_THREAD_T);
+ int SYS_ThreadJoin(PCSCLITE_THREAD_T *, LPVOID*);
+ int SYS_ThreadExit(LPVOID);
+ PCSCLITE_THREAD_T SYS_ThreadSelf(void);
+ int SYS_ThreadEqual(PCSCLITE_THREAD_T *, PCSCLITE_THREAD_T *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __thread_generic_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_macosx.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_macosx.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/thread_macosx.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : thread_macosx.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 7/6/00
+ License: Copyright (C) 2000 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This handles thread function abstraction.
+
+********************************************************************/
+
+#include "config.h"
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "thread_generic.h"
+
+#define PCSC_MUTEX_LOCKED 1
+#define PCSC_MUTEX_UNLOCKED 0
+
+int SYS_MutexInit(PCSCLITE_MUTEX_T mMutex)
+{
+ int retval;
+ retval = pthread_mutex_init(mMutex, NULL);
+ return retval;
+}
+
+int SYS_MutexDestroy(PCSCLITE_MUTEX_T mMutex)
+{
+ int retval;
+ retval = pthread_mutex_destroy(mMutex);
+ return retval;
+}
+
+int SYS_MutexLock(PCSCLITE_MUTEX_T mMutex)
+{
+ int retval;
+ retval = pthread_mutex_lock(mMutex);
+ return retval;
+}
+
+int SYS_MutexUnLock(PCSCLITE_MUTEX_T mMutex)
+{
+ int retval;
+ retval = pthread_mutex_unlock(mMutex);
+ return retval;
+}
+
+int SYS_ThreadCreate(PCSCLITE_THREAD_T * pthThread, int attributes,
+ PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
+{
+ pthread_attr_t attr;
+ int rx;
+
+ if (0 != pthread_attr_init(&attr))
+ return 0;
+
+ if (attributes & THREAD_ATTR_DETACHED)
+ if (0 != pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))
+ {
+ pthread_attr_destroy(&attr);
+ return 0;
+ }
+
+ rx = pthread_create(pthThread, &attr, pvFunction, pvArg);
+
+ pthread_attr_destroy(&attr);
+
+ return (0 == rx); // return 1 if success, 0 otherwise
+}
+
+int SYS_ThreadCancel(PCSCLITE_THREAD_T * pthThread)
+{
+
+ int retval;
+ retval = pthread_cancel(*pthThread);
+
+ if (retval == 0)
+ {
+ return 1;
+ } else
+ {
+ return 0;
+ }
+}
+
+int SYS_ThreadDetach(PCSCLITE_THREAD_T pthThread)
+{
+ // Returns 1 (true) if thread detached OK, 0 (false) otherwise
+ if (pthThread)
+ return (pthread_detach(pthThread) == 0); // 0 result is success
+
+ return 0;
+}
+
+int SYS_ThreadJoin(PCSCLITE_THREAD_T *pthThread, LPVOID* pvRetVal)
+{
+
+ int retval;
+ retval = pthread_join(*pthThread, pvRetVal);
+
+ if (retval == 0)
+ {
+ return 1;
+ } else
+ {
+ return 0;
+ }
+}
+
+int SYS_ThreadExit(LPVOID pvRetVal)
+{
+
+ pthread_exit(pvRetVal);
+ return 1;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,787 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : tokenfactory.c
+ Package: pcsc lite
+ Author : David Corcoran
+ Date : 01/01/00
+ Purpose: This handles card abstraction attachment.
+
+ $Id: tokenfactory.c,v 1.3 2004/09/21 02:43:57 mb Exp $
+
+*******************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#ifndef WIN32
+#include <dirent.h>
+#include "config.h"
+#else
+#include "../win32/win32_config.h"
+#endif
+
+#include "debuglog.h"
+#include "dyn_generic.h"
+#include "tokenfactory.h"
+
+#define MSC_MANUMSC_KEY_NAME "spVendorName"
+#define MSC_PRODMSC_KEY_NAME "spProductName"
+#define MSC_ATRMSC_KEY_NAME "spAtrValue"
+#define MSC_LIBRMSC_KEY_NAME "CFBundleExecutable"
+#define MSC_DEFAULTAPP_NAME "spDefaultApplication"
+
+extern int LTPBundleFindValueWithKey(char *, char *, char *, int);
+
+int atrToString(MSCPUChar8 Atr, MSCULong32 Length, char *outAtr)
+{
+
+ int i;
+ int j;
+
+ j = 0;
+
+ for (i = 0; i < Length; i++)
+ {
+ if ((Atr[i] / 16) > 9)
+ {
+ outAtr[j] = ((Atr[i] / 16) - 10) + 'A';
+ } else
+ {
+ outAtr[j] = (Atr[i] / 16) + '0';
+ }
+
+ j += 1;
+
+ if ((Atr[i] % 16) > 9)
+ {
+ outAtr[j] = ((Atr[i] % 16) - 10) + 'A';
+ } else
+ {
+ outAtr[j] = (Atr[i] % 16) + '0';
+ }
+
+ j += 1;
+
+ }
+
+ outAtr[j] = 0; /* Add the NULL */
+
+ return 0;
+}
+
+int stringToBytes(char *inStr, MSCPUChar8 Buffer, MSCPULong32 Length)
+{
+
+ int i;
+ int j;
+ int inLen;
+
+ j = 0;
+ inLen = 0;
+
+ inLen = strlen(inStr);
+
+ if (inLen > MSC_MAXSIZE_AID)
+ {
+ return -1;
+ }
+
+ for (i = 0; i < inLen; i += 2)
+ {
+ if (inStr[i] <= '9' && inStr[i] >= '0')
+ {
+ Buffer[j] = (inStr[i] - '0') * 16;
+ } else if (inStr[i] <= 'F' && inStr[i] >= 'A')
+ {
+ Buffer[j] = (inStr[i] - 'A' + 10) * 16;
+ }
+
+ if (inStr[i + 1] <= '9' && inStr[i + 1] >= '0')
+ {
+ Buffer[j] += inStr[i + 1] - '0';
+ } else if (inStr[i + 1] <= 'F' && inStr[i + 1] >= 'A')
+ {
+ Buffer[j] += inStr[i + 1] - 'A' + 10;
+ }
+
+ j += 1;
+ }
+
+ *Length = j;
+
+ return 0;
+}
+
+MSCLong32 TPSearchBundlesForAtr(MSCPUChar8 Atr, MSCULong32 Length,
+ MSCLPTokenInfo tokenInfo)
+{
+
+ MSCLong32 rv;
+
+#ifndef WIN32
+ DIR *hpDir = 0;
+ struct dirent *currFP = 0;
+#else
+ HANDLE hFind;
+ WIN32_FIND_DATA findData;
+ char findPath[200];
+#endif
+
+ char atrString[100];
+ char fullPath[200];
+ char fullLibPath[250];
+ char keyValue[200];
+ int atrIndex;
+
+ rv = 0;
+ atrIndex = 0;
+
+ atrToString(Atr, Length, atrString);
+
+#ifndef WIN32
+
+ hpDir = opendir(MSC_SVC_DROPDIR);
+
+ if (hpDir == 0)
+#else
+ sprintf(findPath, "%s\\*.bundle", MSC_SVC_DROPDIR);
+ hFind = FindFirstFile(findPath, &findData);
+
+ if (hFind == INVALID_HANDLE_VALUE)
+#endif
+ {
+ DebugLogA("Cannot open PC/SC token drivers directory.\n");
+
+ return -1;
+ }
+
+#ifndef WIN32
+ while ((currFP = readdir(hpDir)) != 0)
+ {
+ if (strstr(currFP->d_name, ".bundle") != 0)
+#else
+ do
+ {
+ if (strstr(findData.cFileName, ".bundle") != 0)
+#endif
+ {
+
+ /*
+ * The bundle exists - let's form a full path name and get the
+ * vendor and product ID's for this particular bundle
+ */
+#ifndef WIN32
+ sprintf(fullPath, "%s%s%s", MSC_SVC_DROPDIR, currFP->d_name,
+ "/Contents/Info.plist");
+#else
+ sprintf(fullPath, "%s%s%s", MSC_SVC_DROPDIR, findData.cFileName,
+ "\\Contents\\Info.plist");
+#endif
+
+ atrIndex = 0;
+
+#ifdef MSC_DEBUG
+ DebugLogB("ATR comparison: FILE: %s\n", fullPath);
+ DebugLogB("ATR comparison: Target Match: %s\n", atrString);
+#endif
+
+ while (1)
+ {
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_ATRMSC_KEY_NAME, keyValue, atrIndex);
+ if (rv != 0)
+ {
+ break; /* No aliases found, break out of search
+ * aliases loop */
+ }
+#ifdef MSC_DEBUG
+ DebugLogB("ATR comparison: Source: %s\n", keyValue);
+#endif
+
+ if (strcmp(keyValue, atrString) != 0)
+ {
+ /*
+ * Go back and see if there are any aliases
+ */
+ atrIndex += 1;
+ continue;
+ }
+#ifdef MSC_DEBUG
+ DebugLogB("Match found at ATR alias %d\n", atrIndex);
+#endif
+
+ /*
+ * See if this bundle has a special name for this ATR
+ */
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_PRODMSC_KEY_NAME, keyValue, atrIndex);
+ if (rv != 0)
+ {
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_PRODMSC_KEY_NAME, keyValue, 0);
+ if (rv != 0)
+ {
+ DebugLogA
+ ("Match found, failed due to no product name.\n");
+#ifndef WIN32
+ closedir(hpDir);
+#endif
+ return -1;
+ }
+ }
+#ifdef MSC_DEBUG
+ DebugLogB("Product name: %s\n", keyValue);
+#endif
+ strcpy(tokenInfo->tokenName, keyValue);
+
+ /*
+ * See if this bundle has a special driver for this card
+ */
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_LIBRMSC_KEY_NAME, keyValue, atrIndex);
+ if (rv != 0)
+ {
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_LIBRMSC_KEY_NAME, keyValue, 0);
+ if (rv != 0)
+ {
+ DebugLogA
+ ("Match found, failed due to no library path.\n");
+#ifndef WIN32
+ closedir(hpDir);
+#endif
+ return -1;
+ }
+ }
+#ifdef WIN32
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ findData.cFileName, "\\Contents\\Win32\\", keyValue);
+#else
+#ifdef MSC_TARGET_LINUX
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/Linux/", keyValue);
+#else
+#ifdef MSC_TARGET_OSX
+ sprintf(fullLibPath, "%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name);
+
+#else
+#ifdef MSC_TARGET_BSD
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/BSD/", keyValue);
+
+#else
+#ifdef MSC_TARGET_SOLARIS
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/Solaris/", keyValue);
+
+#else
+#ifdef MSC_TARGET_HPUX
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/HPUX/", keyValue);
+
+#else
+#ifdef MSC_TARGET_TRU64
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/Tru64/", keyValue);
+
+#else
+#ifdef MSC_TARGET_CYGWIN
+ sprintf(fullLibPath, "%s%s%s%s", MSC_SVC_DROPDIR,
+ currFP->d_name, "/Contents/CygWin/", keyValue);
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+
+ if (fullLibPath == NULL)
+ {
+ DebugLogA("No path to bundle library found !\n");
+ return -1;
+ }
+
+ /*
+ * Copy the library path and return successfully
+ */
+ strcpy(tokenInfo->svProvider, fullLibPath);
+
+ /*
+ * See if this bundle has a default AID
+ */
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_DEFAULTAPP_NAME, keyValue, atrIndex);
+ if (rv != 0)
+ {
+ rv = LTPBundleFindValueWithKey(fullPath,
+ MSC_DEFAULTAPP_NAME, keyValue, 0);
+ }
+
+ if (rv == 0)
+ {
+#ifdef MSC_DEBUG
+ DebugLogB("Default AID name: %s\n", keyValue);
+#endif
+ rv = stringToBytes(keyValue, tokenInfo->tokenApp,
+ &tokenInfo->tokenAppLen);
+ if (rv != 0)
+ {
+ DebugLogA
+ ("Match found, failed due to malformed aid string.\n");
+#ifndef WIN32
+ closedir(hpDir);
+#endif
+ return -1;
+ }
+
+ } else
+ {
+ DebugLogA("No AID specified in bundle\n");
+ tokenInfo->tokenAppLen = 0;
+ }
+
+#ifndef WIN32
+ closedir(hpDir);
+#endif
+ return 0;
+
+ } /* do ... while */
+ } /* if .bundle */
+ } /* while readdir */
+#ifdef WIN32
+ // This is part of a Do..While loop (see above)
+ while (FindNextFile(hFind, &findData) != 0);
+#endif
+
+#ifndef WIN32
+ closedir(hpDir);
+#endif
+ return -1;
+}
+
+const char *TPSvcDropdir(void)
+{
+ const char *dropDir = getenv(MSC_SVC_DROPDIR_ENV);
+ if (dropDir)
+ return dropDir;
+
+ return MSC_SVC_DROPDIR_DEFAULT;
+}
+
+MSCLong32 TPLoadToken(MSCLPTokenConnection pConnection)
+{
+
+ MSCLong32 rv;
+
+ pConnection->libPointers.pvfWriteFramework = 0;
+ pConnection->libPointers.pvfInitializePlugin = 0;
+ pConnection->libPointers.pvfFinalizePlugin = 0;
+ pConnection->libPointers.pvfGetStatus = 0;
+ pConnection->libPointers.pvfGetCapabilities = 0;
+ pConnection->libPointers.pvfExtendedFeature = 0;
+ pConnection->libPointers.pvfGenerateKeys = 0;
+ pConnection->libPointers.pvfImportKey = 0;
+ pConnection->libPointers.pvfExportKey = 0;
+ pConnection->libPointers.pvfComputeCrypt = 0;
+ pConnection->libPointers.pvfExtAuthenticate = 0;
+ pConnection->libPointers.pvfListKeys = 0;
+ pConnection->libPointers.pvfCreatePIN = 0;
+ pConnection->libPointers.pvfVerifyPIN = 0;
+ pConnection->libPointers.pvfChangePIN = 0;
+ pConnection->libPointers.pvfUnblockPIN = 0;
+ pConnection->libPointers.pvfListPINs = 0;
+ pConnection->libPointers.pvfCreateObject = 0;
+ pConnection->libPointers.pvfDeleteObject = 0;
+ pConnection->libPointers.pvfWriteObject = 0;
+ pConnection->libPointers.pvfReadObject = 0;
+ pConnection->libPointers.pvfListObjects = 0;
+ pConnection->libPointers.pvfLogoutAll = 0;
+ pConnection->libPointers.pvfGetChallenge = 0;
+
+ /*
+ * Find the Card's Library
+ */
+
+ rv = TPSearchBundlesForAtr(pConnection->tokenInfo.tokenId,
+ pConnection->tokenInfo.tokenIdLength, &pConnection->tokenInfo);
+
+ if (rv != 0)
+ {
+ DebugLogA("Error: Matching Token ATR Not Found.\n");
+ log_xxd(PCSC_LOG_INFO, "ATR : ", pConnection->tokenInfo.tokenId,
+ pConnection->tokenInfo.tokenIdLength);
+
+ return SCARD_E_CARD_UNSUPPORTED;
+ }
+
+ /*
+ * Load that library and store the handle in the SCARDCHANNEL
+ * structure
+ */
+
+ rv = DYN_LoadLibrary(&pConnection->tokenLibHandle,
+ pConnection->tokenInfo.svProvider);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ DebugLogA("Error: Could not load service library\n");
+ DebugLogB("->> %s\n", pConnection->tokenInfo.svProvider);
+ return SCARD_E_INVALID_TARGET;
+ } else
+ {
+ DebugLogB("Loading service library %s\n",
+ pConnection->tokenInfo.svProvider);
+ }
+
+ rv = TPBindFunctions(pConnection);
+
+ return rv;
+}
+
+MSCLong32 TPUnloadToken(MSCLPTokenConnection pConnection)
+{
+
+ MSCLong32 rv;
+
+ if (pConnection->tokenLibHandle == 0)
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ rv = DYN_CloseLibrary(&pConnection->tokenLibHandle);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ return rv;
+ }
+
+ pConnection->tokenLibHandle = 0;
+ return TPUnbindFunctions(pConnection);
+}
+
+MSCLong32 TPBindFunctions(MSCLPTokenConnection pConnection)
+{
+
+ MSCLong32 rv;
+
+ if (pConnection->tokenLibHandle == 0)
+ {
+ return SCARD_E_INVALID_TARGET;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfWriteFramework,
+ "PL_MSCWriteFramework");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfWriteFramework = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ /*
+ * No big deal - this feature is just not supported
+ */
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfIdentifyToken, "PL_MSCIdentifyToken");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfIdentifyToken = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfInitializePlugin,
+ "PL_MSCInitializePlugin");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfInitializePlugin = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfFinalizePlugin,
+ "PL_MSCFinalizePlugin");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfFinalizePlugin = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfGetStatus, "PL_MSCGetStatus");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfGetStatus = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfGetCapabilities,
+ "PL_MSCGetCapabilities");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfGetCapabilities = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfExtendedFeature,
+ "PL_MSCExtendedFeature");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfExtendedFeature = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ /*
+ * No big deal - there are no extended features
+ */
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfGenerateKeys, "PL_MSCGenerateKeys");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfGenerateKeys = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfImportKey, "PL_MSCImportKey");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfImportKey = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfExportKey, "PL_MSCExportKey");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfExportKey = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfComputeCrypt, "PL_MSCComputeCrypt");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfComputeCrypt = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfExtAuthenticate,
+ "PL_MSCExtAuthenticate");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfExtAuthenticate = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfListKeys, "PL_MSCListKeys");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfListKeys = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfCreatePIN, "PL_MSCCreatePIN");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfCreatePIN = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfVerifyPIN, "PL_MSCVerifyPIN");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfVerifyPIN = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfChangePIN, "PL_MSCChangePIN");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfChangePIN = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfUnblockPIN, "PL_MSCUnblockPIN");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfUnblockPIN = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfListPINs, "PL_MSCListPINs");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfListPINs = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfCreateObject, "PL_MSCCreateObject");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfCreateObject = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfDeleteObject, "PL_MSCDeleteObject");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfDeleteObject = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfWriteObject, "PL_MSCWriteObject");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfWriteObject = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfReadObject, "PL_MSCReadObject");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfReadObject = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfListObjects, "PL_MSCListObjects");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfListObjects = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfLogoutAll, "PL_MSCLogoutAll");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfLogoutAll = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ rv = DYN_GetAddress(pConnection->tokenLibHandle,
+ &pConnection->libPointers.pvfGetChallenge, "PL_MSCGetChallenge");
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ pConnection->libPointers.pvfGetChallenge = 0;
+ DebugLogA("TPBindFunctions: Missing functions");
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+MSCLong32 TPUnbindFunctions(MSCLPTokenConnection pConnection)
+{
+
+ pConnection->libPointers.pvfWriteFramework = 0;
+ pConnection->libPointers.pvfInitializePlugin = 0;
+ pConnection->libPointers.pvfFinalizePlugin = 0;
+ pConnection->libPointers.pvfGetStatus = 0;
+ pConnection->libPointers.pvfGetCapabilities = 0;
+ pConnection->libPointers.pvfExtendedFeature = 0;
+ pConnection->libPointers.pvfGenerateKeys = 0;
+ pConnection->libPointers.pvfImportKey = 0;
+ pConnection->libPointers.pvfExportKey = 0;
+ pConnection->libPointers.pvfComputeCrypt = 0;
+ pConnection->libPointers.pvfExtAuthenticate = 0;
+ pConnection->libPointers.pvfListKeys = 0;
+ pConnection->libPointers.pvfCreatePIN = 0;
+ pConnection->libPointers.pvfVerifyPIN = 0;
+ pConnection->libPointers.pvfChangePIN = 0;
+ pConnection->libPointers.pvfUnblockPIN = 0;
+ pConnection->libPointers.pvfListPINs = 0;
+ pConnection->libPointers.pvfCreateObject = 0;
+ pConnection->libPointers.pvfDeleteObject = 0;
+ pConnection->libPointers.pvfWriteObject = 0;
+ pConnection->libPointers.pvfReadObject = 0;
+ pConnection->libPointers.pvfListObjects = 0;
+ pConnection->libPointers.pvfLogoutAll = 0;
+ pConnection->libPointers.pvfGetChallenge = 0;
+
+ return SCARD_S_SUCCESS;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenfactory.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : tokenfactory.h
+ Package: pcsc-lite
+ Author : David Corcoran
+ Date : 01/01/00
+ Purpose: This handles card abstraction attachment.
+
+********************************************************************/
+
+#ifndef __cardfactory_h__
+#define __cardfactory_h__
+
+#include "mscdefines.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef WIN32
+#ifndef MSC_SVC_DROPDIR
+#define MSC_SVC_DROPDIR TPSvcDropdir()
+#define MSC_SVC_DROPDIR_DEFAULT "/usr/libexec/SmartCardServices/services/"
+#define MSC_SVC_DROPDIR_ENV "MSC_SVC_DROPDIR"
+#endif
+#else
+#define MSC_SVC_DROPDIR "C:\\Program Files\\Muscle\\Services\\"
+#endif
+
+ const char *TPSvcDropdir(void);
+ MSCLong32 TPLoadToken(MSCLPTokenConnection);
+ MSCLong32 TPUnloadToken(MSCLPTokenConnection);
+ MSCLong32 TPBindFunctions(MSCLPTokenConnection);
+ MSCLong32 TPUnbindFunctions(MSCLPTokenConnection);
+ MSCLong32 TPSearchBundlesForAtr(MSCPUChar8 Atr, MSCULong32 Length,
+ MSCLPTokenInfo tokenInfo);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __cardfactory_h__ */
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1775 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+#ifdef WIN32
+#include <malloc.h>
+#include <stdlib.h>
+#endif
+
+#define yy_create_buffer tp_create_buffer
+#define yy_delete_buffer tp_delete_buffer
+#define yy_scan_buffer tp_scan_buffer
+#define yy_scan_string tp_scan_string
+#define yy_scan_bytes tp_scan_bytes
+#define yy_flex_debug tp_flex_debug
+#define yy_init_buffer tp_init_buffer
+#define yy_flush_buffer tp_flush_buffer
+#define yy_load_buffer_state tp_load_buffer_state
+#define yy_switch_to_buffer tp_switch_to_buffer
+#define yyin tpin
+#define yyleng tpleng
+#define yylex tplex
+#define yyout tpout
+#define yyrestart tprestart
+#define yytext tptext
+#define yywrap tpwrap
+
+/*
+ * A lexical scanner generated by flex
+ */
+
+/*
+ * Scanner skeleton version: $Header:
+ * /home/cvsroot/muscle/PCSC/src/tokenparser.c,v 1.2 2002/03/30 20:59:07
+ * corcoran Exp $
+ */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 5
+
+#include <stdio.h>
+
+/*
+ * cfront 1.2 defines "c_plusplus" instead of "__cplusplus"
+ */
+#ifdef c_plusplus
+#ifndef __cplusplus
+#define __cplusplus
+#endif
+#endif
+
+#ifdef __cplusplus
+
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * Use prototypes in function declarations.
+ */
+#define YY_USE_PROTOS
+
+/*
+ * The "const" storage-class-modifier is valid.
+ */
+#define YY_USE_CONST
+
+#else /* ! __cplusplus */
+
+#if __STDC__
+
+#define YY_USE_PROTOS
+#define YY_USE_CONST
+
+#endif /* __STDC__ */
+#endif /* ! __cplusplus */
+
+#ifdef __TURBOC__
+#pragma warn -rch
+#pragma warn -use
+#include <io.h>
+#include <stdlib.h>
+#define YY_USE_CONST
+#define YY_USE_PROTOS
+#endif
+
+#ifdef YY_USE_CONST
+#define yyconst const
+#else
+#define yyconst
+#endif
+
+#ifdef YY_USE_PROTOS
+#define YY_PROTO(proto) proto
+#else
+#define YY_PROTO(proto) ()
+#endif
+
+/*
+ * Returned upon end-of-file.
+ */
+#define YY_NULL 0
+
+/*
+ * Promotes a possibly negative, possibly signed char to an unsigned
+ * integer for use as an array index. If the signed char is negative, we
+ * want to instead treat it as an 8-bit unsigned char, hence the double
+ * cast.
+ */
+#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+
+/*
+ * Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN yy_start = 1 + 2 *
+
+/*
+ * Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START ((yy_start - 1) / 2)
+#define YYSTATE YY_START
+
+/*
+ * Action number for EOF rule of a given start state.
+ */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+
+/*
+ * Special action meaning "start processing a new file".
+ */
+#define YY_NEW_FILE yyrestart( yyin )
+
+#define YY_END_OF_BUFFER_CHAR 0
+
+/*
+ * Size of default input buffer.
+ */
+#define YY_BUF_SIZE 16384
+
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+
+extern int yyleng;
+extern FILE *yyin, *yyout;
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+/*
+ * The funky do-while in the following #define is used to turn the
+ * definition int a single C statement (which needs a semi-colon
+ * terminator). This avoids problems with code like: if (
+ * condition_holds ) yyless( 5 ); else do_something_else(); Prior to
+ * using the do-while the compiler would get upset at the "else" because
+ * it interpreted the "if" statement as being all done when it reached the
+ * ';' after the yyless() call.
+ */
+
+/*
+ * Return all but the first 'n' matched characters back to the input
+ * stream.
+ */
+
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ *yy_cp = yy_hold_char; \
+ YY_RESTORE_YY_MORE_OFFSET \
+ yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up yytext again */ \
+ } \
+ while ( 0 )
+
+#define unput(c) yyunput( c, yytext_ptr )
+
+/*
+ * The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ */
+typedef unsigned int yy_size_t;
+
+struct yy_buffer_state
+{
+ FILE *yy_input_file;
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /*
+ * Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ yy_size_t yy_buf_size;
+
+ /*
+ * Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /*
+ * Whether we "own" the buffer - i.e., we know we created it, and can
+ * realloc() it to grow it, and should free() it to delete it.
+ */
+ int yy_is_our_buffer;
+
+ /*
+ * Whether this is an "interactive" input source; if so, and if we're
+ * using stdio for input, then we want to use getc() instead of
+ * fread(), to make sure we stop fetching input after each newline.
+ */
+ int yy_is_interactive;
+
+ /*
+ * Whether we're considered to be at the beginning of a line. If so,
+ * '^' rules will be active on the next match, otherwise not.
+ */
+ int yy_at_bol;
+
+ /*
+ * Whether to try to fill the input buffer when we reach the end of
+ * it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /*
+ * When an EOF's been seen but there's still some text to process then
+ * we mark the buffer as YY_EOF_PENDING, to indicate that we shouldn't
+ * try reading from the input source any more. We might still have a
+ * bunch of tokens to match, though, because of possible backing-up.
+ * When we actually see the EOF, we change the status to "new" (via
+ * yyrestart()), so that the user can continue scanning by just
+ * pointing yyin at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+};
+
+static YY_BUFFER_STATE yy_current_buffer = 0;
+
+/*
+ * We provide macros for accessing buffer states in case in the future we
+ * want to put the buffer states in a more general "scanner state".
+ */
+#define YY_CURRENT_BUFFER yy_current_buffer
+
+/*
+ * yy_hold_char holds the character lost when yytext is formed.
+ */
+static char yy_hold_char;
+
+static int yy_n_chars; /* number of characters read into
+ * yy_ch_buf */
+
+int yyleng;
+
+/*
+ * Points to current character in buffer.
+ */
+static char *yy_c_buf_p = (char *) 0;
+static int yy_init = 1; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/*
+ * Flag which is used to allow yywrap()'s to do buffer switches instead of
+ * setting up a fresh yyin. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+
+void yyrestart YY_PROTO((FILE * input_file));
+
+void yy_switch_to_buffer YY_PROTO((YY_BUFFER_STATE new_buffer));
+void yy_load_buffer_state YY_PROTO((void));
+YY_BUFFER_STATE yy_create_buffer YY_PROTO((FILE * file, int size));
+void yy_delete_buffer YY_PROTO((YY_BUFFER_STATE b));
+void yy_init_buffer YY_PROTO((YY_BUFFER_STATE b, FILE * file));
+void yy_flush_buffer YY_PROTO((YY_BUFFER_STATE b));
+#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer )
+
+YY_BUFFER_STATE yy_scan_buffer YY_PROTO((char *base, yy_size_t size));
+YY_BUFFER_STATE yy_scan_string YY_PROTO((yyconst char *yy_str));
+YY_BUFFER_STATE yy_scan_bytes YY_PROTO((yyconst char *bytes, int len));
+
+static void *yy_flex_alloc YY_PROTO((yy_size_t));
+static void *yy_flex_realloc YY_PROTO((void *, yy_size_t));
+static void yy_flex_free YY_PROTO((void *));
+
+#define yy_new_buffer yy_create_buffer
+
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_is_interactive = is_interactive; \
+ }
+
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! yy_current_buffer ) \
+ yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \
+ yy_current_buffer->yy_at_bol = at_bol; \
+ }
+
+#define YY_AT_BOL() (yy_current_buffer->yy_at_bol)
+
+typedef unsigned char YY_CHAR;
+FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
+typedef int yy_state_type;
+extern char *yytext;
+#define yytext_ptr yytext
+
+static yy_state_type yy_get_previous_state YY_PROTO((void));
+static yy_state_type yy_try_NUL_trans YY_PROTO((yy_state_type
+ current_state));
+static int yy_get_next_buffer YY_PROTO((void));
+static void yy_fatal_error YY_PROTO((yyconst char msg[]));
+
+/*
+ * Done after the current pattern has been matched and before the
+ * corresponding action - sets up yytext.
+ */
+#define YY_DO_BEFORE_ACTION \
+ yytext_ptr = yy_bp; \
+ yyleng = (int) (yy_cp - yy_bp); \
+ yy_hold_char = *yy_cp; \
+ *yy_cp = '\0'; \
+ yy_c_buf_p = yy_cp;
+
+#define YY_NUM_RULES 7
+#define YY_END_OF_BUFFER 8
+static yyconst short int yy_accept[39] = { 0,
+ 0, 0, 8, 6, 4, 2, 1, 6, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
+ 0, 0, 0, 0, 0, 0, 5, 0
+};
+
+static yyconst int yy_ec[256] = { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 4, 4, 5, 4, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 4, 6, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 4, 1, 8,
+ 4, 9, 4, 4, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+ 1, 1, 1, 4, 4, 1, 11, 11, 11, 11,
+
+ 12, 11, 13, 11, 14, 11, 15, 11, 11, 16,
+ 11, 11, 11, 17, 18, 19, 11, 11, 11, 11,
+ 20, 11, 1, 1, 1, 4, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1
+};
+
+static yyconst int yy_meta[21] = { 0,
+ 1, 2, 3, 4, 4, 4, 2, 1, 1, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
+};
+
+static yyconst short int yy_base[43] = { 0,
+ 0, 7, 49, 50, 50, 50, 0, 1, 0, 36,
+ 28, 26, 28, 35, 29, 0, 26, 33, 27, 33,
+ 29, 22, 0, 24, 27, 14, 27, 23, 13, 50,
+ 10, 9, 4, 1, 0, 2, 50, 50, 19, 23,
+ 2, 26
+};
+
+static yyconst short int yy_def[43] = { 0,
+ 39, 39, 38, 38, 38, 38, 40, 38, 40, 38,
+ 38, 38, 38, 38, 38, 41, 38, 41, 38, 38,
+ 38, 38, 42, 38, 42, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 0, 38, 38,
+ 38, 38
+};
+
+static yyconst short int yy_nxt[71] = { 0,
+ 38, 5, 6, 18, 7, 38, 38, 8, 5, 6,
+ 37, 7, 36, 38, 8, 10, 35, 34, 11, 4,
+ 4, 4, 4, 9, 9, 33, 9, 25, 32, 25,
+ 31, 30, 29, 28, 27, 26, 24, 23, 22, 21,
+ 20, 19, 17, 16, 15, 14, 13, 12, 38, 3,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38
+};
+
+static yyconst short int yy_chk[71] = { 0,
+ 0, 1, 1, 41, 1, 0, 0, 1, 2, 2,
+ 36, 2, 35, 0, 2, 8, 34, 33, 8, 39,
+ 39, 39, 39, 40, 40, 32, 40, 42, 31, 42,
+ 29, 28, 27, 26, 25, 24, 22, 21, 20, 19,
+ 18, 17, 15, 14, 13, 12, 11, 10, 3, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
+ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38
+};
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+/*
+ * The intent behind this definition is that it'll catch any uses of
+ * REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *yytext;
+#line 1 "tokenparser.l"
+#define INITIAL 0
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+#line 14 "tokenparser.l"
+
+void tpevalToken(char *pcToken, int tokType);
+
+static char *pcDesiredKey = 0;
+static char pcKey[200];
+static char pcValue[200];
+static char pcFinValue[200];
+static int valueIndex = 0;
+static int desiredIndex = 0;
+
+void tperrorCheck(char *pcToken_error);
+
+#line 429 "lex.tp.c"
+
+/*
+ * Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int yywrap YY_PROTO((void));
+#else
+extern int yywrap YY_PROTO((void));
+#endif
+#endif
+
+#ifndef YY_NO_UNPUT
+static void yyunput YY_PROTO((int c, char *buf_ptr));
+#endif
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy YY_PROTO((char *, yyconst char *, int));
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen YY_PROTO((yyconst char *));
+#endif
+
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+static int yyinput YY_PROTO((void));
+#else
+static int input YY_PROTO((void));
+#endif
+#endif
+
+#if YY_STACK_USED
+static int yy_start_stack_ptr = 0;
+static int yy_start_stack_depth = 0;
+static int *yy_start_stack = 0;
+#ifndef YY_NO_PUSH_STATE
+static void yy_push_state YY_PROTO((int new_state));
+#endif
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state YY_PROTO((void));
+#endif
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state YY_PROTO((void));
+#endif
+
+#else
+#define YY_NO_PUSH_STATE 1
+#define YY_NO_POP_STATE 1
+#define YY_NO_TOP_STATE 1
+#endif
+
+#ifdef YY_MALLOC_DECL
+YY_MALLOC_DECL
+#else
+#if __STDC__
+#ifndef __cplusplus
+#include <stdlib.h>
+#endif
+#else
+/*
+ * Just try to get by without declaring the routines. This will fail
+ * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int)
+ * or sizeof(void*) != sizeof(int).
+ */
+#endif
+#endif
+
+/*
+ * Amount of stuff to slurp up with each read.
+ */
+#ifndef YY_READ_BUF_SIZE
+#define YY_READ_BUF_SIZE 8192
+#endif
+
+/*
+ * Copy whatever the last rule matched to the standard output.
+ */
+
+#ifndef ECHO
+/*
+ * This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
+#endif
+
+/*
+ * Gets input and stuffs it into "buf". number of characters read, or
+ * YY_NULL, is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+ if ( yy_current_buffer->yy_is_interactive ) \
+ { \
+ int c = '*', n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
+ && ferror( yyin ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+#endif
+
+/*
+ * No semi-colon after return; correct usage is to write "yyterminate();"
+ * - we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/*
+ * Number of entries by which start-condition stack grows.
+ */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/*
+ * Report a fatal error.
+ */
+#ifndef YY_FATAL_ERROR
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+#endif
+
+/*
+ * Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL int yylex YY_PROTO(( void ))
+#endif
+
+/*
+ * Code executed at the beginning of each rule, after yytext and yyleng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/*
+ * Code executed at the end of each rule.
+ */
+#ifndef YY_BREAK
+#define YY_BREAK break;
+#endif
+
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+YY_DECL
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp, *yy_bp;
+ register int yy_act;
+
+#line 28 "tokenparser.l"
+
+#line 583 "lex.tp.c"
+
+ if (yy_init)
+ {
+ yy_init = 0;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if (!yy_start)
+ yy_start = 1; /* first start state */
+
+ if (!yyin)
+ yyin = stdin;
+
+ if (!yyout)
+ yyout = stdout;
+
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_load_buffer_state();
+ }
+
+ while (1) /* loops until end-of-file is reached */
+ {
+ yy_cp = yy_c_buf_p;
+
+ /*
+ * Support of yytext.
+ */
+ *yy_cp = yy_hold_char;
+
+ /*
+ * yy_bp points to the position in yy_ch_buf of the start of the
+ * current run.
+ */
+ yy_bp = yy_cp;
+
+ yy_current_state = yy_start;
+ yy_match:
+ do
+ {
+ register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ ++yy_cp;
+ }
+ while (yy_base[yy_current_state] != 50);
+
+ yy_find_action:
+ yy_act = yy_accept[yy_current_state];
+ if (yy_act == 0)
+ { /* have to back up */
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ yy_act = yy_accept[yy_current_state];
+ }
+
+ YY_DO_BEFORE_ACTION;
+
+ do_action: /* This label is used only to access EOF actions. */
+
+ switch (yy_act)
+ { /* beginning of action switch */
+ case 0: /* must back up */
+ /*
+ * undo the effects of YY_DO_BEFORE_ACTION
+ */
+ *yy_cp = yy_hold_char;
+ yy_cp = yy_last_accepting_cpos;
+ yy_current_state = yy_last_accepting_state;
+ goto yy_find_action;
+
+ case 1:
+ YY_RULE_SETUP
+#line 30 "tokenparser.l"
+ {
+ }
+ YY_BREAK case 2:
+ YY_RULE_SETUP
+#line 31 "tokenparser.l"
+ {
+ }
+ YY_BREAK case 3:
+ YY_RULE_SETUP
+#line 32 "tokenparser.l"
+ {
+ valueIndex = 0;
+ tpevalToken(yytext, 1);
+ }
+ YY_BREAK case 4:
+ YY_RULE_SETUP
+#line 33 "tokenparser.l"
+ {
+ }
+ YY_BREAK case 5:
+ YY_RULE_SETUP
+#line 34 "tokenparser.l"
+ {
+ tpevalToken(yytext, 2);
+ valueIndex += 1;
+ }
+ YY_BREAK case 6:
+ YY_RULE_SETUP
+#line 35 "tokenparser.l"
+ {
+ tperrorCheck(yytext);
+ }
+ YY_BREAK case 7:
+ YY_RULE_SETUP
+#line 36 "tokenparser.l"
+ ECHO;
+ YY_BREAK
+#line 701 "lex.tp.c"
+ case YY_STATE_EOF(INITIAL):
+ yyterminate();
+
+ case YY_END_OF_BUFFER:
+ {
+ /*
+ * Amount of text matched not including the EOB char.
+ */
+ int yy_amount_of_matched_text =
+ (int) (yy_cp - yytext_ptr) - 1;
+
+ /*
+ * Undo the effects of YY_DO_BEFORE_ACTION.
+ */
+ *yy_cp = yy_hold_char;
+ YY_RESTORE_YY_MORE_OFFSET
+ if (yy_current_buffer->yy_buffer_status ==
+ YY_BUFFER_NEW)
+ {
+ /*
+ * We're scanning a new file or input source. It's
+ * possible that this happened because the user just
+ * pointed yyin at a new source and called yylex().
+ * If so, then we have to assure consistency between
+ * yy_current_buffer and our globals. Here is the
+ * right place to do so, because this is the first
+ * action (other than possibly a back-up) that will
+ * match for the new input source.
+ */
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yy_current_buffer->yy_input_file = yyin;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /*
+ * Note that here we test for yy_c_buf_p "<=" to the
+ * position of the first EOB in the buffer, since
+ * yy_c_buf_p will already have been incremented past the
+ * NUL character (since all states make transitions on EOB
+ * to the end-of-buffer state). Contrast this with the
+ * test in input().
+ */
+ if (yy_c_buf_p <=
+ &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ /*
+ * Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it for us
+ * because it doesn't know how to deal with the
+ * possibility of jamming (and we don't want to build
+ * jamming into it because then it will run more
+ * slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans(yy_current_state);
+
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+
+ if (yy_next_state)
+ {
+ /*
+ * Consume the NUL.
+ */
+ yy_cp = ++yy_c_buf_p;
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+ yy_cp = yy_c_buf_p;
+ goto yy_find_action;
+ }
+ }
+
+ else
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ yy_did_buffer_switch_on_eof = 0;
+
+ if (yywrap())
+ {
+ /*
+ * Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * yytext, we can now set up yy_c_buf_p so
+ * that if some total hoser (like flex
+ * itself) wants to call the scanner after
+ * we return the YY_NULL, it'll still work
+ * - another YY_NULL will get returned.
+ */
+ yy_c_buf_p = yytext_ptr + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p =
+ yytext_ptr + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ yy_c_buf_p =
+ &yy_current_buffer->yy_ch_buf[yy_n_chars];
+
+ yy_current_state = yy_get_previous_state();
+
+ yy_cp = yy_c_buf_p;
+ yy_bp = yytext_ptr + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--no action found");
+ } /* end of action switch */
+ } /* end of scanning one token */
+} /* end of yylex */
+
+/*
+ * yy_get_next_buffer - try to read in a new buffer Returns a code
+ * representing an action: EOB_ACT_LAST_MATCH - EOB_ACT_CONTINUE_SCAN -
+ * continue scanning from current position EOB_ACT_END_OF_FILE - end of
+ * file
+ */
+
+static int yy_get_next_buffer()
+{
+ register char *dest = yy_current_buffer->yy_ch_buf;
+ register char *source = yytext_ptr;
+ register int number_to_move, i;
+ int ret_val;
+
+ if (yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1])
+ YY_FATAL_ERROR
+ ("fatal flex scanner internal error--end of buffer missed");
+
+ if (yy_current_buffer->yy_fill_buffer == 0)
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if (yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1)
+ {
+ /*
+ * We matched a single character, the EOB, so treat this as a
+ * final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /*
+ * We matched some text prior to the EOB, first process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /*
+ * Try to read more data.
+ */
+
+ /*
+ * First move last chars to start of buffer.
+ */
+ number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1;
+
+ for (i = 0; i < number_to_move; ++i)
+ *(dest++) = *(source++);
+
+ if (yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING)
+ /*
+ * don't do the read, it's not guaranteed to return an EOF, just
+ * force an EOF
+ */
+ yy_current_buffer->yy_n_chars = yy_n_chars = 0;
+
+ else
+ {
+ int num_to_read =
+ yy_current_buffer->yy_buf_size - number_to_move - 1;
+
+ while (num_to_read <= 0)
+ { /* Not enough room in the buffer - grow it. */
+#ifdef YY_USES_REJECT
+ YY_FATAL_ERROR
+ ("input buffer overflow, can't enlarge buffer because scanner uses REJECT");
+#else
+
+ /*
+ * just a shorter name for the current buffer
+ */
+ YY_BUFFER_STATE b = yy_current_buffer;
+
+ int yy_c_buf_p_offset = (int) (yy_c_buf_p - b->yy_ch_buf);
+
+ if (b->yy_is_our_buffer)
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if (new_size <= 0)
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /*
+ * Include room in for 2 EOB chars.
+ */
+ yy_flex_realloc((void *) b->yy_ch_buf,
+ b->yy_buf_size + 2);
+ } else
+ /*
+ * Can't grow it, we don't own it.
+ */
+ b->yy_ch_buf = 0;
+
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR
+ ("fatal error - scanner input buffer overflow");
+
+ yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = yy_current_buffer->yy_buf_size -
+ number_to_move - 1;
+#endif
+ }
+
+ if (num_to_read > YY_READ_BUF_SIZE)
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /*
+ * Read in more data.
+ */
+ YY_INPUT((&yy_current_buffer->yy_ch_buf[number_to_move]),
+ yy_n_chars, num_to_read);
+
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ if (yy_n_chars == 0)
+ {
+ if (number_to_move == YY_MORE_ADJ)
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ yyrestart(yyin);
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ yy_current_buffer->yy_buffer_status = YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ yy_n_chars += number_to_move;
+ yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
+ yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
+
+ yytext_ptr = &yy_current_buffer->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/*
+ * yy_get_previous_state - get the state just before the EOB char was
+ * reached
+ */
+
+static yy_state_type yy_get_previous_state()
+{
+ register yy_state_type yy_current_state;
+ register char *yy_cp;
+
+ yy_current_state = yy_start;
+
+ for (yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp)
+ {
+ register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] !=
+ yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/*
+ * yy_try_NUL_trans - try to make a transition on the NUL character
+ * synopsis next_state = yy_try_NUL_trans( current_state );
+ */
+
+#ifdef YY_USE_PROTOS
+static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state)
+#else
+static yy_state_type yy_try_NUL_trans(yy_current_state)
+ yy_state_type yy_current_state;
+#endif
+{
+ register int yy_is_jam;
+ register char *yy_cp = yy_c_buf_p;
+
+ register YY_CHAR yy_c = 1;
+ if (yy_accept[yy_current_state])
+ {
+ yy_last_accepting_state = yy_current_state;
+ yy_last_accepting_cpos = yy_cp;
+ }
+ while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state)
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if (yy_current_state >= 39)
+ yy_c = yy_meta[(unsigned int) yy_c];
+ }
+ yy_current_state =
+ yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
+ yy_is_jam = (yy_current_state == 38);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+#ifdef YY_USE_PROTOS
+static void yyunput(int c, register char *yy_bp)
+#else
+static void yyunput(c, yy_bp)
+ int c;
+ register char *yy_bp;
+#endif
+{
+ register char *yy_cp = yy_c_buf_p;
+
+ /*
+ * undo effects of setting up yytext
+ */
+ *yy_cp = yy_hold_char;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ { /* need to shift things up to make room */
+ /*
+ * +2 for EOB chars.
+ */
+ register int number_to_move = yy_n_chars + 2;
+ register char *dest =
+ &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size +
+ 2];
+ register char *source =
+ &yy_current_buffer->yy_ch_buf[number_to_move];
+
+ while (source > yy_current_buffer->yy_ch_buf)
+ *--dest = *--source;
+
+ yy_cp += (int) (dest - source);
+ yy_bp += (int) (dest - source);
+ yy_current_buffer->yy_n_chars =
+ yy_n_chars = yy_current_buffer->yy_buf_size;
+
+ if (yy_cp < yy_current_buffer->yy_ch_buf + 2)
+ YY_FATAL_ERROR("flex scanner push-back overflow");
+ }
+
+ *--yy_cp = (char) c;
+
+ yytext_ptr = yy_bp;
+ yy_hold_char = *yy_cp;
+ yy_c_buf_p = yy_cp;
+}
+#endif /* ifndef YY_NO_UNPUT */
+
+#ifdef __cplusplus
+static int yyinput()
+#else
+static int input()
+#endif
+{
+ int c;
+
+ *yy_c_buf_p = yy_hold_char;
+
+ if (*yy_c_buf_p == YY_END_OF_BUFFER_CHAR)
+ {
+ /*
+ * yy_c_buf_p now points to the character we want to return. If
+ * this occurs *before* the EOB characters, then it's a valid NUL;
+ * if not, then we've hit the end of the buffer.
+ */
+ if (yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars])
+ /*
+ * This was really a NUL.
+ */
+ *yy_c_buf_p = '\0';
+
+ else
+ { /* need more input */
+ int offset = yy_c_buf_p - yytext_ptr;
+ ++yy_c_buf_p;
+
+ switch (yy_get_next_buffer())
+ {
+ case EOB_ACT_LAST_MATCH:
+ /*
+ * This happens because yy_g_n_b() sees that we've
+ * accumulated a token and flags that we need to try
+ * matching the token before proceeding. But for input(),
+ * there's no matching to consider. So convert the
+ * EOB_ACT_LAST_MATCH to EOB_ACT_END_OF_FILE.
+ */
+
+ /*
+ * Reset buffer status.
+ */
+ yyrestart(yyin);
+
+ /*
+ * fall through
+ */
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if (yywrap())
+ return EOF;
+
+ if (!yy_did_buffer_switch_on_eof)
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ yy_c_buf_p = yytext_ptr + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */
+ *yy_c_buf_p = '\0'; /* preserve yytext */
+ yy_hold_char = *++yy_c_buf_p;
+
+ return c;
+}
+
+#ifdef YY_USE_PROTOS
+void yyrestart(FILE * input_file)
+#else
+void yyrestart(input_file)
+ FILE *input_file;
+#endif
+{
+ if (!yy_current_buffer)
+ yy_current_buffer = yy_create_buffer(yyin, YY_BUF_SIZE);
+
+ yy_init_buffer(yy_current_buffer, input_file);
+ yy_load_buffer_state();
+}
+
+#ifdef YY_USE_PROTOS
+void yy_switch_to_buffer(YY_BUFFER_STATE new_buffer)
+#else
+void yy_switch_to_buffer(new_buffer)
+ YY_BUFFER_STATE new_buffer;
+#endif
+{
+ if (yy_current_buffer == new_buffer)
+ return;
+
+ if (yy_current_buffer)
+ {
+ /*
+ * Flush out information for old buffer.
+ */
+ *yy_c_buf_p = yy_hold_char;
+ yy_current_buffer->yy_buf_pos = yy_c_buf_p;
+ yy_current_buffer->yy_n_chars = yy_n_chars;
+ }
+
+ yy_current_buffer = new_buffer;
+ yy_load_buffer_state();
+
+ /*
+ * We don't actually know whether we did this switch during EOF
+ * (yywrap()) processing, but the only time this flag is looked at is
+ * after yywrap() is called, so it's safe to go ahead and always set
+ * it.
+ */
+ yy_did_buffer_switch_on_eof = 1;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_load_buffer_state(void)
+#else
+void yy_load_buffer_state()
+#endif
+{
+ yy_n_chars = yy_current_buffer->yy_n_chars;
+ yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
+ yyin = yy_current_buffer->yy_input_file;
+ yy_hold_char = *yy_c_buf_p;
+}
+
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_create_buffer(FILE * file, int size)
+#else
+YY_BUFFER_STATE yy_create_buffer(file, size)
+ FILE *file;
+ int size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_buf_size = size;
+
+ /*
+ * yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) yy_flex_alloc(b->yy_buf_size + 2);
+ if (!b->yy_ch_buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_create_buffer()");
+
+ b->yy_is_our_buffer = 1;
+
+ yy_init_buffer(b, file);
+
+ return b;
+}
+
+#ifdef YY_USE_PROTOS
+void yy_delete_buffer(YY_BUFFER_STATE b)
+#else
+void yy_delete_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+{
+ if (!b)
+ return;
+
+ if (b == yy_current_buffer)
+ yy_current_buffer = (YY_BUFFER_STATE) 0;
+
+ if (b->yy_is_our_buffer)
+ yy_flex_free((void *) b->yy_ch_buf);
+
+ yy_flex_free((void *) b);
+}
+
+#ifndef YY_ALWAYS_INTERACTIVE
+#ifndef YY_NEVER_INTERACTIVE
+extern int isatty YY_PROTO((int));
+#endif
+#endif
+
+#ifdef YY_USE_PROTOS
+void yy_init_buffer(YY_BUFFER_STATE b, FILE * file)
+#else
+void yy_init_buffer(b, file)
+ YY_BUFFER_STATE b;
+ FILE *file;
+#endif
+
+{
+ yy_flush_buffer(b);
+
+ b->yy_input_file = file;
+ b->yy_fill_buffer = 1;
+
+#if YY_ALWAYS_INTERACTIVE
+ b->yy_is_interactive = 1;
+#else
+#if YY_NEVER_INTERACTIVE
+ b->yy_is_interactive = 0;
+#else
+ b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0;
+#endif
+#endif
+}
+
+#ifdef YY_USE_PROTOS
+void yy_flush_buffer(YY_BUFFER_STATE b)
+#else
+void yy_flush_buffer(b)
+ YY_BUFFER_STATE b;
+#endif
+
+{
+ if (!b)
+ return;
+
+ b->yy_n_chars = 0;
+
+ /*
+ * We always need two end-of-buffer characters. The first causes a
+ * transition to the end-of-buffer state. The second causes a jam in
+ * that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if (b == yy_current_buffer)
+ yy_load_buffer_state();
+}
+
+#ifndef YY_NO_SCAN_BUFFER
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_buffer(char *base, yy_size_t size)
+#else
+YY_BUFFER_STATE yy_scan_buffer(base, size)
+ char *base;
+ yy_size_t size;
+#endif
+{
+ YY_BUFFER_STATE b;
+
+ if (size < 2 ||
+ base[size - 2] != YY_END_OF_BUFFER_CHAR ||
+ base[size - 1] != YY_END_OF_BUFFER_CHAR)
+ /*
+ * They forgot to leave room for the EOB's.
+ */
+ return 0;
+
+ b = (YY_BUFFER_STATE) yy_flex_alloc(sizeof(struct yy_buffer_state));
+ if (!b)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_buffer()");
+
+ b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = 0;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ yy_switch_to_buffer(b);
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_SCAN_STRING
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_string(yyconst char *yy_str)
+#else
+YY_BUFFER_STATE yy_scan_string(yy_str)
+ yyconst char *yy_str;
+#endif
+{
+ int len;
+ for (len = 0; yy_str[len]; ++len)
+ ;
+
+ return yy_scan_bytes(yy_str, len);
+}
+#endif
+
+#ifndef YY_NO_SCAN_BYTES
+#ifdef YY_USE_PROTOS
+YY_BUFFER_STATE yy_scan_bytes(yyconst char *bytes, int len)
+#else
+YY_BUFFER_STATE yy_scan_bytes(bytes, len)
+ yyconst char *bytes;
+ int len;
+#endif
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /*
+ * Get memory for full buffer, including space for trailing EOB's.
+ */
+ n = len + 2;
+ buf = (char *) yy_flex_alloc(n);
+ if (!buf)
+ YY_FATAL_ERROR("out of dynamic memory in yy_scan_bytes()");
+
+ for (i = 0; i < len; ++i)
+ buf[i] = bytes[i];
+
+ buf[len] = buf[len + 1] = YY_END_OF_BUFFER_CHAR;
+
+ b = yy_scan_buffer(buf, n);
+ if (!b)
+ YY_FATAL_ERROR("bad buffer in yy_scan_bytes()");
+
+ /*
+ * It's okay to grow etc. this buffer, and we should throw it away
+ * when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+#endif
+
+#ifndef YY_NO_PUSH_STATE
+#ifdef YY_USE_PROTOS
+static void yy_push_state(int new_state)
+#else
+static void yy_push_state(new_state)
+ int new_state;
+#endif
+{
+ if (yy_start_stack_ptr >= yy_start_stack_depth)
+ {
+ yy_size_t new_size;
+
+ yy_start_stack_depth += YY_START_STACK_INCR;
+ new_size = yy_start_stack_depth * sizeof(int);
+
+ if (!yy_start_stack)
+ yy_start_stack = (int *) yy_flex_alloc(new_size);
+
+ else
+ yy_start_stack = (int *) yy_flex_realloc(
+ (void *) yy_start_stack, new_size);
+
+ if (!yy_start_stack)
+ YY_FATAL_ERROR
+ ("out of memory expanding start-condition stack");
+ }
+
+ yy_start_stack[yy_start_stack_ptr++] = YY_START;
+
+ BEGIN(new_state);
+}
+#endif
+
+#ifndef YY_NO_POP_STATE
+static void yy_pop_state()
+{
+ if (--yy_start_stack_ptr < 0)
+ YY_FATAL_ERROR("start-condition stack underflow");
+
+ BEGIN(yy_start_stack[yy_start_stack_ptr]);
+}
+#endif
+
+#ifndef YY_NO_TOP_STATE
+static int yy_top_state()
+{
+ return yy_start_stack[yy_start_stack_ptr - 1];
+}
+#endif
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+#ifdef YY_USE_PROTOS
+static void yy_fatal_error(yyconst char msg[])
+#else
+static void yy_fatal_error(msg)
+ char msg[];
+#endif
+{
+ (void) fprintf(stderr, "%s\n", msg);
+ exit(YY_EXIT_FAILURE);
+}
+
+/*
+ * Redefine yyless() so it works in section 3 code.
+ */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up yytext. */ \
+ yytext[yyleng] = yy_hold_char; \
+ yy_c_buf_p = yytext + n; \
+ yy_hold_char = *yy_c_buf_p; \
+ *yy_c_buf_p = '\0'; \
+ yyleng = n; \
+ } \
+ while ( 0 )
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+#ifdef YY_USE_PROTOS
+static void yy_flex_strncpy(char *s1, yyconst char *s2, int n)
+#else
+static void yy_flex_strncpy(s1, s2, n)
+ char *s1;
+ yyconst char *s2;
+ int n;
+#endif
+{
+ register int i;
+ for (i = 0; i < n; ++i)
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+#ifdef YY_USE_PROTOS
+static int yy_flex_strlen(yyconst char *s)
+#else
+static int yy_flex_strlen(s)
+ yyconst char *s;
+#endif
+{
+ register int n;
+ for (n = 0; s[n]; ++n)
+ ;
+
+ return n;
+}
+#endif
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_alloc(yy_size_t size)
+#else
+static void *yy_flex_alloc(size)
+ yy_size_t size;
+#endif
+{
+ return (void *) malloc(size);
+}
+
+#ifdef YY_USE_PROTOS
+static void *yy_flex_realloc(void *ptr, yy_size_t size)
+#else
+static void *yy_flex_realloc(ptr, size)
+ void *ptr;
+ yy_size_t size;
+#endif
+{
+ /*
+ * The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those that use
+ * void* generic pointers. It works with the latter because both ANSI
+ * C and C++ allow castless assignment from any pointer type to void*,
+ * and deal with argument conversions as though doing an assignment.
+ */
+ return (void *) realloc((char *) ptr, size);
+}
+
+#ifdef YY_USE_PROTOS
+static void yy_flex_free(void *ptr)
+#else
+static void yy_flex_free(ptr)
+ void *ptr;
+#endif
+{
+ free(ptr);
+}
+
+#if YY_MAIN
+int main()
+{
+ yylex();
+ return 0;
+}
+#endif
+#line 36 "tokenparser.l"
+
+#include <stdio.h>
+#include <string.h>
+#include "debuglog.h"
+
+#ifndef WIN32
+#include "config.h"
+#else
+#include "../win32/win32_config.h"
+#endif
+
+int yywrap()
+{
+ return 1;
+}
+
+void tpevalToken(char *pcToken, int tokType)
+{
+
+ int len;
+ len = 0;
+
+ if (tokType == 1)
+ {
+ for (len = 5; pcToken[len] != '<'; len++) ;
+ strncpy(pcKey, &pcToken[5], len - 5);
+ pcKey[len - 5] = 0;
+ }
+
+ if (tokType == 2)
+ {
+ for (len = 8; pcToken[len] != '<'; len++) ;
+ strncpy(pcValue, &pcToken[8], len - 8);
+ pcValue[len - 8] = 0;
+ if (strcmp(pcKey, pcDesiredKey) == 0)
+ {
+ if (desiredIndex == valueIndex)
+ {
+ strcpy(pcFinValue, pcValue);
+ }
+ }
+ }
+
+}
+
+void tperrorCheck(char *token_error)
+{
+}
+
+int LTPBundleFindValueWithKey(char *fileName, char *tokenKey,
+ char *tokenValue, int tokenIndice)
+{
+
+ FILE *file;
+ file = 0;
+
+ desiredIndex = tokenIndice;
+ pcDesiredKey = tokenKey;
+ pcFinValue[0] = 0;
+
+ file = fopen(fileName, "r");
+
+ if (!file)
+ {
+ DebugLogB("Could not open bundle file : %s\n", fileName);
+ return 1;
+ }
+
+ yyin = file;
+
+ do
+ {
+ yylex();
+ }
+ while (!feof(file));
+
+ if (pcFinValue[0] == 0)
+ {
+ if (tokenIndice == 0)
+ {
+ /*
+ * Not defined at all
+ */
+ DebugLogB("Value/Key not defined for: %s\n", tokenKey);
+ }
+ fclose(file);
+ return -1;
+ } else
+ {
+ strcpy(tokenValue, pcFinValue);
+ fclose(file);
+ return 0;
+ }
+
+ fclose(file);
+ return 0;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.l
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.l (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/tokenparser.l 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,114 @@
+/*****************************************************************
+
+ File : configfile.ll
+ Author : David Corcoran
+ Date : February 12, 1999 modified 7/28/99
+ Purpose: Reads lexical config files and updates database.
+ See http://www.linuxnet.com for more information.
+ License: Copyright (C) 1999 David Corcoran
+ <corcoran at linuxnet.com>
+
+******************************************************************/
+
+%{
+
+void tpevalToken( char *pcToken, int tokType );
+
+static char *pcDesiredKey = 0;
+static char pcKey[200];
+static char pcValue[200];
+static char pcFinValue[200];
+static int valueIndex = 0;
+static int desiredIndex = 0;
+
+void tperrorCheck ( char *pcToken_error );
+
+%}
+
+%%
+
+#.* {}
+"\n" {}
+\<key\>([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { valueIndex = 0; tpevalToken(yytext, 1); }
+[ \t] {}
+\<string\>([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'"])+\<\/string\> {tpevalToken(yytext, 2); valueIndex += 1;}
+. { tperrorCheck( yytext ); }
+%%
+
+#include <stdio.h>
+#include <string.h>
+#include "debuglog.h"
+#include "config.h"
+
+int yywrap() {
+ return 1;
+}
+
+
+void tpevalToken( char *pcToken, int tokType ) {
+
+ int len;
+ len = 0;
+
+ if ( tokType == 1 ) {
+ for (len=5; pcToken[len] != '<'; len++);
+ strncpy(pcKey, &pcToken[5], len - 5);
+ pcKey[len-5] = 0;
+ }
+
+ if ( tokType == 2 ) {
+ for (len=8; pcToken[len] != '<'; len++);
+ strncpy(pcValue, &pcToken[8], len - 8);
+ pcValue[len-8] = 0;
+ if ( strcmp(pcKey, pcDesiredKey) == 0 ) {
+ if ( desiredIndex == valueIndex ) {
+ strcpy(pcFinValue, pcValue);
+ }
+ }
+ }
+
+
+}
+
+void tperrorCheck ( char *token_error ) { }
+
+int LTPBundleFindValueWithKey(char *fileName, char *tokenKey,
+ char *tokenValue, int tokenIndice) {
+
+ FILE *file;
+ file = 0;
+
+ desiredIndex = tokenIndice;
+ pcDesiredKey = tokenKey;
+ pcFinValue[0] = 0;
+
+ file = fopen(fileName, "r");
+
+ if (!file) {
+ DebugLogC( "Could not open bundle file : %s\n", fileName );
+ return 1;
+ }
+
+ yyin = file;
+
+ do {
+ yylex();
+ } while (!feof(file));
+
+ if ( pcFinValue[0] == 0 ) {
+ if ( tokenIndice == 0 ) {
+ /* Not defined at all */
+ DebugLogC( "Value/Key not defined for: %s\n", tokenKey );
+ }
+ fclose(file);
+ return -1;
+ } else {
+ strcpy(tokenValue, pcFinValue);
+ fclose(file);
+ return 0;
+ }
+
+ fclose(file);
+ return 0;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/utils/bundleTool.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/utils/bundleTool.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/utils/bundleTool.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ Title : bundleTool.c
+ Package: MuscleCard Framework
+ Author : David Corcoran
+ Date : 03/11/01
+ License: Copyright (C) 2002 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This automatically updates the Info.plist
+
+ You may not remove this header from this file
+ without prior permission from the author.
+
+$Id: bundleTool.c,v 1.2 2003/02/13 20:06:36 ghoo Exp $
+
+********************************************************************/
+
+#include "wintypes.h"
+#include "winscard.h"
+#include "tokenfactory.h"
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+
+/*
+ * End of personalization
+ */
+
+#define CHECK_ERR(cond, msg) { if (cond) { \
+ printf("Error: %s\n", msg); return -1; } }
+
+int main(int argc, char **argv)
+{
+
+ LONG rv;
+ SCARDCONTEXT hContext;
+ SCARD_READERSTATE_A rgReaderStates;
+ DWORD readerListSize;
+ struct stat statBuffer;
+ char spAtrValue[100];
+ char chosenInfoPlist[1024];
+ char *readerList;
+ char *restFile;
+ char atrInsertion[256];
+ FILE *fp;
+ DIR *bundleDir;
+ struct dirent *currBundle;
+ int i, p;
+ int userChoice;
+ int totalBundles;
+ int filePosition;
+ int restFileSize;
+ int restOffset;
+ int getsSize;
+
+ if (argc > 1)
+ {
+ printf("Invalid arguments\n");
+ printf("./bundleTool\n");
+ return -1;
+ }
+
+ currBundle = 0;
+
+ bundleDir = opendir(MSC_SVC_DROPDIR);
+ CHECK_ERR(bundleDir == 0, "Could not open services directory.");
+
+ printf("Select the approprate token driver:\n");
+ printf("-----------------------------------\n");
+
+ i = 1;
+ totalBundles = 0;
+
+ while ((currBundle = readdir(bundleDir)) != 0)
+ {
+ if (strstr(currBundle->d_name, ".bundle") != 0)
+ {
+ printf(" %d. %s\n", i++, currBundle->d_name);
+ totalBundles += 1;
+ }
+ }
+ printf("-----------------------------------\n");
+
+ if (totalBundles == 0)
+ {
+ printf("No services are present - exiting.\n");
+ return 1;
+ }
+
+ do
+ {
+ printf("Enter the number: ");
+ scanf("%d", &userChoice);
+ }
+ while (userChoice < 1 && userChoice > totalBundles);
+
+ closedir(bundleDir);
+
+ bundleDir = opendir(MSC_SVC_DROPDIR);
+ CHECK_ERR(bundleDir == 0, "Could not open services directory.");
+ CHECK_ERR(bundleDir == 0, MSC_SVC_DROPDIR);
+
+ do
+ {
+ if ((currBundle = readdir(bundleDir)) != 0)
+ {
+ if (strstr(currBundle->d_name, ".bundle") != 0)
+ {
+ userChoice -= 1;
+ }
+ }
+ }
+ while (userChoice != 0);
+
+ snprintf(chosenInfoPlist, sizeof(chosenInfoPlist),
+ "%s%s/Contents/Info.plist", MSC_SVC_DROPDIR, currBundle->d_name);
+ closedir(bundleDir);
+ printf("\n");
+
+ rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, 0, 0, &hContext);
+ CHECK_ERR(rv != SCARD_S_SUCCESS, "PC/SC SCardEstablishContext Failed");
+
+ readerListSize = 0;
+ rv = SCardListReaders(hContext, 0, 0, &readerListSize);
+ CHECK_ERR(rv != SCARD_S_SUCCESS, "PC/SC SCardListReaders Failed");
+
+ readerList = (char *) malloc(sizeof(char) * readerListSize);
+ CHECK_ERR(readerList == 0, "Malloc Failed");
+
+ rv = SCardListReaders(hContext, 0, readerList, &readerListSize);
+ CHECK_ERR(rv != SCARD_S_SUCCESS, "PC/SC SCardListReaders Alloc Failed");
+
+ printf("Insert your token in: %s\n", readerList);
+
+ rgReaderStates.szReader = readerList;
+ rgReaderStates.dwCurrentState = SCARD_STATE_EMPTY;
+
+ rv = SCardGetStatusChange(hContext, INFINITE, &rgReaderStates, 1);
+ CHECK_ERR(rv != SCARD_S_SUCCESS, "PC/SC SCardGetStatusChange Failed");
+
+ p = 0;
+ for (i = 0; i < rgReaderStates.cbAtr; i++)
+ {
+ sprintf(&spAtrValue[p], "%02X", rgReaderStates.rgbAtr[i]);
+ p += 2;
+ }
+ printf("\n");
+
+ snprintf(atrInsertion, sizeof(atrInsertion),
+ " <string>%s</string>\n", spAtrValue);
+
+ fp = fopen(chosenInfoPlist, "r+");
+ if (fp == 0)
+ {
+ printf("Could not open %s\n", chosenInfoPlist);
+ }
+ CHECK_ERR(fp == 0, "Opening of Info.plist failed.");
+
+ rv = stat(chosenInfoPlist, &statBuffer);
+ CHECK_ERR(rv != 0, "File Stat failed\n");
+
+ restFileSize = statBuffer.st_size + strlen(atrInsertion);
+ restFile = (char *) malloc(sizeof(char) * restFileSize);
+ CHECK_ERR(restFile == 0, "Malloc failed");
+
+ filePosition = 0;
+ restOffset = 0;
+ getsSize = 0;
+
+ do
+ {
+ if (fgets(&restFile[restOffset], restFileSize, fp) == 0)
+ {
+ break;
+ }
+
+ if (strstr(&restFile[restOffset], "<key>spAtrValue</key>"))
+ {
+ filePosition = ftell(fp);
+ }
+
+ getsSize = strlen(&restFile[restOffset]);
+ restOffset += getsSize;
+ }
+ while (1);
+
+ rewind(fp);
+ fwrite(restFile, 1, filePosition, fp);
+ fwrite(atrInsertion, 1, strlen(atrInsertion), fp);
+ fwrite(&restFile[filePosition], 1,
+ statBuffer.st_size - filePosition, fp);
+
+ fclose(fp);
+
+ printf("Token support updated successfully !\n");
+
+ return 0;
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1525 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard.c 2385 2007-02-05 13:55:01Z rousseau $
+ */
+
+/**
+ * @mainpage MUSCLE PC/SC-Lite API Documentation
+ *
+ * @section Introduction
+ *
+ * This document contains the reference API calls for communicating to the
+ * MUSCLE PC/SC Smart Card Resource Manager. PC/SC is a standard proposed by
+ * the PC/SC workgroup http://www.pcscworkgroup.com/ which is a conglomerate of
+ * representative from major smart card manufacturers and other companies. This
+ * specification tries to abstract the smart card layer into a high level API
+ * so that smart cards and their readers can be accessed in a homogeneous
+ * fashion.
+ *
+ * This toolkit was written in ANSI C that can be used with most compilers and
+ * does NOT use complex and large data structures such as vectors, etc. The C
+ * API emulates the winscard API that is used on the Windows platform. It is
+ * contained in the library <tt>libpcsclite.so</tt> that is linked to your
+ * application.
+ *
+ * I would really like to hear from you. If you have any feedback either on
+ * this documentation or on the MUSCLE project please feel free to email me at:
+ * corcoran at musclecard.com.
+ *
+ *
+ * @section API Routines
+ *
+ * These routines specified here are winscard routines like those in the
+ * winscard API provided under Windows(R). These are compatible with the
+ * Microsoft(R) API calls. This list of calls is mainly an abstraction of
+ * readers. It gives a common API for communication to most readers in a
+ * homogeneous fashion.
+ *
+ * Since all functions can produce a wide array of errors, please refer to
+ * Error codes for a list of error returns.
+ *
+ * For a human readable representation of an error the function
+ * pcsc_stringify_error() is declared in pcsclite.h. This function is not
+ * available on Microsoft(R) winscard API and is pcsc-lite specific.
+ *
+ * @section Internals
+ *
+ * PC/SC Lite is formed by a server deamon (<tt>pcscd</tt>) and a client
+ * library (<tt>libpcsclite.so</tt>) that communicate via IPC.
+ *
+ * The file \em winscard_clnt.c in the client-side exposes the API for
+ * applications.\n The file \em winscard.c has the server-side counterpart
+ * functions present in \em winscard_clnt.c.\n The file \em winscard_msg.c is
+ * the communication interface between \em winscard_clnt.c and \em
+ * winscard.c.\n The file pcscdaemon.c has the main server-side function,
+ * including a loop for accepting client requests.\n The file \em
+ * winscard_svc.c has the functions called by \em pcscdaemon.c to serve clients
+ * requests.
+ *
+ * When a function from \em winscard_clnt.c is called by a client application,
+ * it calls a function in \em winscard_msg.c to send the message to \em
+ * pcscdaemon.c. When \em pcscdaemon.c a client detects a request arrived, it
+ * calls \em winscard_svc.c which identifies what command the message contains
+ * and requests \em winscard.c to execute the command.\n Meanwhile
+ * winscard_clnt.c waits for the response until a timeout occurs.
+ */
+
+/**
+ * @file
+ * @brief This handles smartcard reader communications.
+ * This is the heart of the MS smartcard API.
+ *
+ * Here are the main server-side functions which execute the requests from the
+ * clients.
+ */
+
+#include "config.h"
+#include <stdlib.h>
+#include <sys/time.h>
+#include <string.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "winscard.h"
+#include "ifdhandler.h"
+#include "debuglog.h"
+#include "readerfactory.h"
+#include "prothandler.h"
+#include "ifdwrapper.h"
+#include "atrhandler.h"
+#include "configfile.h"
+#include "sys_generic.h"
+#include "eventhandler.h"
+#include "readerstate.h"
+
+#include <security_utilities/debugging.h>
+
+/** used for backward compatibility */
+#define SCARD_PROTOCOL_ANY_OLD 0x1000
+
+/** Some defines for context stack. */
+#define SCARD_LAST_CONTEXT 1
+/** Some defines for context stack. */
+#define SCARD_NO_CONTEXT 0
+/** Some defines for context stack. */
+#define SCARD_EXCLUSIVE_CONTEXT -1
+/** Some defines for context stack. */
+#define SCARD_NO_LOCK 0
+
+SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
+SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
+SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
+
+#define PCSCLITE_LOCK_POLL_RATE 100000 /**< Lock polling rate */
+
+static LONG NotifyOfCardReset(DWORD state, PREADER_CONTEXT rContext, SCARDHANDLE hCard);
+static LONG EjectCard(PREADER_CONTEXT rContext);
+
+
+/**
+ * @brief Creates an Application Context for a client.
+ *
+ * This must be the first function called in a PC/SC application.
+ *
+ * @param[in] dwScope Scope of the establishment.
+ * This can either be a local or remote connection.
+ * <ul>
+ * <li>SCARD_SCOPE_USER - Not used.
+ * <li>SCARD_SCOPE_TERMINAL - Not used.
+ * <li>SCARD_SCOPE_GLOBAL - Not used.
+ * <li>SCARD_SCOPE_SYSTEM - Services on the local machine.
+ * </ul>
+ * @param[in] pvReserved1 Reserved for future use. Can be used for remote connection.
+ * @param[in] pvReserved2 Reserved for future use.
+ * @param[out] phContext Returned Application Context.
+ *
+ * @return Connection status.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_VALUE Invalid scope type passed (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_INVALID_PARAMETER phContext is null (\ref SCARD_E_INVALID_PARAMETER)
+ */
+LONG SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
+ LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+{
+ /*
+ * Check for NULL pointer
+ */
+ if (phContext == 0)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL &&
+ dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL)
+ {
+
+ *phContext = 0;
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ /*
+ * Unique identifier for this server so that it can uniquely be
+ * identified by clients and distinguished from others
+ */
+
+ *phContext = (PCSCLITE_SVC_IDENTITY + SYS_Random(SYS_GetSeed(),
+ 1.0, 65535.0));
+
+ Log3(PCSC_LOG_DEBUG, "Establishing Context: %d [0x%08X]", *phContext, *phContext);
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardReleaseContext(SCARDCONTEXT hContext)
+{
+ /*
+ * Nothing to do here RPC layer will handle this
+ */
+
+ Log2(PCSC_LOG_DEBUG, "Releasing Context: %d", hContext);
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardSetTimeout(SCARDCONTEXT hContext, DWORD dwTimeout)
+{
+ /*
+ * This is only used at the client side of an RPC call but just in
+ * case someone calls it here
+ */
+
+ return SCARD_E_UNSUPPORTED_FEATURE;
+}
+
+LONG SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader,
+ DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,
+ LPDWORD pdwActiveProtocol)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+ DWORD dwStatus;
+
+ /*
+ * Check for NULL parameters
+ */
+ if (szReader == NULL || phCard == NULL || pdwActiveProtocol == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+ else
+ *phCard = 0;
+
+ if (!(dwPreferredProtocols & SCARD_PROTOCOL_T0) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_T1) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_RAW) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD))
+ return SCARD_E_PROTO_MISMATCH;
+
+ if (dwShareMode != SCARD_SHARE_EXCLUSIVE &&
+ dwShareMode != SCARD_SHARE_SHARED &&
+ dwShareMode != SCARD_SHARE_DIRECT)
+ return SCARD_E_INVALID_VALUE;
+
+ Log3(PCSC_LOG_DEBUG, "Attempting Connect to %s using protocol: %d",
+ szReader, dwPreferredProtocols);
+
+ rv = RFReaderInfo((LPSTR) szReader, &rContext);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log2(PCSC_LOG_ERROR, "Reader %s Not Found", szReader);
+ return rv;
+ }
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*******************************************
+ *
+ * This section checks for simple errors
+ *
+ *******************************************/
+
+ /*
+ * Connect if not exclusive mode
+ */
+ if (rContext->dwContexts == SCARD_EXCLUSIVE_CONTEXT)
+ {
+ Log1(PCSC_LOG_ERROR, "Error Reader Exclusive");
+ return SCARD_E_SHARING_VIOLATION;
+ }
+
+ /*
+ * wait until a possible transaction is finished
+ */
+ if (rContext->dwLockId != 0)
+ {
+ Log1(PCSC_LOG_INFO, "Waiting for release of lock");
+ while (rContext->dwLockId != 0)
+ SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+ Log1(PCSC_LOG_INFO, "Lock released");
+
+ /* Allow the status thread to convey information */
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+ }
+
+ /*******************************************
+ *
+ * This section tries to determine the
+ * presence of a card or not
+ *
+ *******************************************/
+ dwStatus = SharedReaderState_State(rContext->readerState);
+
+ if (dwShareMode != SCARD_SHARE_DIRECT)
+ {
+ if (!(dwStatus & SCARD_PRESENT))
+ {
+ Log1(PCSC_LOG_ERROR, "Card Not Inserted");
+ return SCARD_E_NO_SMARTCARD;
+ }
+
+ if (dwStatus & SCARD_SWALLOWED)
+ {
+ Log1(PCSC_LOG_ERROR, "Card Not Powered");
+ return SCARD_W_UNPOWERED_CARD;
+ }
+ }
+
+
+ /*******************************************
+ *
+ * This section tries to decode the ATR
+ * and set up which protocol to use
+ *
+ *******************************************/
+ if (dwPreferredProtocols & SCARD_PROTOCOL_RAW)
+ SharedReaderState_SetProtocol(rContext->readerState, SCARD_PROTOCOL_RAW);
+ else
+ {
+ if (dwShareMode != SCARD_SHARE_DIRECT)
+ {
+ /* lock here instead in IFDSetPTS() to lock up to
+ * setting rContext->readerState->cardProtocol */
+ SYS_MutexLock(rContext->mMutex);
+
+ /* the protocol is not yet set (no PPS yet) */
+ if (SCARD_PROTOCOL_UNSET == SharedReaderState_Protocol(rContext->readerState))
+ {
+ UCHAR ucAvailable, ucDefault;
+ int ret;
+
+ ucDefault = PHGetDefaultProtocol(SharedReaderState_CardAtr(rContext->readerState),
+ SharedReaderState_CardAtrLength(rContext->readerState));
+ ucAvailable =
+ PHGetAvailableProtocols(SharedReaderState_CardAtr(rContext->readerState),
+ SharedReaderState_CardAtrLength(rContext->readerState));
+
+ /*
+ * If it is set to ANY let it do any of the protocols
+ */
+ if (dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD)
+ dwPreferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
+
+ ret = PHSetProtocol(rContext, dwPreferredProtocols,
+ ucAvailable, ucDefault);
+
+ /* keep cardProtocol = SCARD_PROTOCOL_UNSET in case of error */
+ if (SET_PROTOCOL_PPS_FAILED == ret)
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+ return SCARD_W_UNRESPONSIVE_CARD;
+ }
+
+ if (SET_PROTOCOL_WRONG_ARGUMENT == ret)
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+ return SCARD_E_PROTO_MISMATCH;
+ }
+
+ /* use negotiated protocol */
+ SharedReaderState_SetProtocol(rContext->readerState, ret);
+
+ SYS_MutexUnLock(rContext->mMutex);
+ }
+ else
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+
+ if (! (dwPreferredProtocols & SharedReaderState_Protocol(rContext->readerState)))
+ return SCARD_E_PROTO_MISMATCH;
+ }
+ }
+ }
+
+ *pdwActiveProtocol = SharedReaderState_Protocol(rContext->readerState);
+
+ if (dwShareMode != SCARD_SHARE_DIRECT)
+ {
+ if ((*pdwActiveProtocol != SCARD_PROTOCOL_T0)
+ && (*pdwActiveProtocol != SCARD_PROTOCOL_T1))
+ Log2(PCSC_LOG_ERROR, "Active Protocol: unknown %d",
+ *pdwActiveProtocol);
+ else
+ Log2(PCSC_LOG_DEBUG, "Active Protocol: T=%d",
+ (*pdwActiveProtocol == SCARD_PROTOCOL_T0) ? 0 : 1);
+ }
+ else
+ Log1(PCSC_LOG_DEBUG, "Direct access: no protocol selected");
+
+ /*
+ * Prepare the SCARDHANDLE identity
+ */
+ *phCard = RFCreateReaderHandle(rContext);
+
+ Log2(PCSC_LOG_DEBUG, "hCard Identity: %x", *phCard);
+
+ /*******************************************
+ *
+ * This section tries to set up the
+ * exclusivity modes. -1 is exclusive
+ *
+ *******************************************/
+
+ if (dwShareMode == SCARD_SHARE_EXCLUSIVE)
+ {
+ if (rContext->dwContexts == SCARD_NO_CONTEXT)
+ {
+ rContext->dwContexts = SCARD_EXCLUSIVE_CONTEXT;
+ RFLockSharing(*phCard);
+ }
+ else
+ {
+ RFDestroyReaderHandle(*phCard);
+ *phCard = 0;
+ Log1(PCSC_LOG_ERROR, "SCardConnect: share mode is exclusive, but already in use");
+ return SCARD_E_SHARING_VIOLATION;
+ }
+ }
+ else
+ {
+ /*
+ * Add a connection to the context stack
+ */
+ rContext->dwContexts += 1;
+ }
+
+ /*
+ * Add this handle to the handle list
+ */
+ rv = RFAddReaderHandle(rContext, *phCard);
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ /*
+ * Clean up - there is no more room
+ */
+ RFDestroyReaderHandle(*phCard);
+ if (rContext->dwContexts == SCARD_EXCLUSIVE_CONTEXT)
+ rContext->dwContexts = SCARD_NO_CONTEXT;
+ else
+ if (rContext->dwContexts > SCARD_NO_CONTEXT)
+ rContext->dwContexts -= 1;
+
+ *phCard = 0;
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ /*
+ * Allow the status thread to convey information
+ */
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode,
+ DWORD dwPreferredProtocols, DWORD dwInitialization,
+ LPDWORD pdwActiveProtocol)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+ int do_sleep = 1;
+
+ Log1(PCSC_LOG_DEBUG, "Attempting reconnect to token.");
+
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*
+ * Handle the dwInitialization
+ */
+ if (dwInitialization != SCARD_LEAVE_CARD &&
+ dwInitialization != SCARD_RESET_CARD &&
+ dwInitialization != SCARD_UNPOWER_CARD)
+ return SCARD_E_INVALID_VALUE;
+
+ if (dwShareMode != SCARD_SHARE_SHARED &&
+ dwShareMode != SCARD_SHARE_EXCLUSIVE &&
+ dwShareMode != SCARD_SHARE_DIRECT)
+ return SCARD_E_INVALID_VALUE;
+
+ if (!(dwPreferredProtocols & SCARD_PROTOCOL_T0) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_T1) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_RAW) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD))
+ return SCARD_E_PROTO_MISMATCH;
+
+ if (pdwActiveProtocol == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure no one has a lock on this reader
+ */
+ rv = RFCheckSharing(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * RFUnblockReader( rContext ); FIX - this doesn't work
+ */
+
+ if (dwInitialization == SCARD_RESET_CARD ||
+ dwInitialization == SCARD_UNPOWER_CARD)
+ {
+ LONG ret = NotifyOfCardReset(dwInitialization, rContext, hCard);
+ if (ret != SCARD_S_SUCCESS)
+ return ret;
+
+ do_sleep = 1;
+ }
+ else if (dwInitialization == SCARD_LEAVE_CARD)
+ {
+ /*
+ * Do nothing
+ */
+ do_sleep = 0;
+ }
+
+ /*******************************************
+ *
+ * This section tries to decode the ATR
+ * and set up which protocol to use
+ *
+ *******************************************/
+
+
+ if (dwPreferredProtocols & SCARD_PROTOCOL_RAW)
+ SharedReaderState_SetProtocol(rContext->readerState, SCARD_PROTOCOL_RAW);
+ else
+ {
+ if (dwShareMode != SCARD_SHARE_DIRECT)
+ {
+ /* lock here instead in IFDSetPTS() to lock up to
+ * setting rContext->readerState->cardProtocol */
+ SYS_MutexLock(rContext->mMutex);
+
+ /* the protocol is not yet set (no PPS yet) */
+ if (SCARD_PROTOCOL_UNSET == SharedReaderState_Protocol(rContext->readerState))
+ {
+ UCHAR ucAvailable, ucDefault;
+ int ret;
+
+ ucDefault = PHGetDefaultProtocol(SharedReaderState_CardAtr(rContext->readerState),
+ SharedReaderState_CardAtrLength(rContext->readerState));
+ ucAvailable =
+ PHGetAvailableProtocols(SharedReaderState_CardAtr(rContext->readerState),
+ SharedReaderState_CardAtrLength(rContext->readerState));
+
+ /* If it is set to ANY let it do any of the protocols */
+ if (dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD)
+ dwPreferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;
+
+ ret = PHSetProtocol(rContext, dwPreferredProtocols,
+ ucAvailable, ucDefault);
+
+ /* keep cardProtocol = SCARD_PROTOCOL_UNSET in case of error */
+ if (SET_PROTOCOL_PPS_FAILED == ret)
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+ return SCARD_W_UNRESPONSIVE_CARD;
+ }
+
+ if (SET_PROTOCOL_WRONG_ARGUMENT == ret)
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+ return SCARD_E_PROTO_MISMATCH;
+ }
+
+ /* use negotiated protocol */
+ SharedReaderState_SetProtocol(rContext->readerState, ret);
+
+ SYS_MutexUnLock(rContext->mMutex);
+ }
+ else
+ {
+ SYS_MutexUnLock(rContext->mMutex);
+
+ if (! (dwPreferredProtocols & SharedReaderState_Protocol(rContext->readerState)))
+ return SCARD_E_PROTO_MISMATCH;
+ }
+ }
+ }
+
+ *pdwActiveProtocol = SharedReaderState_Protocol(rContext->readerState);
+
+ if (dwShareMode == SCARD_SHARE_EXCLUSIVE)
+ {
+ if (rContext->dwContexts == SCARD_EXCLUSIVE_CONTEXT)
+ {
+ /*
+ * Do nothing - we are already exclusive
+ */
+ } else
+ {
+ if (rContext->dwContexts == SCARD_LAST_CONTEXT)
+ {
+ rContext->dwContexts = SCARD_EXCLUSIVE_CONTEXT;
+ RFLockSharing(hCard);
+ } else
+ {
+ Log1(PCSC_LOG_ERROR, "SCardReConnect: share mode is exclusive, but already in use");
+ return SCARD_E_SHARING_VIOLATION;
+ }
+ }
+ } else if (dwShareMode == SCARD_SHARE_SHARED)
+ {
+ if (rContext->dwContexts != SCARD_EXCLUSIVE_CONTEXT)
+ {
+ /*
+ * Do nothing - in sharing mode already
+ */
+ } else
+ {
+ /*
+ * We are in exclusive mode but want to share now
+ */
+ RFUnlockSharing(hCard);
+ rContext->dwContexts = SCARD_LAST_CONTEXT;
+ }
+ } else if (dwShareMode == SCARD_SHARE_DIRECT)
+ {
+ if (rContext->dwContexts != SCARD_EXCLUSIVE_CONTEXT)
+ {
+ /*
+ * Do nothing - in sharing mode already
+ */
+ } else
+ {
+ /*
+ * We are in exclusive mode but want to share now
+ */
+ RFUnlockSharing(hCard);
+ rContext->dwContexts = SCARD_LAST_CONTEXT;
+ }
+ } else
+ return SCARD_E_INVALID_VALUE;
+
+ /*
+ * Clear a previous event to the application
+ */
+ RFClearReaderEventState(rContext, hCard);
+
+ /*
+ * Allow the status thread to convey information
+ */
+ if (do_sleep)
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ if ((dwDisposition != SCARD_LEAVE_CARD)
+ && (dwDisposition != SCARD_UNPOWER_CARD)
+ && (dwDisposition != SCARD_RESET_CARD)
+ && (dwDisposition != SCARD_EJECT_CARD))
+ return SCARD_E_INVALID_VALUE;
+
+ /*
+ * wait until a possible transaction is finished
+ */
+ if ((rContext->dwLockId != 0) && (rContext->dwLockId != (uint32_t)hCard))
+ {
+ Log1(PCSC_LOG_INFO, "Waiting for release of lock");
+ while (rContext->dwLockId != 0)
+ SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+ Log1(PCSC_LOG_INFO, "Lock released");
+ }
+
+ /*
+ * Unlock any blocks on this context
+ */
+ rv = RFUnlockSharing(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ Log2(PCSC_LOG_DEBUG, "Active Contexts: %d", rContext->dwContexts);
+
+ if (dwDisposition == SCARD_RESET_CARD ||
+ dwDisposition == SCARD_UNPOWER_CARD)
+ {
+ /* LONG ret = */ NotifyOfCardReset(dwDisposition, rContext, hCard);
+ /* we ignore the return values in this case */
+
+ /*
+ * Allow the status thread to convey information
+ */
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+
+ }
+ else
+ if (dwDisposition == SCARD_EJECT_CARD)
+ EjectCard(rContext);
+ else if (dwDisposition == SCARD_LEAVE_CARD)
+ {
+ /*
+ * Do nothing
+ */
+ }
+
+ /*
+ * Remove and destroy this handle
+ */
+ RFRemoveReaderHandle(rContext, hCard);
+ RFDestroyReaderHandle(hCard);
+
+ /*
+ * For exclusive connection reset it to no connections
+ */
+ if (rContext->dwContexts == SCARD_EXCLUSIVE_CONTEXT)
+ {
+ rContext->dwContexts = SCARD_NO_CONTEXT;
+ return SCARD_S_SUCCESS;
+ }
+
+ /*
+ * Remove a connection from the context stack
+ */
+ rContext->dwContexts -= 1;
+
+ if (rContext->dwContexts < 0)
+ rContext->dwContexts = 0;
+
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardBeginTransaction(SCARDHANDLE hCard)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext;
+
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+
+ /*
+ * Cannot find the hCard in this context
+ */
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log3(PCSC_LOG_DEBUG, "SCardBeginTransaction: cannot find hCard: 0x%08X [0x%08X]", hCard, rv);
+ return rv;
+ }
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log3(PCSC_LOG_DEBUG, "SCardBeginTransaction: reader status fail: 0x%08X [0x%08X]", hCard, rv);
+ return rv;
+ }
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ {
+ Log3(PCSC_LOG_DEBUG, "SCardBeginTransaction: reader handle fail: 0x%08X [0x%08X]", hCard, rv);
+ return rv;
+ }
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ {
+ Log3(PCSC_LOG_DEBUG, "SCardBeginTransaction: reader event fail: 0x%08X [0x%08X]", hCard, rv);
+ return rv;
+ }
+
+ rv = RFLockSharing(hCard);
+
+ /* if the transaction is not yet ready we sleep a bit so the client
+ * do not retry immediately */
+ if (SCARD_E_SHARING_VIOLATION == (uint32_t)rv)
+ SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
+
+ Log2(PCSC_LOG_DEBUG, "SCardBeginTransaction ending status: 0x%08X", rv);
+
+ return rv;
+}
+
+LONG SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ /*
+ * Ignoring dwDisposition for now
+ */
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ if ((dwDisposition != SCARD_LEAVE_CARD)
+ && (dwDisposition != SCARD_UNPOWER_CARD)
+ && (dwDisposition != SCARD_RESET_CARD)
+ && (dwDisposition != SCARD_EJECT_CARD))
+ return SCARD_E_INVALID_VALUE;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+
+ /*
+ * Cannot find the hCard in this context
+ */
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ if (dwDisposition == SCARD_RESET_CARD ||
+ dwDisposition == SCARD_UNPOWER_CARD)
+ {
+ /* LONG ret = */ NotifyOfCardReset(dwDisposition, rContext, hCard);
+ }
+ else if (dwDisposition == SCARD_EJECT_CARD)
+ EjectCard(rContext);
+ else if (dwDisposition == SCARD_LEAVE_CARD)
+ {
+ /*
+ * Do nothing
+ */
+ }
+
+ /*
+ * Unlock any blocks on this context
+ */
+ RFUnlockSharing(hCard);
+
+ Log2(PCSC_LOG_DEBUG, "Status: 0x%08X", rv);
+
+ return rv;
+}
+
+LONG SCardCancelTransaction(SCARDHANDLE hCard)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ /*
+ * Ignoring dwDisposition for now
+ */
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+
+ /*
+ * Cannot find the hCard in this context
+ */
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFUnlockSharing(hCard);
+
+ Log2(PCSC_LOG_DEBUG, "Status: 0x%08X", rv);
+
+ return rv;
+}
+
+LONG SCardStatus(SCARDHANDLE hCard, LPSTR mszReaderNames,
+ LPDWORD pcchReaderLen, LPDWORD pdwState,
+ LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+
+ /*
+ * Cannot find the hCard in this context
+ */
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ if (strlen(rContext->lpcReader) > MAX_BUFFER_SIZE
+ || SharedReaderState_CardAtrLength(rContext->readerState) > MAX_ATR_SIZE)
+ return SCARD_F_INTERNAL_ERROR;
+
+ /*
+ * This is a client side function however the server maintains the
+ * list of events between applications so it must be passed through to
+ * obtain this event if it has occurred
+ */
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ if (mszReaderNames) /* want reader name */
+ {
+ int cchReaderLen;
+ if (!pcchReaderLen) /* present buf & no buflen */
+ return SCARD_E_INVALID_PARAMETER;
+
+ cchReaderLen = strlen(rContext->lpcReader);
+ if(*pcchReaderLen < cchReaderLen)
+ rv = SCARD_E_INSUFFICIENT_BUFFER;
+ else /* There's enough room in the buffer */
+ strncpy(mszReaderNames, rContext->lpcReader, cchReaderLen);
+ *pcchReaderLen = cchReaderLen;
+ }
+ else if (pcchReaderLen) /* want the reader length but not the name */
+ *pcchReaderLen = strlen(rContext->lpcReader);
+
+ if (pdwState)
+ *pdwState = SharedReaderState_State(rContext->readerState);
+
+ if (pdwProtocol)
+ *pdwProtocol = SharedReaderState_Protocol(rContext->readerState);
+
+ if (pbAtr) /* want ATR */
+ {
+ int cbAtrLen;
+ if (!pcbAtrLen)
+ return SCARD_E_INVALID_PARAMETER;
+ cbAtrLen = SharedReaderState_CardAtrLength(rContext->readerState);
+
+ if(cbAtrLen >= *pcbAtrLen)
+ rv = SCARD_E_INSUFFICIENT_BUFFER;
+ else
+ {
+ *pcbAtrLen = cbAtrLen;
+ memcpy(pbAtr, SharedReaderState_CardAtr(rContext->readerState), cbAtrLen);
+ }
+ }
+ else if (pcbAtrLen)
+ *pcbAtrLen = SharedReaderState_CardAtrLength(rContext->readerState);
+
+ return rv;
+}
+
+LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout,
+ LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders)
+{
+ /*
+ * Client side function
+ */
+ return SCARD_S_SUCCESS;
+}
+
+#undef SCardControl
+
+LONG SCardControl(SCARDHANDLE hCard, const void *pbSendBuffer,
+ DWORD cbSendLength, void *pbRecvBuffer, LPDWORD pcbRecvLength)
+{
+ // Pre pcsclite 1.3.2 version
+
+ uint32_t dwControlCode = 0;
+
+ uint32_t cbRecvLength = *pcbRecvLength;
+ uint32_t bytesReturned = 0;
+ int32_t rv = SCardControl132(hCard, dwControlCode, pbSendBuffer, cbSendLength,
+ pbRecvBuffer, cbRecvLength, &bytesReturned);
+ *pcbRecvLength = bytesReturned;
+ return rv;
+}
+
+int32_t SCardControl132(SCARDHANDLE hCard, uint32_t dwControlCode,
+ const void *pbSendBuffer, uint32_t cbSendLength,
+ void *pbRecvBuffer, uint32_t cbRecvLength, uint32_t *lpBytesReturned)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ /* 0 bytes returned by default */
+ *lpBytesReturned = 0;
+
+ if (0 == hCard)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*
+ * Make sure no one has a lock on this reader
+ */
+ if ((rv = RFCheckSharing(hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ if (IFD_HVERSION_2_0 == rContext->dwVersion)
+ if (NULL == pbSendBuffer || 0 == cbSendLength)
+ return SCARD_E_INVALID_PARAMETER;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ if (IFD_HVERSION_2_0 == rContext->dwVersion)
+ {
+ /* we must wrap a API 3.0 client in an API 2.0 driver */
+ *lpBytesReturned = cbRecvLength;
+ return IFDControl_v2(rContext, (PUCHAR)pbSendBuffer,
+ cbSendLength, (uint8_t *)pbRecvBuffer, lpBytesReturned);
+ }
+ else
+ if (IFD_HVERSION_3_0 == rContext->dwVersion)
+ return IFDControl(rContext, dwControlCode, pbSendBuffer,
+ cbSendLength, pbRecvBuffer, cbRecvLength, lpBytesReturned);
+ else
+ return SCARD_E_UNSUPPORTED_FEATURE;
+}
+
+LONG SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId,
+ LPBYTE pbAttr, LPDWORD pcbAttrLen)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ if (0 == hCard)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*
+ * Make sure no one has a lock on this reader
+ */
+ if ((rv = RFCheckSharing(hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = IFDGetCapabilities(rContext, dwAttrId, pcbAttrLen, pbAttr);
+ if (rv == IFD_SUCCESS)
+ return SCARD_S_SUCCESS;
+ else
+ if (rv == IFD_ERROR_TAG)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+ else
+ return SCARD_E_NOT_TRANSACTED;
+}
+
+LONG SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId,
+ LPCBYTE pbAttr, DWORD cbAttrLen)
+{
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+
+ if (0 == hCard)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*
+ * Make sure no one has a lock on this reader
+ */
+ if ((rv = RFCheckSharing(hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = IFDSetCapabilities(rContext, dwAttrId, cbAttrLen, (PUCHAR)pbAttr);
+ if (rv == IFD_SUCCESS)
+ return SCARD_S_SUCCESS;
+ else
+ if (rv == IFD_ERROR_TAG)
+ return SCARD_E_UNSUPPORTED_FEATURE;
+ else
+ return SCARD_E_NOT_TRANSACTED;
+}
+
+#define kSCARD_LE_IN_SW2 0x6C
+#define kReadBinaryAPDU 0xB0
+#define kReadBinaryLe 4
+
+LONG SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,
+ LPCBYTE pbSendBuffer, DWORD cbSendLength,
+ LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,
+ LPDWORD pcbRecvLength)
+{
+ /*
+ See for example:
+ NIST IR 6887 "Government Smart Card Interoperability Specification (GSC-IS), v2.1",
+ July 2003
+ http://csrc.nist.gov/publications/nistir/nistir-6887.pdf
+ for info on error conditions. One define is SCARD_LE_IN_SW2
+ */
+ LONG rv;
+ PREADER_CONTEXT rContext = NULL;
+ SCARD_IO_HEADER sSendPci, sRecvPci;
+ DWORD dwRxLength, tempRxLength;
+
+ if (pcbRecvLength == 0)
+ return SCARD_E_INVALID_PARAMETER;
+
+ dwRxLength = *pcbRecvLength;
+ *pcbRecvLength = 0;
+
+ if (hCard == 0)
+ return SCARD_E_INVALID_HANDLE;
+
+ if (pbSendBuffer == NULL || pbRecvBuffer == NULL || pioSendPci == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ /*
+ * Must at least send a 4 bytes APDU
+ */
+ if (cbSendLength < 4)
+ return SCARD_E_INVALID_PARAMETER;
+
+ /*
+ * Must at least have 2 status words even for SCardControl
+ */
+ if (dwRxLength < 2)
+ return SCARD_E_INSUFFICIENT_BUFFER;
+
+ /*
+ * Make sure no one has a lock on this reader
+ */
+ if ((rv = RFCheckSharing(hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFReaderInfoById(hCard, &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure the reader is working properly
+ */
+ rv = RFCheckReaderStatus(rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ rv = RFFindReaderHandle(hCard);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Make sure some event has not occurred
+ */
+ if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
+ return rv;
+
+ /*
+ * Check for some common errors
+ */
+ if (pioSendPci->dwProtocol != SCARD_PROTOCOL_RAW)
+ {
+ if (SharedReaderState_State(rContext->readerState) & SCARD_ABSENT)
+ {
+ return SCARD_E_NO_SMARTCARD;
+ }
+ }
+
+ if (pioSendPci->dwProtocol != SCARD_PROTOCOL_RAW)
+ {
+ if (pioSendPci->dwProtocol != SCARD_PROTOCOL_ANY_OLD)
+ {
+ if (pioSendPci->dwProtocol != SharedReaderState_Protocol(rContext->readerState))
+ {
+ return SCARD_E_PROTO_MISMATCH;
+ }
+ }
+ }
+
+ /*
+ * Quick fix: PC/SC starts at 1 for bit masking but the IFD_Handler
+ * just wants 0 or 1
+ */
+
+ sSendPci.Protocol = 0; /* protocol T=0 by default */
+
+ if (pioSendPci->dwProtocol == SCARD_PROTOCOL_T1)
+ {
+ sSendPci.Protocol = 1;
+ } else if (pioSendPci->dwProtocol == SCARD_PROTOCOL_RAW)
+ {
+ /*
+ * This is temporary ......
+ */
+ sSendPci.Protocol = SCARD_PROTOCOL_RAW;
+ } else if (pioSendPci->dwProtocol == SCARD_PROTOCOL_ANY_OLD)
+ {
+ /* Fix by Amira (Athena) */
+ unsigned long i;
+ unsigned long prot = SharedReaderState_Protocol(rContext->readerState);
+
+ for (i = 0 ; prot != 1 ; i++)
+ prot >>= 1;
+
+ sSendPci.Protocol = i;
+ }
+
+ sSendPci.Length = pioSendPci->cbPciLength;
+
+ /* the protocol number is decoded a few lines above */
+ Log2(PCSC_LOG_DEBUG, "Send Protocol: T=%d", sSendPci.Protocol);
+
+ tempRxLength = dwRxLength;
+
+ if (pioSendPci->dwProtocol == SCARD_PROTOCOL_RAW)
+ {
+ rv = IFDControl_v2(rContext, (PUCHAR)pbSendBuffer , cbSendLength,
+ pbRecvBuffer, &dwRxLength);
+ } else
+ {
+ rv = IFDTransmit(rContext, sSendPci, (PUCHAR)pbSendBuffer,
+ cbSendLength, pbRecvBuffer, &dwRxLength, &sRecvPci);
+ }
+
+ if (pioRecvPci)
+ {
+ pioRecvPci->dwProtocol = sRecvPci.Protocol;
+ pioRecvPci->cbPciLength = sRecvPci.Length;
+ }
+
+ Log3(PCSC_LOG_DEBUG, "IFDControl_v2/IFDTransmit result: 0x%08X, received: %d", rv, dwRxLength);
+ Log3(PCSC_LOG_DEBUG, " pbRecvBuffer: [0]: 0x%02X, [1]: 0x%02X", pbRecvBuffer[0], pbRecvBuffer[1]);
+
+ /*
+ * Check for any errors that might have occurred
+ */
+
+ if (rv != SCARD_S_SUCCESS)
+ {
+ *pcbRecvLength = 0;
+ Log2(PCSC_LOG_ERROR, "Card not transacted: 0x%08lX", rv);
+ return SCARD_E_NOT_TRANSACTED;
+ }
+
+ /*
+ * Available is less than received
+ */
+ if (tempRxLength < dwRxLength)
+ {
+ Log3(PCSC_LOG_DEBUG, "Available is less than received: avail: %d, received: %d", tempRxLength, dwRxLength);
+ *pcbRecvLength = 0;
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ /*
+ * Successful return
+ */
+ *pcbRecvLength = dwRxLength;
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups,
+ LPSTR mszReaders, LPDWORD pcchReaders)
+{
+ /*
+ * Client side function
+ */
+ return SCARD_S_SUCCESS;
+}
+
+LONG SCardCancel(SCARDCONTEXT hContext)
+{
+ /*
+ * Client side function
+ */
+ return SCARD_S_SUCCESS;
+}
+
+static LONG NotifyOfCardReset(DWORD state, PREADER_CONTEXT rContext, SCARDHANDLE hCard)
+{
+ /*
+ * Currently pcsc-lite keeps the card powered constantly
+ * Note that although EndTransaction initially sets dwAction in one
+ * case to IFD_POWER_DOWN, it then sets it to IFD_RESET
+ */
+
+ LONG rv = SCARD_S_SUCCESS, ret = SCARD_S_SUCCESS;
+
+ DWORD tmpCardAtrLength = SharedReaderState_CardAtrLength(rContext->readerState);
+ if (SCARD_RESET_CARD == state)
+ rv = IFDPowerICC(rContext, IFD_RESET, SharedReaderState_CardAtr(rContext->readerState), &tmpCardAtrLength);
+ else
+ {
+ rv = IFDPowerICC(rContext, IFD_POWER_DOWN, SharedReaderState_CardAtr(rContext->readerState), &tmpCardAtrLength);
+ rv = IFDPowerICC(rContext, IFD_POWER_UP, SharedReaderState_CardAtr(rContext->readerState), &tmpCardAtrLength);
+ }
+ SharedReaderState_SetCardAtrLength(rContext->readerState, tmpCardAtrLength);
+
+ /* the protocol is unset after a power on */
+ SharedReaderState_SetProtocol(rContext->readerState, SCARD_PROTOCOL_UNSET);
+
+ /*
+ * Notify the card has been reset
+ * Not doing this could result in deadlock
+ */
+ ret = RFCheckReaderEventState(rContext, hCard);
+
+ /*
+ Note: there is disagreement on which value of rv to use for the switch below:
+
+ SCardReconnect: result of RFCheckReaderEventState
+ SCardDisconnect: result of IFDPowerICC
+ SCardEndTransaction: result of IFDPowerICC
+
+ We use the result of IFDPowerICC here; this seems more sensible
+ */
+ switch (rv)
+ {
+ /* avoid deadlock */
+ case SCARD_W_RESET_CARD:
+ break;
+
+ case SCARD_W_REMOVED_CARD:
+ Log1(PCSC_LOG_ERROR, "card removed");
+ return SCARD_W_REMOVED_CARD;
+
+ /* invalid EventStatus */
+ case SCARD_E_INVALID_VALUE:
+ Log1(PCSC_LOG_ERROR, "invalid EventStatus");
+ return SCARD_F_INTERNAL_ERROR;
+
+ /* invalid hCard, but hCard was widely used some lines above :( */
+ case SCARD_E_INVALID_HANDLE:
+ Log1(PCSC_LOG_ERROR, "invalid handle");
+ return SCARD_F_INTERNAL_ERROR;
+
+ case SCARD_S_SUCCESS:
+ /*
+ * Notify the card has been reset
+ */
+ RFSetReaderEventState(rContext, SCARD_RESET);
+
+ /*
+ * Set up the status bit masks on dwStatus
+ */
+ DWORD readerStateTmp = SharedReaderState_State(rContext->readerState);
+ if (rv == SCARD_S_SUCCESS)
+ {
+ readerStateTmp |= SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_ABSENT;
+ readerStateTmp |= SCARD_POWERED;
+ readerStateTmp |= SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ readerStateTmp &= ~SCARD_SWALLOWED;
+ readerStateTmp &= ~SCARD_UNKNOWN;
+ }
+ else
+ {
+ readerStateTmp |= SCARD_PRESENT;
+ readerStateTmp &= ~SCARD_ABSENT;
+ readerStateTmp |= SCARD_SWALLOWED;
+ readerStateTmp &= ~SCARD_POWERED;
+ readerStateTmp &= ~SCARD_NEGOTIABLE;
+ readerStateTmp &= ~SCARD_SPECIFIC;
+ readerStateTmp &= ~SCARD_UNKNOWN;
+ SharedReaderState_SetCardAtrLength(rContext->readerState, 0);
+ }
+ SharedReaderState_SetState(rContext->readerState, readerStateTmp);
+
+ if (SharedReaderState_CardAtrLength(rContext->readerState) > 0)
+ {
+ Log1(PCSC_LOG_ERROR, "Reset complete.");
+ LogXxd(PCSC_LOG_DEBUG, "Card ATR: ", SharedReaderState_CardAtr(rContext->readerState),
+ SharedReaderState_CardAtrLength(rContext->readerState));
+ }
+ else
+ {
+ DWORD dwStatus, dwAtrLen;
+ UCHAR ucAtr[MAX_ATR_SIZE];
+
+ Log1(PCSC_LOG_ERROR, "Error resetting card.");
+ IFDStatusICC(rContext, &dwStatus, ucAtr, &dwAtrLen);
+ if (dwStatus & SCARD_PRESENT)
+ return SCARD_W_UNRESPONSIVE_CARD;
+ else
+ return SCARD_E_NO_SMARTCARD;
+ }
+ break;
+ default:
+ Log2(PCSC_LOG_ERROR, "invalid retcode from RFCheckReaderEventState (%X)", rv);
+ return SCARD_F_INTERNAL_ERROR;
+ }
+ return SCARD_S_SUCCESS;
+}
+
+static LONG EjectCard(PREADER_CONTEXT rContext)
+{
+ LONG rv = SCARD_S_SUCCESS;
+
+ UCHAR controlBuffer[5];
+ UCHAR receiveBuffer[MAX_BUFFER_SIZE];
+ DWORD receiveLength;
+
+ /*
+ * Set up the CTBCS command for Eject ICC
+ */
+ controlBuffer[0] = 0x20;
+ controlBuffer[1] = 0x15;
+ controlBuffer[2] = (rContext->dwSlot & 0x0000FFFF) + 1;
+ controlBuffer[3] = 0x00;
+ controlBuffer[4] = 0x00;
+ receiveLength = 2;
+ rv = IFDControl_v2(rContext, controlBuffer, 5, receiveBuffer, &receiveLength);
+
+ if (rv == SCARD_S_SUCCESS)
+ {
+ if (receiveLength == 2 && receiveBuffer[0] == 0x90) // Successful
+ Log1(PCSC_LOG_ERROR, "Card ejected successfully.");
+ else
+ {
+ Log3(PCSC_LOG_ERROR, "Error ejecting card: %02X%02X", receiveBuffer[0], receiveBuffer[1]);
+ rv = SCARD_F_UNKNOWN_ERROR;
+ }
+ }
+ else
+ Log1(PCSC_LOG_ERROR, "Error ejecting card.");
+
+ return rv;
+}
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2003
+ * David Corcoran <corcoran at linuxnet.com>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard.h 2072 2006-06-06 09:31:07Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles smartcard reader communications.
+ */
+
+#ifndef __winscard_h__
+#define __winscard_h__
+
+#include <PCSC/pcsclite.h>
+#include <stdint.h>
+//#include "pcscexport.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef PCSC_API
+#define PCSC_API
+#endif
+
+ PCSC_API int32_t SCardEstablishContext(uint32_t dwScope,
+ const void *pvReserved1, const void *pvReserved2, LPSCARDCONTEXT phContext);
+
+ PCSC_API int32_t SCardReleaseContext(SCARDCONTEXT hContext);
+
+ PCSC_API int32_t SCardIsValidContext(SCARDCONTEXT hContext);
+
+ PCSC_API int32_t SCardSetTimeout(SCARDCONTEXT hContext, uint32_t dwTimeout);
+
+ PCSC_API int32_t SCardConnect(SCARDCONTEXT hContext,
+ const char *szReader,
+ uint32_t dwShareMode,
+ uint32_t dwPreferredProtocols,
+ LPSCARDHANDLE phCard, uint32_t *pdwActiveProtocol);
+
+ PCSC_API int32_t SCardReconnect(SCARDHANDLE hCard,
+ uint32_t dwShareMode,
+ uint32_t dwPreferredProtocols,
+ uint32_t dwInitialization, uint32_t *pdwActiveProtocol);
+
+ PCSC_API int32_t SCardDisconnect(SCARDHANDLE hCard, uint32_t dwDisposition);
+
+ PCSC_API int32_t SCardBeginTransaction(SCARDHANDLE hCard);
+
+ PCSC_API int32_t SCardEndTransaction(SCARDHANDLE hCard, uint32_t dwDisposition);
+
+ PCSC_API int32_t SCardCancelTransaction(SCARDHANDLE hCard);
+
+ PCSC_API int32_t SCardStatus(SCARDHANDLE hCard,
+ char *mszReaderNames, uint32_t *pcchReaderLen,
+ uint32_t *pdwState,
+ uint32_t *pdwProtocol,
+ unsigned char *pbAtr, uint32_t *pcbAtrLen);
+
+ PCSC_API int32_t SCardGetStatusChange(SCARDCONTEXT hContext,
+ uint32_t dwTimeout,
+ LPSCARD_READERSTATE_A rgReaderStates, uint32_t cReaders);
+
+ PCSC_API int32_t SCardControl(SCARDHANDLE hCard,
+ const void *pbSendBuffer, uint32_t cbSendLength,
+ void *pbRecvBuffer, uint32_t *pcbRecvLength);
+
+ PCSC_API int32_t SCardControl132(SCARDHANDLE hCard, uint32_t dwControlCode,
+ const void *pbSendBuffer, uint32_t cbSendLength,
+ void *pbRecvBuffer, uint32_t cbRecvLength, uint32_t *lpBytesReturned);
+
+ PCSC_API int32_t SCardTransmit(SCARDHANDLE hCard,
+ LPCSCARD_IO_REQUEST pioSendPci,
+ const unsigned char *pbSendBuffer, uint32_t cbSendLength,
+ LPSCARD_IO_REQUEST pioRecvPci,
+ unsigned char *pbRecvBuffer, uint32_t *pcbRecvLength);
+
+ PCSC_API int32_t SCardListReaderGroups(SCARDCONTEXT hContext,
+ char *mszGroups, uint32_t *pcchGroups);
+
+ PCSC_API int32_t SCardListReaders(SCARDCONTEXT hContext,
+ const char *mszGroups,
+ char *mszReaders, uint32_t *pcchReaders);
+
+ PCSC_API int32_t SCardCancel(SCARDCONTEXT hContext);
+
+ PCSC_API int32_t SCardGetAttrib(SCARDHANDLE hCard, uint32_t dwAttrId,
+ uint8_t *pbAttr, uint32_t *pcbAttrLen);
+
+ PCSC_API int32_t SCardSetAttrib(SCARDHANDLE hCard, uint32_t dwAttrId,
+ const uint8_t *pbAttr, uint32_t cbAttrLen);
+
+ void SCardUnload(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+/*
+ To support the newer version of SCardControl, we define it
+ as follows. The old version number was 1.1.2, the new call
+ appears in 1.3.2 of pcsc-lite (or perhaps earlier).
+*/
+
+#if !defined(USE_SCARD_CONTROL_112)
+#define SCardControl SCardControl132
+#endif /* USE_SCARD_CONTROL_112 */
+
+#endif
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_clnt.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_clnt.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_clnt.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,3408 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard_clnt.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard_clnt.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This handles smartcard reader communications and
+ * forwarding requests over message queues.
+ *
+ * Here is exposed the API for client applications.
+ */
+
+#include <assert.h>
+#include "config.h"
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/_endian.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "pcscexport.h"
+#include "winscard.h"
+#include "debug.h"
+#include "thread_generic.h"
+
+#include "readerfactory.h"
+#include "eventhandler.h"
+#include "sys_generic.h"
+#include "winscard_msg.h"
+#include "readerstate.h"
+
+#include <security_utilities/debugging.h>
+
+/** used for backward compatibility */
+#define SCARD_PROTOCOL_ANY_OLD 0x1000
+
+#ifndef min
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#define PROFILE_START
+#define PROFILE_END
+
+/**
+ * Represents an Application Context Channel.
+ * A channel belongs to an Application Context (\c _psContextMap).
+ */
+struct _psChannelMap
+{
+ SCARDHANDLE hCard;
+ LPSTR readerName;
+};
+
+typedef struct _psChannelMap CHANNEL_MAP, *PCHANNEL_MAP;
+
+/**
+ * @brief Represents the an Application Context on the Client side.
+ *
+ * An Application Context contains Channels (\c _psChannelMap).
+ */
+static struct _psContextMap
+{
+ DWORD dwClientID; /** Client Connection ID */
+ SCARDCONTEXT hContext; /** Application Context ID */
+ DWORD contextBlockStatus;
+ PCSCLITE_MUTEX_T mMutex; /** Mutex for this context */
+ CHANNEL_MAP psChannelMap[PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS];
+} psContextMap[PCSCLITE_MAX_APPLICATION_CONTEXTS];
+
+/**
+ * Make sure the initialization code is executed only once.
+ */
+static short isExecuted = 0;
+
+/**
+ * Memory mapped address used to read status information about the readers.
+ * Each element in the vector \ref readerStates makes references to a part of
+ * the memory mapped.
+ */
+static int mapAddr = 0;
+
+/**
+ * Ensure that some functions be accessed in thread-safe mode.
+ * These function's names finishes with "TH".
+ */
+static PCSCLITE_MUTEX clientMutex = PTHREAD_MUTEX_INITIALIZER;
+
+/**
+ * Pointers to a memory mapped area used to read status information about the
+ * readers.
+ * Each element in the vector \ref readerStates makes references to a part of
+ * the memory mapped \ref mapAddr.
+ */
+static PREADER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS];
+
+PCSC_API SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
+PCSC_API SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
+PCSC_API SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
+
+
+static LONG SCardAddContext(SCARDCONTEXT, DWORD);
+static LONG SCardGetContextIndice(SCARDCONTEXT);
+static LONG SCardGetContextIndiceTH(SCARDCONTEXT);
+static LONG SCardRemoveContext(SCARDCONTEXT);
+
+static LONG SCardAddHandle(SCARDHANDLE, DWORD, LPSTR);
+static LONG SCardGetIndicesFromHandle(SCARDHANDLE, PDWORD, PDWORD);
+static LONG SCardGetIndicesFromHandleTH(SCARDHANDLE, PDWORD, PDWORD);
+static LONG SCardRemoveHandle(SCARDHANDLE);
+
+static LONG SCardGetSetAttrib(SCARDHANDLE hCard, int command, DWORD dwAttrId,
+ LPBYTE pbAttr, LPDWORD pcbAttrLen);
+
+static LONG SCardCheckDaemonAvailability(void);
+static int SCardInitializeOnce();
+
+static int SHMClientCommunicationTimeout();
+
+/*
+ * Thread safety functions
+ */
+inline static LONG SCardLockThread(void);
+inline static LONG SCardUnlockThread(void);
+
+static LONG SCardEstablishContextTH(DWORD, LPCVOID, LPCVOID, LPSCARDCONTEXT);
+
+/**
+ * @brief Creates an Application Context to the PC/SC Resource Manager.
+
+ * This must be the first function called in a PC/SC application.
+ * This is a thread-safe wrapper to the function SCardEstablishContextTH().
+ *
+ * @param[in] dwScope Scope of the establishment.
+ * This can either be a local or remote connection.
+ * <ul>
+ * <li>\ref SCARD_SCOPE_USER - Not used.
+ * <li>\ref SCARD_SCOPE_TERMINAL - Not used.
+ * <li>\ref SCARD_SCOPE_GLOBAL - Not used.
+ * <li>\ref SCARD_SCOPE_SYSTEM - Services on the local machine.
+ * </ul>
+ * @param[in] pvReserved1 Reserved for future use. Can be used for remote connection.
+ * @param[in] pvReserved2 Reserved for future use.
+ * @param[out] phContext Returned Application Context.
+ *
+ * @return Connection status.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NO_SERVICE The server is not runing (\ref SCARD_E_NO_SERVICE)
+ * @retval SCARD_E_INVALID_VALUE Invalid scope type passed (\ref SCARD_E_INVALID_VALUE )
+ * @retval SCARD_E_INVALID_PARAMETER phContext is null (\ref SCARD_E_INVALID_PARAMETER)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * @endcode
+ */
+LONG SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
+ LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+{
+ LONG rv;
+
+ PROFILE_START
+
+ SCardLockThread();
+ rv = SCardEstablishContextTH(dwScope, pvReserved1,
+ pvReserved2, phContext);
+ SCardUnlockThread();
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * @brief Creates a communication context to the PC/SC Resource
+ * Manager.
+ *
+ * This function shuld not be called directly. Instead, the thread-safe
+ * function SCardEstablishContext() should be called.
+ *
+ * @param[in] dwScope Scope of the establishment.
+ * This can either be a local or remote connection.
+ * <ul>
+ * <li>\ref SCARD_SCOPE_USER - Not used.
+ * <li>\ref SCARD_SCOPE_TERMINAL - Not used.
+ * <li>\ref SCARD_SCOPE_GLOBAL - Not used.
+ * <li>\ref SCARD_SCOPE_SYSTEM - Services on the local machine.
+ * </ul>
+ * @param[in] pvReserved1 Reserved for future use. Can be used for remote connection.
+ * @param[in] pvReserved2 Reserved for future use.
+ * @param[out] phContext Returned reference to this connection.
+ *
+ * @return Connection status.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NO_SERVICE The server is not runing (\ref SCARD_E_NO_SERVICE)
+ * @retval SCARD_E_INVALID_PARAMETER phContext is null. (\ref SCARD_E_INVALID_PARAMETER)
+ * @retval SCARD_E_INVALID_VALUE Invalid scope type passed (\ref SCARD_E_INVALID_VALUE)
+ */
+static LONG SCardEstablishContextTH(DWORD dwScope, LPCVOID pvReserved1,
+ LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+{
+ LONG rv;
+ establish_struct scEstablishStruct;
+ sharedSegmentMsg msgStruct;
+ DWORD dwClientID = 0;
+
+ if (phContext == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+ else
+ *phContext = 0;
+
+ /* Check if the server is running */
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Do this only once:
+ * - Initialize debug of need.
+ * - Set up the memory mapped structures for reader states.
+ * - Allocate each reader structure.
+ * - Initialize context struct.
+ */
+ if (isExecuted == 0)
+ {
+ SCardInitializeOnce();
+ isExecuted = 1;
+ }
+
+ /* Establishes a connection to the server */
+ if (SHMClientSetupSession(&dwClientID) != 0)
+ {
+ SYS_CloseFile(mapAddr);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ { /* exchange client/server protocol versions */
+ sharedSegmentMsg msgStruct;
+ version_struct *veStr = (version_struct *)&msgStruct.data;
+ veStr->major = PROTOCOL_VERSION_MAJOR;
+ veStr->minor = PROTOCOL_VERSION_MINOR;
+ htonlVersionStruct(veStr);
+
+ if (-1 == WrapSHMWrite(CMD_VERSION, dwClientID, sizeof(version_struct), SHMClientCommunicationTimeout(), veStr))
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Read a message from the server
+ */
+ if (-1 == SHMClientReadMessage(&msgStruct, dwClientID, sizeof(version_struct), SHMClientCommunicationTimeout()))
+ {
+ Log1(PCSC_LOG_ERROR, "Your pcscd is too old and does not support CMD_VERSION");
+ return SCARD_F_COMM_ERROR;
+ }
+
+ ntohlVersionStruct(veStr);
+ Log3(PCSC_LOG_ERROR, "Server is protocol version %d:%d",
+ veStr->major, veStr->minor);
+
+ if (veStr->rv != SCARD_S_SUCCESS)
+ return veStr->rv;
+ }
+
+ if (dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL &&
+ dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL)
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ /*
+ * Try to establish an Application Context with the server
+ */
+ scEstablishStruct.dwScope = dwScope;
+ scEstablishStruct.phContext = 0;
+ scEstablishStruct.rv = 0;
+
+ htonlEstablishStruct(&scEstablishStruct);
+ rv = WrapSHMWrite(SCARD_ESTABLISH_CONTEXT, dwClientID,
+ sizeof(scEstablishStruct), PCSCLITE_MCLIENT_ATTEMPTS,
+ (void *) &scEstablishStruct);
+
+ if (rv == -1)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Read the response from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, dwClientID, sizeof(establish_struct), SHMClientCommunicationTimeout());
+
+ if (rv == -1)
+ return SCARD_F_COMM_ERROR;
+
+ memcpy(&scEstablishStruct, &msgStruct.data, sizeof(scEstablishStruct));
+ ntohlEstablishStruct(&scEstablishStruct);
+
+ if (scEstablishStruct.rv != SCARD_S_SUCCESS)
+ return scEstablishStruct.rv;
+
+ *phContext = scEstablishStruct.phContext;
+
+ /*
+ * Allocate the new hContext - if allocator full return an error
+ */
+ rv = SCardAddContext(*phContext, dwClientID);
+
+ return rv;
+}
+
+/**
+ * @brief This function destroys a communication context to the PC/SC Resource
+ * Manager. This must be the last function called in a PC/SC application.
+ *
+ * @param[in] hContext Connection context to be closed.
+ *
+ * @return Connection status.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardReleaseContext(hContext);
+ * @endcode
+ */
+LONG SCardReleaseContext(SCARDCONTEXT hContext)
+{
+ LONG rv;
+ release_struct scReleaseStruct;
+ sharedSegmentMsg msgStruct;
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this context has been opened
+ */
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ scReleaseStruct.hContext = hContext;
+ scReleaseStruct.rv = 0;
+ htonlReleaseStruct(&scReleaseStruct);
+
+ rv = WrapSHMWrite(SCARD_RELEASE_CONTEXT, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scReleaseStruct),
+ PCSCLITE_MCLIENT_ATTEMPTS, (void *) &scReleaseStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(release_struct), SHMClientCommunicationTimeout());
+ memcpy(&scReleaseStruct, &msgStruct.data, sizeof(scReleaseStruct));
+ ntohlReleaseStruct(&scReleaseStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ /*
+ * Remove the local context from the stack
+ */
+ SCardLockThread();
+ SCardRemoveContext(hContext);
+ SCardUnlockThread();
+
+ PROFILE_END
+
+ return scReleaseStruct.rv;
+}
+
+/**
+ * @deprecated
+ * This function is not in Microsoft(R) WinSCard API and is deprecated
+ * in pcsc-lite API.
+ * The function does not do anything except returning \ref SCARD_S_SUCCESS.
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ * @param[in] dwTimeout New timeout value.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ */
+LONG SCardSetTimeout(SCARDCONTEXT hContext, DWORD dwTimeout)
+{
+ /*
+ * Deprecated
+ */
+
+ return SCARD_S_SUCCESS;
+}
+
+/**
+ * This function establishes a connection to the friendly name of the reader
+ * specified in szReader. The first connection will power up and perform a
+ * reset on the card.
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ * @param[in] szReader Reader name to connect to.
+ * @param[in] dwShareMode Mode of connection type: exclusive or shared.
+ * <ul>
+ * <li>\ref SCARD_SHARE_SHARED - This application will allow others to share
+ * the reader.
+ * <li>\ref SCARD_SHARE_EXCLUSIVE - This application will NOT allow others to
+ * share the reader.
+ * <li>\ref SCARD_SHARE_DIRECT - Direct control of the reader, even without a
+ * card. \ref SCARD_SHARE_DIRECT can be used before using SCardControl() to
+ * send control commands to the reader even if a card is not present in the
+ * reader.
+ * </ul>
+ * @param[in] dwPreferredProtocols Desired protocol use.
+ * <ul>
+ * <li>\ref SCARD_PROTOCOL_T0 - Use the T=0 protocol.
+ * <li>\ref SCARD_PROTOCOL_T1 - Use the T=1 protocol.
+ * <li>\ref SCARD_PROTOCOL_RAW - Use with memory type cards.
+ * </ul>
+ * dwPreferredProtocols is a bit mask of acceptable protocols for the
+ * connection. You can use (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1) if you
+ * do not have a preferred protocol.
+ * @param[out] phCard Handle to this connection.
+ * @param[out] pdwActiveProtocol Established protocol to this connection.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hContext handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INVALID_VALUE Invalid sharing mode, requested protocol, or reader name (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_NOT_READY Could not allocate the desired port (\ref SCARD_E_NOT_READY)
+ * @retval SCARD_E_READER_UNAVAILABLE Could not power up the reader or card (\ref SCARD_E_READER_UNAVAILABLE)
+ * @retval SCARD_E_SHARING_VIOLATION Someone else has exclusive rights (\ref SCARD_E_SHARING_VIOLATION)
+ * @retval SCARD_E_UNSUPPORTED_FEATURE Protocol not supported (\ref SCARD_E_UNSUPPORTED_FEATURE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * @endcode
+ */
+LONG SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader,
+ DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,
+ LPDWORD pdwActiveProtocol)
+{
+ LONG rv;
+ connect_struct scConnectStruct = {0,};
+ sharedSegmentMsg msgStruct = {0,};
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ /*
+ * Check for NULL parameters
+ */
+ if (phCard == NULL || pdwActiveProtocol == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+ else
+ *phCard = 0;
+
+ if (szReader == NULL)
+ return SCARD_E_UNKNOWN_READER;
+
+ /*
+ * Check for uninitialized strings
+ */
+ if (strlen(szReader) > MAX_READERNAME)
+ return SCARD_E_INVALID_VALUE;
+
+ if (!(dwPreferredProtocols & SCARD_PROTOCOL_T0) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_T1) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_RAW) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD))
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this context has been opened
+ */
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ strncpy(scConnectStruct.szReader, szReader, MAX_READERNAME);
+
+ scConnectStruct.hContext = hContext;
+ scConnectStruct.dwShareMode = dwShareMode;
+ scConnectStruct.dwPreferredProtocols = dwPreferredProtocols;
+ scConnectStruct.phCard = *phCard;
+ scConnectStruct.pdwActiveProtocol = *pdwActiveProtocol;
+ htonlConnectStruct(&scConnectStruct);
+
+ rv = WrapSHMWrite(SCARD_CONNECT, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scConnectStruct),
+ SHMClientCommunicationTimeout(), (void *) &scConnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(connect_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scConnectStruct, &msgStruct.data, sizeof(scConnectStruct));
+ ntohlConnectStruct(&scConnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ *phCard = scConnectStruct.phCard;
+ *pdwActiveProtocol = scConnectStruct.pdwActiveProtocol;
+
+ if (scConnectStruct.rv == SCARD_S_SUCCESS)
+ {
+ /*
+ * Keep track of the handle locally
+ */
+ rv = SCardAddHandle(*phCard, dwContextIndex, (LPSTR) szReader);
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return rv;
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return scConnectStruct.rv;
+}
+
+/**
+ * @brief This function reestablishes a connection to a reader that was previously
+ * connected to using SCardConnect().
+ *
+ * In a multi application environment it is possible for an application to reset
+ * the card in shared mode. When this occurs any other application trying to
+ * access certain commands will be returned the value SCARD_W_RESET_CARD. When
+ * this occurs SCardReconnect() must be called in order to acknowledge that
+ * the card was reset and allow it to change it's state accordingly.
+ *
+ * @param[in] hCard Handle to a previous call to connect.
+ * @param[in] dwShareMode Mode of connection type: exclusive/shared.
+ * <ul>
+ * <li>\ref SCARD_SHARE_SHARED - This application will allow others to share
+ * the reader.
+ * <li>\ref SCARD_SHARE_EXCLUSIVE - This application will NOT allow others to
+ * share the reader.
+ * </ul>
+ * @param[in] dwPreferredProtocols Desired protocol use.
+ * <ul>
+ * <li>\ref SCARD_PROTOCOL_T0 - Use the T=0 protocol.
+ * <li>\ref SCARD_PROTOCOL_T1 - Use the T=1 protocol.
+ * <li>\ref SCARD_PROTOCOL_RAW - Use with memory type cards.
+ * </ul>
+ * \p dwPreferredProtocols is a bit mask of acceptable protocols for
+ * the connection. You can use (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
+ * if you do not have a preferred protocol.
+ * @param[in] dwInitialization Desired action taken on the card/reader.
+ * <ul>
+ * <li>\ref SCARD_LEAVE_CARD - Do nothing.
+ * <li>\ref SCARD_RESET_CARD - Reset the card (warm reset).
+ * <li>\ref SCARD_UNPOWER_CARD - Unpower the card (cold reset).
+ * <li>\ref SCARD_EJECT_CARD - Eject the card.
+ * </ul>
+ * @param[out] pdwActiveProtocol Established protocol to this connection.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid \p hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_NOT_READY Could not allocate the desired port (\ref SCARD_E_NOT_READY)
+ * @retval SCARD_E_INVALID_VALUE Invalid sharing mode, requested protocol, or reader name (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed (\ref SCARD_E_READER_UNAVAILABLE)
+ * @retval SCARD_E_UNSUPPORTED_FEATURE Protocol not supported (\ref SCARD_E_UNSUPPORTED_FEATURE)
+ * @retval SCARD_E_SHARING_VIOLATION Someone else has exclusive rights (\ref SCARD_E_SHARING_VIOLATION)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol, dwSendLength, dwRecvLength;
+ * LONG rv;
+ * BYTE pbRecvBuffer[10];
+ * BYTE pbSendBuffer[] = {0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00};
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * ...
+ * dwSendLength = sizeof(pbSendBuffer);
+ * dwRecvLength = sizeof(pbRecvBuffer);
+ * rv = SCardTransmit(hCard, SCARD_PCI_T0, pbSendBuffer, dwSendLength, &pioRecvPci, pbRecvBuffer, &dwRecvLength);
+ * / * Card has been reset by another application * /
+ * if (rv == SCARD_W_RESET_CARD)
+ * {
+ * rv = SCardReconnect(hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &dwActiveProtocol);
+ * }
+ * @endcode
+ */
+LONG SCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode,
+ DWORD dwPreferredProtocols, DWORD dwInitialization,
+ LPDWORD pdwActiveProtocol)
+{
+ LONG rv;
+ reconnect_struct scReconnectStruct;
+ sharedSegmentMsg msgStruct;
+ int i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ if (dwInitialization != SCARD_LEAVE_CARD &&
+ dwInitialization != SCARD_RESET_CARD &&
+ dwInitialization != SCARD_UNPOWER_CARD &&
+ dwInitialization != SCARD_EJECT_CARD)
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ if (!(dwPreferredProtocols & SCARD_PROTOCOL_T0) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_T1) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_RAW) &&
+ !(dwPreferredProtocols & SCARD_PROTOCOL_ANY_OLD))
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ if (pdwActiveProtocol == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ scReconnectStruct.hCard = hCard;
+ scReconnectStruct.dwShareMode = dwShareMode;
+ scReconnectStruct.dwPreferredProtocols = dwPreferredProtocols;
+ scReconnectStruct.dwInitialization = dwInitialization;
+ scReconnectStruct.pdwActiveProtocol = *pdwActiveProtocol;
+ htonlReconnectStruct(&scReconnectStruct);
+
+ rv = WrapSHMWrite(SCARD_RECONNECT, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scReconnectStruct),
+ SHMClientCommunicationTimeout(), (void *) &scReconnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(reconnect_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scReconnectStruct, &msgStruct.data, sizeof(scReconnectStruct));
+ ntohlReconnectStruct(&scReconnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ *pdwActiveProtocol = scReconnectStruct.pdwActiveProtocol;
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return scReconnectStruct.rv;
+}
+
+/**
+ * This function terminates a connection to the connection made through
+ * SCardConnect(). dwDisposition can have the following values:
+ *
+ * @param[in] hCard Connection made from SCardConnect.
+ * @param[in] dwDisposition Reader function to execute.
+ * <ul>
+ * <li>\ref SCARD_LEAVE_CARD - Do nothing.
+ * <li>\ref SCARD_RESET_CARD - Reset the card (warm reset).
+ * <li>\ref SCARD_UNPOWER_CARD - Unpower the card (cold reset).
+ * <li>\ref SCARD_EJECT_CARD - Eject the card.
+ * </ul>
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful(\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid \p hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INVALID_VALUE - Invalid \p dwDisposition (\ref SCARD_E_INVALID_VALUE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);
+ * @endcode
+ */
+LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
+{
+ LONG rv;
+ disconnect_struct scDisconnectStruct;
+ sharedSegmentMsg msgStruct;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ if (dwDisposition != SCARD_LEAVE_CARD &&
+ dwDisposition != SCARD_RESET_CARD &&
+ dwDisposition != SCARD_UNPOWER_CARD &&
+ dwDisposition != SCARD_EJECT_CARD)
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ scDisconnectStruct.hCard = hCard;
+ scDisconnectStruct.dwDisposition = dwDisposition;
+ htonlDisconnectStruct(&scDisconnectStruct);
+
+ rv = WrapSHMWrite(SCARD_DISCONNECT, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scDisconnectStruct),
+ SHMClientCommunicationTimeout(), (void *) &scDisconnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(disconnect_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scDisconnectStruct, &msgStruct.data, sizeof(scDisconnectStruct));
+ ntohlDisconnectStruct(&scDisconnectStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ SCardRemoveHandle(hCard);
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return scDisconnectStruct.rv;
+}
+
+/**
+ * @brief This function establishes a temporary exclusive access mode for
+ * doing a series of commands or transaction.
+ *
+ * You might want to use this when you are selecting a few files and then
+ * writing a large file so you can make sure that another application will
+ * not change the current file. If another application has a lock on this
+ * reader or this application is in \ref SCARD_SHARE_EXCLUSIVE there will be no
+ * action taken.
+ *
+ * @param[in] hCard Connection made from SCardConnect.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_SHARING_VIOLATION Someone else has exclusive rights (\ref SCARD_E_SHARING_VIOLATION)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed (\ref SCARD_E_READER_UNAVAILABLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * rv = SCardBeginTransaction(hCard);
+ * ...
+ * / * Do some transmit commands * /
+ * @endcode
+ */
+LONG SCardBeginTransaction(SCARDHANDLE hCard)
+{
+
+ LONG rv;
+ begin_struct txBeginStruct = {0,}, rxBeginStruct = {0,};
+ int i;
+ sharedSegmentMsg msgStruct = {0,};
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ secdebug("pcscd", "SCardBeginTransaction: initial request: hCard: 0x%08X", hCard);
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ txBeginStruct.hCard = hCard;
+ htonlBeginStruct(&txBeginStruct);
+
+ /*
+ * Query the server every so often until the sharing violation ends
+ * and then hold the lock for yourself.
+ */
+
+ do
+ {
+ rv = WrapSHMWrite(SCARD_BEGIN_TRANSACTION, psContextMap[dwContextIndex].dwClientID,
+ sizeof(txBeginStruct),
+ SHMClientCommunicationTimeout(), (void *) &txBeginStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(begin_struct), SHMClientCommunicationTimeout());
+ memcpy(&rxBeginStruct, &msgStruct.data, sizeof(rxBeginStruct));
+ ntohlBeginStruct(&rxBeginStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ }
+ while (rxBeginStruct.rv == SCARD_E_SHARING_VIOLATION);
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+ secdebug("pcscd", "SCardBeginTransaction: hCard: 0x%08X, returning: 0x%08X", rxBeginStruct.hCard, rxBeginStruct.rv);
+
+ return rxBeginStruct.rv;
+}
+
+/**
+ * @brief This function ends a previously begun transaction.
+ *
+ * The calling application must be the owner of the previously begun
+ * transaction or an error will occur.
+ *
+ * @param[in] hCard Connection made from SCardConnect.
+ * @param[in] dwDisposition Action to be taken on the reader.
+ * The disposition action is not currently used in this release.
+ * <ul>
+ * <li>\ref SCARD_LEAVE_CARD - Do nothing.
+ * <li>\ref SCARD_RESET_CARD - Reset the card.
+ * <li>\ref SCARD_UNPOWER_CARD - Unpower the card.
+ * <li>\ref SCARD_EJECT_CARD - Eject the card.
+ * </ul>
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_SHARING_VIOLATION Someone else has exclusive rights (\ref SCARD_E_SHARING_VIOLATION)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed (\ref SCARD_E_READER_UNAVAILABLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * rv = SCardBeginTransaction(hCard);
+ * ...
+ * / * Do some transmit commands * /
+ * ...
+ * rv = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
+ * @endcode
+ */
+LONG SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)
+{
+ LONG rv;
+ end_struct scEndStruct;
+ sharedSegmentMsg msgStruct;
+ int randnum, i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ secdebug("pcscd", "SCardEndTransaction: initial request: hCard: 0x%08X, dwDisposition: 0x%04X",
+ hCard, dwDisposition);
+ /*
+ * Zero out everything
+ */
+ randnum = 0;
+
+ if (dwDisposition != SCARD_LEAVE_CARD &&
+ dwDisposition != SCARD_RESET_CARD &&
+ dwDisposition != SCARD_UNPOWER_CARD &&
+ dwDisposition != SCARD_EJECT_CARD)
+ {
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ scEndStruct.hCard = hCard;
+ scEndStruct.dwDisposition = dwDisposition;
+ htonlEndStruct(&scEndStruct);
+
+ rv = WrapSHMWrite(SCARD_END_TRANSACTION, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scEndStruct),
+ SHMClientCommunicationTimeout(), (void *) &scEndStruct);
+ secdebug("pcscd", "SCardEndTransaction: WrapSHMWrite result: 0x%08X", rv);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(end_struct), SHMClientCommunicationTimeout());
+ secdebug("pcscd", "SCardEndTransaction: SHMClientRead result: 0x%08X", rv);
+
+ memcpy(&scEndStruct, &msgStruct.data, sizeof(scEndStruct));
+ ntohlEndStruct(&scEndStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ /*
+ * This helps prevent starvation
+ */
+ randnum = SYS_Random(randnum, 1000.0, 10000.0);
+ SYS_USleep(randnum);
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ secdebug("pcscd", "SCardEndTransaction: returning: 0x%08X", scEndStruct.rv);
+ return scEndStruct.rv;
+}
+
+/**
+ * @deprecated
+ * This function is not in Microsoft(R) WinSCard API and is deprecated
+ * in pcsc-lite API.
+ */
+LONG SCardCancelTransaction(SCARDHANDLE hCard)
+{
+ LONG rv;
+ cancel_struct scCancelStruct;
+ sharedSegmentMsg msgStruct;
+ int i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ scCancelStruct.hCard = hCard;
+ htonlCancelStruct(&scCancelStruct);
+
+ rv = WrapSHMWrite(SCARD_CANCEL_TRANSACTION, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scCancelStruct),
+ SHMClientCommunicationTimeout(), (void *) &scCancelStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(cancel_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scCancelStruct, &msgStruct.data, sizeof(scCancelStruct));
+ ntohlCancelStruct(&scCancelStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return scCancelStruct.rv;
+}
+
+/**
+ * @brief This function returns the current status of the reader connected to by hCard.
+ *
+ * It's friendly name will be stored in szReaderName. pcchReaderLen will be
+ * the size of the allocated buffer for szReaderName, while pcbAtrLen will
+ * be the size of the allocated buffer for pbAtr. If either of these is too
+ * small, the function will return with \ref SCARD_E_INSUFFICIENT_BUFFER and the
+ * necessary size in pcchReaderLen and pcbAtrLen. The current state, and
+ * protocol will be stored in pdwState and pdwProtocol respectively.
+ *
+ * @param[in] hCard Connection made from SCardConnect.
+ * @param mszReaderNames [inout] Friendly name of this reader.
+ * @param pcchReaderLen [inout] Size of the szReaderName multistring.
+ * @param[out] pdwState Current state of this reader. pdwState
+ * is a DWORD possibly OR'd with the following values:
+ * <ul>
+ * <li>\ref SCARD_ABSENT - There is no card in the reader.
+ * <li>\ref SCARD_PRESENT - There is a card in the reader, but it has not
+ * been moved into position for use.
+ * <li>\ref SCARD_SWALLOWED - There is a card in the reader in position for
+ * use. The card is not powered.
+ * <li>\ref SCARD_POWERED - Power is being provided to the card, but the
+ * reader driver is unaware of the mode of the card.
+ * <li>\ref SCARD_NEGOTIABLE - The card has been reset and is awaiting PTS
+ * negotiation.
+ * <li>\ref SCARD_SPECIFIC - The card has been reset and specific
+ * communication protocols have been established.
+ * </ul>
+ * @param[out] pdwProtocol Current protocol of this reader.
+ * <ul>
+ * <li>\ref SCARD_PROTOCOL_T0 Use the T=0 protocol.
+ * <li>\ref SCARD_PROTOCOL_T1 Use the T=1 protocol.
+ * </ul>
+ * @param[out] pbAtr Current ATR of a card in this reader.
+ * @param[out] pcbAtrLen Length of ATR.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INSUFFICIENT_BUFFER Not enough allocated memory for szReaderName or for pbAtr (\ref SCARD_E_INSUFFICIENT_BUFFER)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed (\ref SCARD_E_READER_UNAVAILABLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * DWORD dwState, dwProtocol, dwAtrLen, dwReaderLen;
+ * BYTE pbAtr[MAX_ATR_SIZE];
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * ...
+ * dwAtrLen = sizeof(pbAtr);
+ * rv=SCardStatus(hCard, NULL, &dwReaderLen, &dwState, &dwProtocol, pbAtr, &dwAtrLen);
+ * @endcode
+ */
+LONG SCardStatus(SCARDHANDLE hCard, LPSTR mszReaderNames,
+ LPDWORD pcchReaderLen, LPDWORD pdwState,
+ LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
+{
+ DWORD dwReaderLen, atrOutputBufferSize;
+ LONG rv;
+ int i;
+ status_struct scStatusStruct;
+ sharedSegmentMsg msgStruct;
+ DWORD dwContextIndex, dwChannelIndex;
+ char *r;
+
+ PROFILE_START
+
+ /*
+ * Check for NULL parameters
+ */
+
+ if (pcchReaderLen == NULL || pcbAtrLen == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ /* length passed from caller */
+ dwReaderLen = *pcchReaderLen;
+ atrOutputBufferSize = *pcbAtrLen;
+
+ /* default output values */
+ if (pdwState)
+ *pdwState = 0;
+
+ if (pdwProtocol)
+ *pdwProtocol = 0;
+
+ *pcchReaderLen = 0;
+ *pcbAtrLen = 0;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ /* initialise the structure */
+ memset(&scStatusStruct, 0, sizeof(scStatusStruct));
+ scStatusStruct.hCard = hCard;
+
+ /* those sizes need to be initialised */
+ scStatusStruct.pcchReaderLen = sizeof(scStatusStruct.mszReaderNames);
+ scStatusStruct.pcbAtrLen = sizeof(scStatusStruct.pbAtr);
+ htonlStatusStruct(&scStatusStruct);
+
+ rv = WrapSHMWrite(SCARD_STATUS, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scStatusStruct),
+ SHMClientCommunicationTimeout(), (void *) &scStatusStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(status_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scStatusStruct, &msgStruct.data, sizeof(scStatusStruct));
+ ntohlStatusStruct(&scStatusStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ rv = scStatusStruct.rv;
+ if (rv != SCARD_S_SUCCESS && rv != SCARD_E_INSUFFICIENT_BUFFER)
+ {
+ /*
+ * An event must have occurred
+ */
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return rv;
+ }
+
+ /*
+ * Now continue with the client side SCardStatus
+ */
+
+ *pcchReaderLen = strlen(psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName) + 1;
+ *pcbAtrLen = SharedReaderState_CardAtrLength(readerStates[i]);
+
+ if (pdwState)
+ *pdwState = SharedReaderState_State(readerStates[i]);
+
+ if (pdwProtocol)
+ *pdwProtocol = SharedReaderState_Protocol(readerStates[i]);
+
+ /* return SCARD_E_INSUFFICIENT_BUFFER only if buffer pointer is non NULL */
+ if (mszReaderNames)
+ {
+ if (*pcchReaderLen > dwReaderLen)
+ rv = SCARD_E_INSUFFICIENT_BUFFER;
+
+ strncpy(mszReaderNames,
+ psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName,
+ dwReaderLen);
+ }
+
+ if (pbAtr)
+ {
+ if (*pcbAtrLen > atrOutputBufferSize)
+ rv = SCARD_E_INSUFFICIENT_BUFFER;
+
+ memcpy(pbAtr, SharedReaderState_CardAtr(readerStates[i]),
+ min(*pcbAtrLen, atrOutputBufferSize));
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * @brief This function receives a structure or list of structures containing
+ * reader names. It then blocks for a change in state to occur on any of the
+ * OR'd values contained in dwCurrentState for a maximum blocking time of
+ * dwTimeout or forever if INFINITE is used.
+ *
+ * The new event state will be contained in dwEventState. A status change might
+ * be a card insertion or removal event, a change in ATR, etc.
+ *
+ * This function will block for reader availability if cReaders is equal to
+ * zero and rgReaderStates is NULL.
+ *
+ * @code
+ * typedef struct {
+ * LPCSTR szReader; // Reader name
+ * LPVOID pvUserData; // User defined data
+ * DWORD dwCurrentState; // Current state of reader
+ * DWORD dwEventState; // Reader state after a state change
+ * DWORD cbAtr; // ATR Length, usually MAX_ATR_SIZE
+ * BYTE rgbAtr[MAX_ATR_SIZE]; // ATR Value
+ * } SCARD_READERSTATE;
+ * ...
+ * typedef SCARD_READERSTATE *PSCARD_READERSTATE, **LPSCARD_READERSTATE;
+ * ...
+ * @endcode
+ *
+ * Value of dwCurrentState and dwEventState:
+ * <ul>
+ * <li>\ref SCARD_STATE_UNAWARE The application is unaware of the current
+ * state, and would like to know. The use of this value results in an
+ * immediate return from state transition monitoring services. This is
+ * represented by all bits set to zero.
+ * <li>\ref SCARD_STATE_IGNORE This reader should be ignored
+ * <li>\ref SCARD_STATE_CHANGED There is a difference between the state believed
+ * by the application, and the state known by the resource manager.
+ * When this bit is set, the application may assume a significant state
+ * change has occurred on this reader.
+ * <li>\ref SCARD_STATE_UNKNOWN The given reader name is not recognized by the
+ * resource manager. If this bit is set, then \ref SCARD_STATE_CHANGED and
+ * \ref SCARD_STATE_IGNORE will also be set
+ * <li>\ref SCARD_STATE_UNAVAILABLE The actual state of this reader is not
+ * available. If this bit is set, then all the following bits are clear.
+ * <li>\ref SCARD_STATE_EMPTY There is no card in the reader. If this bit is set,
+ * all the following bits will be clear
+ * <li>\ref SCARD_STATE_PRESENT There is a card in the reader
+ * <li>\ref SCARD_STATE_ATRMATCH There is a card in the reader with an ATR
+ * matching one of the target cards. If this bit is set,
+ * \ref SCARD_STATE_PRESENT will also be set. This bit is only returned on
+ * the SCardLocateCards() function.
+ * <li>\ref SCARD_STATE_EXCLUSIVE The card in the reader is allocated for
+ * exclusive use by another application. If this bit is set,
+ * \ref SCARD_STATE_PRESENT will also be set.
+ * <li>\ref SCARD_STATE_INUSE The card in the reader is in use by one or more
+ * other applications, but may be connected to in shared mode. If this
+ * bit is set, \ref SCARD_STATE_PRESENT will also be set.
+ * <li>\ref SCARD_STATE_MUTE There is an unresponsive card in the reader.
+ * </ul>
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ * @param[in] dwTimeout Maximum waiting time (in miliseconds) for status
+ * change, zero (or INFINITE) for infinite.
+ * @param rgReaderStates [inout] Structures of readers with current states.
+ * @param[in] cReaders Number of structures.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_VALUE Invalid States, reader name, etc (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hContext handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader is unavailable (\ref SCARD_E_READER_UNAVAILABLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * SCARD_READERSTATE_A rgReaderStates[1];
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * ...
+ * rgReaderStates[0].szReader = "Reader X";
+ * rgReaderStates[0].dwCurrentState = SCARD_STATE_UNAWARE;
+ * ...
+ * rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
+ * printf("reader state: 0x%04X\n", rgReaderStates[0].dwEventState);
+ * @endcode
+ */
+LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout,
+ LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders)
+{
+ PSCARD_READERSTATE_A currReader;
+ PREADER_STATE rContext;
+ DWORD dwTime = 0;
+ DWORD dwState;
+ DWORD dwBreakFlag = 0;
+ int j;
+ LONG dwContextIndex;
+ int currentReaderCount = 0;
+
+ PROFILE_START
+
+ if (rgReaderStates == NULL && cReaders > 0)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this context has been opened
+ */
+
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ /*
+ * Application is waiting for a reader - return the first available
+ * reader
+ */
+
+ if (cReaders == 0)
+ {
+ while (1)
+ {
+ int i;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (SharedReaderState_ReaderID(readerStates[i]) != 0)
+ {
+ /*
+ * Reader was found
+ */
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return SCARD_S_SUCCESS;
+ }
+ }
+
+ if (dwTimeout == 0)
+ {
+ /*
+ * return immediately - no reader available
+ */
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ SYS_USleep(PCSCLITE_STATUS_WAIT);
+
+ if (dwTimeout != INFINITE)
+ {
+ dwTime += PCSCLITE_STATUS_WAIT;
+
+ if (dwTime >= (dwTimeout * 1000))
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return SCARD_E_TIMEOUT;
+ }
+ }
+ }
+ }
+ else
+ if (cReaders >= PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INVALID_VALUE;
+ }
+
+ /*
+ * Check the integrity of the reader states structures
+ */
+
+ for (j = 0; j < cReaders; j++)
+ {
+ currReader = &rgReaderStates[j];
+
+ if (currReader->szReader == NULL)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INVALID_VALUE;
+ }
+ }
+
+ /*
+ * End of search for readers
+ */
+
+ /*
+ * Clear the event state for all readers
+ */
+ for (j = 0; j < cReaders; j++)
+ {
+ currReader = &rgReaderStates[j];
+ currReader->dwEventState = 0;
+ }
+
+ /*
+ * Now is where we start our event checking loop
+ */
+
+ Log1(PCSC_LOG_DEBUG, "Event Loop Start");
+
+ psContextMap[dwContextIndex].contextBlockStatus = BLOCK_STATUS_BLOCKING;
+
+ /* Get the initial reader count on the system */
+ for (j=0; j < PCSCLITE_MAX_READERS_CONTEXTS; j++)
+ if (SharedReaderState_ReaderID(readerStates[j]) != 0)
+ currentReaderCount++;
+
+ j = 0;
+
+ do
+ {
+ int newReaderCount = 0;
+ char ReaderCountChanged = 0;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return SCARD_E_NO_SERVICE;
+ }
+
+ if (j == 0)
+ {
+ int i;
+
+ for (i=0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ if (SharedReaderState_ReaderID(readerStates[i]) != 0)
+ newReaderCount++;
+
+ if (newReaderCount != currentReaderCount)
+ {
+ Log1(PCSC_LOG_INFO, "Reader list changed");
+ ReaderCountChanged = 1;
+ currentReaderCount = newReaderCount;
+ }
+ }
+ currReader = &rgReaderStates[j];
+
+ /************ Look for IGNORED readers ****************************/
+
+ if (currReader->dwCurrentState & SCARD_STATE_IGNORE)
+ currReader->dwEventState = SCARD_STATE_IGNORE;
+ else
+ {
+ LPSTR lpcReaderName;
+ int i;
+
+ /************ Looks for correct readernames *********************/
+
+ lpcReaderName = (char *) currReader->szReader;
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], lpcReaderName))
+ break;
+ }
+
+ /*
+ * The requested reader name is not recognized
+ */
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ if (currReader->dwCurrentState & SCARD_STATE_UNKNOWN)
+ currReader->dwEventState = SCARD_STATE_UNKNOWN;
+ else
+ {
+ currReader->dwEventState =
+ SCARD_STATE_UNKNOWN | SCARD_STATE_CHANGED;
+ /*
+ * Spec says use SCARD_STATE_IGNORE but a removed USB
+ * reader with eventState fed into currentState will
+ * be ignored forever
+ */
+ dwBreakFlag = 1;
+ }
+ }
+ else
+ {
+
+ /*
+ * The reader has come back after being away
+ */
+ if (currReader->dwCurrentState & SCARD_STATE_UNKNOWN)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ currReader->dwEventState &= ~SCARD_STATE_UNKNOWN;
+ dwBreakFlag = 1;
+ }
+
+ /*****************************************************************/
+
+ /*
+ * Set the reader status structure
+ */
+ rContext = readerStates[i];
+
+ /*
+ * Now we check all the Reader States
+ */
+ dwState = SharedReaderState_State(rContext);
+
+ /*********** Check if the reader is in the correct state ********/
+ if (dwState & SCARD_UNKNOWN)
+ {
+ /*
+ * App thinks reader is in bad state and it is
+ */
+ if (currReader-> dwCurrentState & SCARD_STATE_UNAVAILABLE)
+ currReader->dwEventState = SCARD_STATE_UNAVAILABLE;
+ else
+ {
+ /*
+ * App thinks reader is in good state and it is
+ * not
+ */
+ currReader->dwEventState = SCARD_STATE_CHANGED |
+ SCARD_STATE_UNAVAILABLE;
+ dwBreakFlag = 1;
+ }
+ }
+ else
+ {
+ /*
+ * App thinks reader in bad state but it is not
+ */
+ if (currReader-> dwCurrentState & SCARD_STATE_UNAVAILABLE)
+ {
+ currReader->dwEventState &=
+ ~SCARD_STATE_UNAVAILABLE;
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+
+ /********** Check for card presence in the reader **************/
+
+ if (dwState & SCARD_PRESENT)
+ {
+ /* card present but not yet powered up */
+ if (0 == SharedReaderState_CardAtrLength(rContext))
+ /* Allow the status thread to convey information */
+ SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+
+ currReader->cbAtr = SharedReaderState_CardAtrLength(rContext);
+ memcpy(currReader->rgbAtr, SharedReaderState_CardAtr(rContext),
+ currReader->cbAtr);
+ }
+ else
+ currReader->cbAtr = 0;
+
+ /*
+ * Card is now absent
+ */
+ if (dwState & SCARD_ABSENT)
+ {
+ currReader->dwEventState |= SCARD_STATE_EMPTY;
+ currReader->dwEventState &= ~SCARD_STATE_PRESENT;
+ currReader->dwEventState &= ~SCARD_STATE_UNAWARE;
+ currReader->dwEventState &= ~SCARD_STATE_IGNORE;
+ currReader->dwEventState &= ~SCARD_STATE_UNKNOWN;
+ currReader->dwEventState &= ~SCARD_STATE_UNAVAILABLE;
+ currReader->dwEventState &= ~SCARD_STATE_ATRMATCH;
+ currReader->dwEventState &= ~SCARD_STATE_MUTE;
+ currReader->dwEventState &= ~SCARD_STATE_INUSE;
+
+ /*
+ * After present the rest are assumed
+ */
+ if (currReader->dwCurrentState & SCARD_STATE_PRESENT
+ || currReader->dwCurrentState & SCARD_STATE_ATRMATCH
+ || currReader->dwCurrentState & SCARD_STATE_EXCLUSIVE
+ || currReader->dwCurrentState & SCARD_STATE_INUSE)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+
+ /*
+ * Card is now present
+ */
+ } else if (dwState & SCARD_PRESENT)
+ {
+ currReader->dwEventState |= SCARD_STATE_PRESENT;
+ currReader->dwEventState &= ~SCARD_STATE_EMPTY;
+ currReader->dwEventState &= ~SCARD_STATE_UNAWARE;
+ currReader->dwEventState &= ~SCARD_STATE_IGNORE;
+ currReader->dwEventState &= ~SCARD_STATE_UNKNOWN;
+ currReader->dwEventState &= ~SCARD_STATE_UNAVAILABLE;
+ currReader->dwEventState &= ~SCARD_STATE_MUTE;
+
+ if (currReader->dwCurrentState & SCARD_STATE_EMPTY)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+
+ if (dwState & SCARD_SWALLOWED)
+ {
+ if (currReader->dwCurrentState & SCARD_STATE_MUTE)
+ currReader->dwEventState |= SCARD_STATE_MUTE;
+ else
+ {
+ currReader->dwEventState |= SCARD_STATE_MUTE;
+ if (currReader->dwCurrentState
+ != SCARD_STATE_UNAWARE)
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+ else
+ {
+ /*
+ * App thinks card is mute but it is not
+ */
+ if (currReader->dwCurrentState & SCARD_STATE_MUTE)
+ {
+ currReader->dwEventState |=
+ SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+ }
+
+ /*
+ * Now figure out sharing modes
+ */
+ DWORD sharing = SharedReaderState_Sharing(rContext);
+ if (sharing == -1)
+ {
+ currReader->dwEventState |= SCARD_STATE_EXCLUSIVE;
+ currReader->dwEventState &= ~SCARD_STATE_INUSE;
+ if (currReader->dwCurrentState & SCARD_STATE_INUSE)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+ else if (sharing >= 1)
+ {
+ /*
+ * A card must be inserted for it to be INUSE
+ */
+ if (dwState & SCARD_PRESENT)
+ {
+ currReader->dwEventState |= SCARD_STATE_INUSE;
+ currReader->dwEventState &= ~SCARD_STATE_EXCLUSIVE;
+ if (currReader-> dwCurrentState & SCARD_STATE_EXCLUSIVE)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+ }
+ else if (sharing == 0)
+ {
+ currReader->dwEventState &= ~SCARD_STATE_INUSE;
+ currReader->dwEventState &= ~SCARD_STATE_EXCLUSIVE;
+
+ if (currReader->dwCurrentState & SCARD_STATE_INUSE)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ else if (currReader-> dwCurrentState
+ & SCARD_STATE_EXCLUSIVE)
+ {
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+ }
+
+ if (currReader->dwCurrentState == SCARD_STATE_UNAWARE)
+ {
+ /*
+ * Break out of the while .. loop and return status
+ * once all the status's for all readers is met
+ */
+ currReader->dwEventState |= SCARD_STATE_CHANGED;
+ dwBreakFlag = 1;
+ }
+
+ } /* End of SCARD_STATE_UNKNOWN */
+
+ } /* End of SCARD_STATE_IGNORE */
+
+ /*
+ * Counter and resetter
+ */
+ j = j + 1;
+ if (j == cReaders)
+ {
+ if (!dwBreakFlag)
+ {
+ /* break if the reader count changed,
+ * so that the calling application can update
+ * the reader list
+ */
+ if (ReaderCountChanged)
+ break;
+ }
+ j = 0;
+ }
+
+ /*
+ * Declare all the break conditions
+ */
+
+ if (psContextMap[dwContextIndex].contextBlockStatus
+ == BLOCK_STATUS_RESUME)
+ break;
+
+ /*
+ * Break if UNAWARE is set and all readers have been checked
+ */
+ if ((dwBreakFlag == 1) && (j == 0))
+ break;
+
+ /*
+ * Timeout has occurred and all readers checked
+ */
+ if ((dwTimeout == 0) && (j == 0))
+ break;
+
+ if (dwTimeout != INFINITE && dwTimeout != 0)
+ {
+ /*
+ * If time is greater than timeout and all readers have been
+ * checked
+ */
+ if ((dwTime >= (dwTimeout * 1000)) && (j == 0))
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_TIMEOUT;
+ }
+ }
+
+ /*
+ * Only sleep once for each cycle of reader checks.
+ */
+ if (j == 0)
+ {
+ SYS_USleep(PCSCLITE_STATUS_WAIT);
+ dwTime += PCSCLITE_STATUS_WAIT;
+ }
+ }
+ while (1);
+
+ Log1(PCSC_LOG_DEBUG, "Event Loop End");
+
+ if (psContextMap[dwContextIndex].contextBlockStatus ==
+ BLOCK_STATUS_RESUME)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_CANCELLED;
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return SCARD_S_SUCCESS;
+}
+
+#undef SCardControl
+
+LONG SCardControl(SCARDHANDLE hCard, const void *pbSendBuffer,
+ DWORD cbSendLength, void *pbRecvBuffer, LPDWORD pcbRecvLength)
+{
+
+ SCARD_IO_REQUEST pioSendPci, pioRecvPci;
+
+ pioSendPci.dwProtocol = SCARD_PROTOCOL_RAW;
+ pioRecvPci.dwProtocol = SCARD_PROTOCOL_RAW;
+
+ return SCardTransmit(hCard, &pioSendPci, pbSendBuffer, cbSendLength,
+ &pioRecvPci, pbRecvBuffer, pcbRecvLength);
+}
+
+/**
+ * @brief This function sends a command directly to the IFD Handler to be
+ * processed by the reader.
+ *
+ * This is useful for creating client side reader drivers for functions like
+ * PIN pads, biometrics, or other extensions to the normal smart card reader
+ * that are not normally handled by PC/SC.
+ *
+ * @note the API of this function changed. In pcsc-lite 1.2.0 and before the
+ * API was not Windows(R) PC/SC compatible. This has been corrected.
+ *
+ * @param[in] hCard Connection made from SCardConnect.
+ * @param[in] dwControlCode Control code for the operation.\n
+ * <a href="http://pcsclite.alioth.debian.org/pcsc-lite/node26.html#Some_SCardControl_commands">
+ * Click here</a> for a list of supported commands by some drivers.
+ * @param[in] pbSendBuffer Command to send to the reader.
+ * @param[in] cbSendLength Length of the command.
+ * @param[out] pbRecvBuffer Response from the reader.
+ * @param[in] cbRecvLength Length of the response buffer.
+ * @param[out] lpBytesReturned Length of the response.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NOT_TRANSACTED Data exchange not successful (\ref SCARD_E_NOT_TRANSACTED)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INVALID_VALUE Invalid value was presented (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed(\ref SCARD_E_READER_UNAVAILABLE)
+ * @retval SCARD_W_RESET_CARD The card has been reset by another application (\ref SCARD_W_RESET_CARD)
+ * @retval SCARD_W_REMOVED_CARD The card has been removed from the reader(\ref SCARD_W_REMOVED_CARD)
+ *
+ * @test
+ * @code
+ * LONG rv;
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol, dwSendLength, dwRecvLength;
+ * BYTE pbRecvBuffer[10];
+ * BYTE pbSendBuffer[] = { 0x06, 0x00, 0x0A, 0x01, 0x01, 0x10 0x00 };
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol);
+ * dwSendLength = sizeof(pbSendBuffer);
+ * dwRecvLength = sizeof(pbRecvBuffer);
+ * rv = SCardControl(hCard, 0x42000001, pbSendBuffer, dwSendLength, pbRecvBuffer, sizeof(pbRecvBuffer), &dwRecvLength);
+ * @endcode
+ */
+int32_t SCardControl132(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer,
+ DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength,
+ LPDWORD lpBytesReturned)
+{
+ // Real implementation to be provided as part of:
+ // <rdar://problem/4711576> Support the new SCardControl function
+ //
+
+ LONG rv;
+ control_struct scControlStruct;
+ sharedSegmentMsg msgStruct;
+ int i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ /* 0 bytes received by default */
+ if (NULL != lpBytesReturned)
+ *lpBytesReturned = 0;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ if ((cbSendLength > MAX_BUFFER_SIZE_EXTENDED)
+ || (cbRecvLength > MAX_BUFFER_SIZE_EXTENDED))
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ if ((cbSendLength > MAX_BUFFER_SIZE) || (cbRecvLength > MAX_BUFFER_SIZE))
+ {
+ /* extended control */
+ unsigned char buffer[sizeof(sharedSegmentMsg) + MAX_BUFFER_SIZE_EXTENDED];
+ control_struct_extended *scControlStructExtended = (control_struct_extended *)buffer;
+ sharedSegmentMsg *pmsgStruct = (psharedSegmentMsg)buffer;
+
+ scControlStructExtended->hCard = hCard;
+ scControlStructExtended->dwControlCode = dwControlCode;
+ scControlStructExtended->cbSendLength = cbSendLength;
+ scControlStructExtended->cbRecvLength = cbRecvLength;
+ scControlStructExtended->size = sizeof(*scControlStructExtended) + cbSendLength;
+ memcpy(scControlStructExtended->data, pbSendBuffer, cbSendLength);
+
+ size_t csesize = scControlStructExtended->size; // remember it from before byte swap
+ htonlControlStructExtended(scControlStructExtended);
+ rv = WrapSHMWrite(SCARD_CONTROL_EXTENDED,
+ psContextMap[dwContextIndex].dwClientID,
+ csesize,
+ SHMClientCommunicationTimeout(), buffer);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ /* read the first block */
+ rv = SHMClientReadMessage(pmsgStruct, psContextMap[dwContextIndex].dwClientID, 0, SHMClientCommunicationTimeout());
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ /* we receive a sharedSegmentMsg and not a control_struct_extended */
+ scControlStructExtended = (control_struct_extended *)&(pmsgStruct -> data);
+ ntohlControlStructExtended(scControlStructExtended);
+
+ /* a second block is present */
+ if (scControlStructExtended->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ rv = SHMMessageReceive(buffer + sizeof(sharedSegmentMsg),
+ scControlStructExtended->size-PCSCLITE_MAX_MESSAGE_SIZE,
+ psContextMap[dwContextIndex].dwClientID,
+ SHMClientCommunicationTimeout());
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+ }
+
+ if (scControlStructExtended -> rv == SCARD_S_SUCCESS)
+ {
+ /*
+ * Copy and zero it so any secret information is not leaked
+ */
+ memcpy(pbRecvBuffer, scControlStructExtended -> data,
+ scControlStructExtended -> pdwBytesReturned);
+ memset(scControlStructExtended -> data, 0x00,
+ scControlStructExtended -> pdwBytesReturned);
+ }
+
+ if (NULL != lpBytesReturned)
+ *lpBytesReturned = scControlStructExtended -> pdwBytesReturned;
+
+ rv = scControlStructExtended -> rv;
+ }
+ else
+ {
+ scControlStruct.hCard = hCard;
+ scControlStruct.dwControlCode = dwControlCode;
+ scControlStruct.cbSendLength = cbSendLength;
+ scControlStruct.cbRecvLength = cbRecvLength;
+ memcpy(scControlStruct.pbSendBuffer, pbSendBuffer, cbSendLength);
+ htonlControlStruct(&scControlStruct);
+
+ rv = WrapSHMWrite(SCARD_CONTROL, psContextMap[dwContextIndex].dwClientID,
+ sizeof(scControlStruct), SHMClientCommunicationTimeout(), &scControlStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(control_struct), SHMClientCommunicationTimeout());
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ memcpy(&scControlStruct, &msgStruct.data, sizeof(scControlStruct));
+ ntohlControlStruct(&scControlStruct);
+
+ if (NULL != lpBytesReturned)
+ *lpBytesReturned = scControlStruct.dwBytesReturned;
+
+ if (scControlStruct.rv == SCARD_S_SUCCESS)
+ {
+ /*
+ * Copy and zero it so any secret information is not leaked
+ */
+ memcpy(pbRecvBuffer, scControlStruct.pbRecvBuffer,
+ scControlStruct.cbRecvLength);
+ memset(scControlStruct.pbRecvBuffer, 0x00,
+ sizeof(scControlStruct.pbRecvBuffer));
+ }
+
+ rv = scControlStruct.rv;
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * This function get an attribute from the IFD Handler. The list of possible
+ * attributes is available in the file \c pcsclite.h.
+ *
+ * @param[in] hCard Connection made from SCardConnect().
+ * @param[in] dwAttrId Identifier for the attribute to get.
+ * <ul>
+ * <li>\ref SCARD_ATTR_ASYNC_PROTOCOL_TYPES
+ * <li>\ref SCARD_ATTR_ATR_STRING
+ * <li>\ref SCARD_ATTR_CHANNEL_ID
+ * <li>\ref SCARD_ATTR_CHARACTERISTICS
+ * <li>\ref SCARD_ATTR_CURRENT_BWT
+ * <li>\ref SCARD_ATTR_CURRENT_CLK
+ * <li>\ref SCARD_ATTR_CURRENT_CWT
+ * <li>\ref SCARD_ATTR_CURRENT_D
+ * <li>\ref SCARD_ATTR_CURRENT_EBC_ENCODING
+ * <li>\ref SCARD_ATTR_CURRENT_F
+ * <li>\ref SCARD_ATTR_CURRENT_IFSC
+ * <li>\ref SCARD_ATTR_CURRENT_IFSD
+ * <li>\ref SCARD_ATTR_CURRENT_IO_STATE
+ * <li>\ref SCARD_ATTR_CURRENT_N
+ * <li>\ref SCARD_ATTR_CURRENT_PROTOCOL_TYPE
+ * <li>\ref SCARD_ATTR_CURRENT_W
+ * <li>\ref SCARD_ATTR_DEFAULT_CLK
+ * <li>\ref SCARD_ATTR_DEFAULT_DATA_RATE
+ * <li>\ref SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
+ * <li>\ref SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
+ * <li>\ref SCARD_ATTR_DEVICE_IN_USE
+ * <li>\ref SCARD_ATTR_DEVICE_SYSTEM_NAME_A
+ * <li>\ref SCARD_ATTR_DEVICE_SYSTEM_NAME_W
+ * <li>\ref SCARD_ATTR_DEVICE_UNIT
+ * <li>\ref SCARD_ATTR_ESC_AUTHREQUEST
+ * <li>\ref SCARD_ATTR_ESC_CANCEL
+ * <li>\ref SCARD_ATTR_ESC_RESET
+ * <li>\ref SCARD_ATTR_EXTENDED_BWT
+ * <li>\ref SCARD_ATTR_ICC_INTERFACE_STATUS
+ * <li>\ref SCARD_ATTR_ICC_PRESENCE
+ * <li>\ref SCARD_ATTR_ICC_TYPE_PER_ATR
+ * <li>\ref SCARD_ATTR_MAX_CLK
+ * <li>\ref SCARD_ATTR_MAX_DATA_RATE
+ * <li>\ref SCARD_ATTR_MAX_IFSD
+ * <li>\ref SCARD_ATTR_MAXINPUT
+ * <li>\ref SCARD_ATTR_POWER_MGMT_SUPPORT
+ * <li>\ref SCARD_ATTR_SUPRESS_T1_IFS_REQUEST
+ * <li>\ref SCARD_ATTR_SYNC_PROTOCOL_TYPES
+ * <li>\ref SCARD_ATTR_USER_AUTH_INPUT_DEVICE
+ * <li>\ref SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE
+ * <li>\ref SCARD_ATTR_VENDOR_IFD_SERIAL_NO
+ * <li>\ref SCARD_ATTR_VENDOR_IFD_TYPE
+ * <li>\ref SCARD_ATTR_VENDOR_IFD_VERSION
+ * <li>\ref SCARD_ATTR_VENDOR_NAME
+ * </ul>
+ *
+ * Not all the dwAttrId values listed above may be implemented in the IFD
+ * Handler you are using. And some dwAttrId values not listed here may be
+ * implemented.
+ *
+ * @param[out] pbAttr Pointer to a buffer that receives the attribute.
+ * @param pcbAttrLen [inout] Length of the \p pbAttr buffer in bytes.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NOT_TRANSACTED Data exchange not successful (\ref SCARD_E_NOT_TRANSACTED)
+ * @retval SCARD_E_INSUFFICIENT_BUFFER Reader buffer not large enough (\ref SCARD_E_INSUFFICIENT_BUFFER)
+ *
+ * @test
+ * @code
+ * LONG rv;
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * unsigned char pbAtr[MAX_ATR_SIZE];
+ * DWORD dwAtrLen;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED,
+ * SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol);
+ * rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, pbAtr, &dwAtrLen);
+ * @endcode
+ */
+
+int32_t SCardGetAttrib(SCARDHANDLE hCard, uint32_t dwAttrId, uint8_t * pbAttr,
+ uint32_t * pcbAttrLen)
+{
+ PROFILE_START
+
+ if (NULL == pcbAttrLen)
+ return SCARD_E_INVALID_PARAMETER;
+
+ /* if only get the length */
+ if (NULL == pbAttr)
+ /* this variable may not be set by the caller. use a reasonable size */
+ *pcbAttrLen = MAX_BUFFER_SIZE;
+
+ PROFILE_END
+
+ return SCardGetSetAttrib(hCard, SCARD_GET_ATTRIB, dwAttrId, pbAttr,
+ pcbAttrLen);
+}
+
+/**
+ * @brief This function set an attribute of the IFD Handler.
+ *
+ * The list of attributes you can set is dependent on the IFD Handler you are
+ * using.
+ *
+ * @param[in] hCard Connection made from SCardConnect().
+ * @param[in] dwAttrId Identifier for the attribute to set.
+ * @param[in] pbAttr Pointer to a buffer that receives the attribute.
+ * @param[in] cbAttrLen Length of the \p pbAttr buffer in bytes.
+ *
+ * @return Error code
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NOT_TRANSACTED Data exchange not successful (\ref SCARD_E_NOT_TRANSACTED)
+ *
+ * @test
+ * @code
+ * LONG rv;
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol;
+ * unsigned char pbAtr[MAX_ATR_SIZE];
+ * DWORD dwAtrLen;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED,
+ * SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol);
+ * rv = SCardSetAttrib(hCard, 0x42000001, "\x12\x34\x56", 3);
+ * @endcode
+ */
+
+int32_t SCardSetAttrib(SCARDHANDLE hCard, uint32_t dwAttrId, const uint8_t *pbAttr,
+ uint32_t cbAttrLen)
+{
+ PROFILE_START
+
+ if (NULL == pbAttr || 0 == cbAttrLen)
+ return SCARD_E_INVALID_PARAMETER;
+
+ PROFILE_END
+
+ return SCardGetSetAttrib(hCard, SCARD_SET_ATTRIB, dwAttrId, (LPBYTE)pbAttr,
+ &cbAttrLen);
+}
+
+static LONG SCardGetSetAttrib(SCARDHANDLE hCard, int command, DWORD dwAttrId,
+ LPBYTE pbAttr, LPDWORD pcbAttrLen)
+{
+ PROFILE_START
+
+ LONG rv;
+ getset_struct scGetSetStruct;
+ sharedSegmentMsg msgStruct;
+ int i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ if (*pcbAttrLen > MAX_BUFFER_SIZE)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ scGetSetStruct.hCard = hCard;
+ scGetSetStruct.dwAttrId = dwAttrId;
+ scGetSetStruct.cbAttrLen = *pcbAttrLen;
+ scGetSetStruct.rv = SCARD_E_NO_SERVICE;
+ if (SCARD_SET_ATTRIB == command)
+ memcpy(scGetSetStruct.pbAttr, pbAttr, *pcbAttrLen);
+
+ ntohlGetSetStruct(&scGetSetStruct);
+ rv = WrapSHMWrite(command,
+ psContextMap[dwContextIndex].dwClientID, sizeof(scGetSetStruct),
+ SHMClientCommunicationTimeout(), &scGetSetStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(getset_struct), SHMClientCommunicationTimeout());
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ memcpy(&scGetSetStruct, &msgStruct.data, sizeof(scGetSetStruct));
+ ntohlGetSetStruct(&scGetSetStruct);
+
+ if ((SCARD_S_SUCCESS == scGetSetStruct.rv) && (SCARD_GET_ATTRIB == command))
+ {
+ /*
+ * Copy and zero it so any secret information is not leaked
+ */
+ if (*pcbAttrLen < scGetSetStruct.cbAttrLen)
+ {
+ scGetSetStruct.cbAttrLen = *pcbAttrLen;
+ scGetSetStruct.rv = SCARD_E_INSUFFICIENT_BUFFER;
+ }
+ else
+ *pcbAttrLen = scGetSetStruct.cbAttrLen;
+
+ if (pbAttr)
+ memcpy(pbAttr, scGetSetStruct.pbAttr, scGetSetStruct.cbAttrLen);
+
+ memset(scGetSetStruct.pbAttr, 0x00, sizeof(scGetSetStruct.pbAttr));
+ }
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return scGetSetStruct.rv;
+}
+
+/**
+ * @brief This function sends an APDU to the smart card contained in the reader
+ * connected to by SCardConnect().
+ *
+ * The card responds from the APDU and stores this response in pbRecvBuffer
+ * and it's length in SpcbRecvLength.
+ * SSendPci and SRecvPci are structures containing the following:
+ * @code
+ * typedef struct {
+ * DWORD dwProtocol; // SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1
+ * DWORD cbPciLength; // Length of this structure - not used
+ * } SCARD_IO_REQUEST;
+ * @endcode
+ *
+ * @param[in] hCard Connection made from SCardConnect().
+ * @param pioSendPci [inout] Structure of protocol information.
+ * <ul>
+ * <li>\ref SCARD_PCI_T0 - Pre-defined T=0 PCI structure.
+ * <li>\ref SCARD_PCI_T1 - Pre-defined T=1 PCI structure.
+ * </ul>
+ * @param[in] pbSendBuffer APDU to send to the card.
+ * @param[in] cbSendLength Length of the APDU.
+ * @param pioRecvPci [inout] Structure of protocol information.
+ * @param[out] pbRecvBuffer Response from the card.
+ * @param pcbRecvLength [inout] Length of the response.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid hCard handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_NOT_TRANSACTED APDU exchange not successful (\ref SCARD_E_NOT_TRANSACTED)
+ * @retval SCARD_E_PROTO_MISMATCH Connect protocol is different than desired (\ref SCARD_E_PROTO_MISMATCH)
+ * @retval SCARD_E_INVALID_VALUE Invalid Protocol, reader name, etc (\ref SCARD_E_INVALID_VALUE)
+ * @retval SCARD_E_READER_UNAVAILABLE The reader has been removed (\ref SCARD_E_READER_UNAVAILABLE)
+ * @retval SCARD_W_RESET_CARD The card has been reset by another application (\ref SCARD_W_RESET_CARD)
+ * @retval SCARD_W_REMOVED_CARD The card has been removed from the reader (\ref SCARD_W_REMOVED_CARD)
+ *
+ * @test
+ * @code
+ * LONG rv;
+ * SCARDCONTEXT hContext;
+ * SCARDHANDLE hCard;
+ * DWORD dwActiveProtocol, dwSendLength, dwRecvLength;
+ * SCARD_IO_REQUEST pioRecvPci;
+ * BYTE pbRecvBuffer[10];
+ * BYTE pbSendBuffer[] = { 0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
+ * dwSendLength = sizeof(pbSendBuffer);
+ * dwRecvLength = sizeof(pbRecvBuffer);
+ * rv = SCardTransmit(hCard, SCARD_PCI_T0, pbSendBuffer, dwSendLength, &pioRecvPci, pbRecvBuffer, &dwRecvLength);
+ * @endcode
+ */
+#include <syslog.h>
+LONG SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,
+ LPCBYTE pbSendBuffer, DWORD cbSendLength,
+ LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,
+ LPDWORD pcbRecvLength)
+{
+ LONG rv;
+ int i;
+ DWORD dwContextIndex, dwChannelIndex;
+
+ PROFILE_START
+
+ if (pbSendBuffer == NULL || pbRecvBuffer == NULL ||
+ pcbRecvLength == NULL || pioSendPci == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this handle has been opened
+ */
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
+
+ if (rv == -1)
+ {
+ *pcbRecvLength = 0;
+ return SCARD_E_INVALID_HANDLE;
+ }
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;
+
+ /* by default r == NULL */
+ if (SharedReaderState_ReaderNameIsEqual(readerStates[i], r))
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_READERS_CONTEXTS)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_READER_UNAVAILABLE;
+ }
+
+ if ((cbSendLength > MAX_BUFFER_SIZE_EXTENDED)
+ || (*pcbRecvLength > MAX_BUFFER_SIZE_EXTENDED))
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ if ((cbSendLength > MAX_BUFFER_SIZE) || (*pcbRecvLength > MAX_BUFFER_SIZE))
+ {
+ /* extended APDU */
+ unsigned char buffer[sizeof(sharedSegmentMsg) + MAX_BUFFER_SIZE_EXTENDED];
+ const sharedSegmentMsg *pmsgStruct = (psharedSegmentMsg)buffer;
+ transmit_struct_extended *scTransmitStructExtended = (transmit_struct_extended *)buffer;
+
+ scTransmitStructExtended->hCard = hCard;
+ scTransmitStructExtended->cbSendLength = cbSendLength;
+ scTransmitStructExtended->pcbRecvLength = *pcbRecvLength;
+ scTransmitStructExtended->size = sizeof(*scTransmitStructExtended) + cbSendLength;
+ scTransmitStructExtended->pioSendPciProtocol = pioSendPci->dwProtocol;
+ scTransmitStructExtended->pioSendPciLength = pioSendPci->cbPciLength;
+ memcpy(scTransmitStructExtended->data, pbSendBuffer, cbSendLength);
+ secdebug("pcscd", "Extended APDU: initial request: hCard: 0x%08X, cbSendLength: %d",
+ hCard, cbSendLength);
+ secdebug("pcscd", " pcbRecvLength: %d", *pcbRecvLength);
+
+ if (pioRecvPci)
+ {
+ scTransmitStructExtended->pioRecvPciProtocol = pioRecvPci->dwProtocol;
+ scTransmitStructExtended->pioRecvPciLength = pioRecvPci->cbPciLength;
+ }
+ else
+ scTransmitStructExtended->pioRecvPciProtocol = SCARD_PROTOCOL_ANY;
+
+ size_t tsesize = scTransmitStructExtended->size; // remember it before we byte swap
+ LogXxd(PCSC_LOG_INFO, "Extended APDU: sending: ", pbSendBuffer, cbSendLength);
+ htonlTransmitStructExtended(scTransmitStructExtended);
+ rv = WrapSHMWrite(SCARD_TRANSMIT_EXTENDED,
+ psContextMap[dwContextIndex].dwClientID,
+ tsesize,
+ SHMClientCommunicationTimeout(), buffer);
+ secdebug("pcscd", "Extended APDU: WrapSHMWrite result: %d [0x%08X]", rv, rv);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage((psharedSegmentMsg)buffer, psContextMap[dwContextIndex].dwClientID, 0, SHMClientCommunicationTimeout());
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ /* we receive a sharedSegmentMsg and not a transmit_struct_extended */
+ scTransmitStructExtended = (transmit_struct_extended *)pmsgStruct->data;
+ ntohlTransmitStructExtended(scTransmitStructExtended);
+ secdebug("pcscd", "Extended APDU: reply received: hCard: 0x%08X, cbSendLength: %d",
+ hCard, cbSendLength);
+ secdebug("pcscd", " reply received: pcbRecvLength: %d, size: %llu",
+ scTransmitStructExtended->pcbRecvLength, scTransmitStructExtended->size);
+ secdebug("pcscd", " reply received: rv %d [0x%08X]",
+ scTransmitStructExtended -> rv, scTransmitStructExtended -> rv);
+ LogXxd(PCSC_LOG_INFO, "Extended APDU: received: ", scTransmitStructExtended->data, scTransmitStructExtended->pcbRecvLength);
+
+ /* a second block is present */
+ if (scTransmitStructExtended->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ rv = SHMMessageReceive(buffer + sizeof(sharedSegmentMsg),
+ scTransmitStructExtended->size-PCSCLITE_MAX_MESSAGE_SIZE,
+ psContextMap[dwContextIndex].dwClientID,
+ SHMClientCommunicationTimeout());
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+ // we don't fix up byte order here since this is in the data portion
+ }
+
+ if (scTransmitStructExtended -> rv == SCARD_S_SUCCESS)
+ {
+ /*
+ * Copy and zero it so any secret information is not leaked
+ */
+ memcpy(pbRecvBuffer, scTransmitStructExtended -> data,
+ scTransmitStructExtended -> pcbRecvLength);
+ memset(scTransmitStructExtended -> data, 0x00,
+ scTransmitStructExtended -> pcbRecvLength);
+
+ if (pioRecvPci)
+ {
+ pioRecvPci->dwProtocol = scTransmitStructExtended->pioRecvPciProtocol;
+ pioRecvPci->cbPciLength = scTransmitStructExtended->pioRecvPciLength;
+ }
+ }
+
+ *pcbRecvLength = scTransmitStructExtended -> pcbRecvLength;
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ rv = scTransmitStructExtended -> rv;
+ }
+ else
+ {
+ /* short APDU */
+ transmit_struct scTransmitStruct;
+ sharedSegmentMsg msgStruct;
+
+ scTransmitStruct.hCard = hCard;
+ scTransmitStruct.cbSendLength = cbSendLength;
+ scTransmitStruct.pcbRecvLength = *pcbRecvLength;
+ scTransmitStruct.pioSendPciProtocol = pioSendPci->dwProtocol;
+ scTransmitStruct.pioSendPciLength = pioSendPci->cbPciLength;
+ memcpy(scTransmitStruct.pbSendBuffer, pbSendBuffer, cbSendLength);
+
+ if (pioRecvPci)
+ {
+ scTransmitStruct.pioRecvPciProtocol = pioRecvPci->dwProtocol;
+ scTransmitStruct.pioRecvPciLength = pioRecvPci->cbPciLength;
+ }
+ else
+ scTransmitStruct.pioRecvPciProtocol = SCARD_PROTOCOL_ANY;
+
+ htonlTransmitStruct(&scTransmitStruct);
+ rv = WrapSHMWrite(SCARD_TRANSMIT,
+ psContextMap[dwContextIndex].dwClientID, sizeof(scTransmitStruct),
+ SHMClientCommunicationTimeout(), (void *) &scTransmitStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ /*
+ * Read a message from the server
+ */
+ rv = SHMClientReadMessage(&msgStruct, psContextMap[dwContextIndex].dwClientID, sizeof(transmit_struct), SHMClientCommunicationTimeout());
+
+ memcpy(&scTransmitStruct, &msgStruct.data, sizeof(scTransmitStruct));
+ ntohlTransmitStruct(&scTransmitStruct);
+
+ if (rv == -1)
+ {
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_F_COMM_ERROR;
+ }
+
+ /*
+ * Zero it and free it so any secret information cannot be leaked
+ */
+ memset(scTransmitStruct.pbSendBuffer, 0x00, cbSendLength);
+
+ if (scTransmitStruct.rv == SCARD_S_SUCCESS)
+ {
+ /*
+ * Copy and zero it so any secret information is not leaked
+ */
+ memcpy(pbRecvBuffer, scTransmitStruct.pbRecvBuffer,
+ scTransmitStruct.pcbRecvLength);
+ memset(scTransmitStruct.pbRecvBuffer, 0x00,
+ scTransmitStruct.pcbRecvLength);
+
+ if (pioRecvPci)
+ {
+ pioRecvPci->dwProtocol = scTransmitStruct.pioRecvPciProtocol;
+ pioRecvPci->cbPciLength = scTransmitStruct.pioRecvPciLength;
+ }
+ }
+
+ *pcbRecvLength = scTransmitStruct.pcbRecvLength;
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ rv = scTransmitStruct.rv;
+ }
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * This function returns a list of currently available readers on the system.
+ * \p mszReaders is a pointer to a character string that is allocated by the application.
+ * If the application sends mszGroups and mszReaders as NULL then this function will
+ * return the size of the buffer needed to allocate in pcchReaders.
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ * @param[in] mszGroups List of groups to list readers (not used).
+ * @param[out] mszReaders Multi-string with list of readers.
+ * @param pcchReaders [inout] Size of multi-string buffer including NULL's.
+ *
+ * @return Connection status.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid Scope Handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INSUFFICIENT_BUFFER Reader buffer not large enough (\ref SCARD_E_INSUFFICIENT_BUFFER)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * LPSTR mszReaders;
+ * DWORD dwReaders;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardListReaders(hContext, NULL, NULL, &dwReaders);
+ * mszReaders = malloc(sizeof(char)*dwReaders);
+ * rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders);
+ * @endcode
+ */
+LONG SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups,
+ LPSTR mszReaders, LPDWORD pcchReaders)
+{
+ DWORD dwReadersLen;
+ int i, lastChrPtr;
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ /*
+ * Check for NULL parameters
+ */
+ if (pcchReaders == NULL)
+ return SCARD_E_INVALID_PARAMETER;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this context has been opened
+ */
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ dwReadersLen = 0;
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ if (SharedReaderState_ReaderID(readerStates[i]) != 0)
+ dwReadersLen += strlen(SharedReaderState_ReaderName(readerStates[i])) + 1;
+
+ /* for the last NULL byte */
+ dwReadersLen += 1;
+
+ if ((mszReaders == NULL) /* text array not allocated */
+ || (*pcchReaders == 0)) /* size == 0 */
+ {
+ *pcchReaders = dwReadersLen;
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_S_SUCCESS;
+ }
+
+ if (*pcchReaders < dwReadersLen)
+ {
+ *pcchReaders = dwReadersLen;
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ lastChrPtr = 0;
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (SharedReaderState_ReaderID(readerStates[i]) != 0)
+ {
+ /*
+ * Build the multi-string
+ */
+ strcpy(&mszReaders[lastChrPtr], SharedReaderState_ReaderName(readerStates[i]));
+ lastChrPtr += strlen(SharedReaderState_ReaderName(readerStates[i]))+1;
+ }
+ }
+ mszReaders[lastChrPtr] = '\0'; /* Add the last null */
+
+ *pcchReaders = dwReadersLen;
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return SCARD_S_SUCCESS;
+}
+
+/**
+ * @brief This function returns a list of currently available reader groups on the system.
+ * \p mszGroups is a pointer to a character string that is allocated by the
+ * application. If the application sends mszGroups as NULL then this function
+ * will return the size of the buffer needed to allocate in pcchGroups.
+ *
+ * The group names is a multi-string and separated by a nul character ('\\0') and ended by
+ * a double nul character. "SCard$DefaultReaders\\0Group 2\\0\\0".
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ * @param[out] mszGroups List of groups to list readers.
+ * @param pcchGroups [inout] Size of multi-string buffer including NULL's.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid Scope Handle (\ref SCARD_E_INVALID_HANDLE)
+ * @retval SCARD_E_INSUFFICIENT_BUFFER Reader buffer not large enough (\ref SCARD_E_INSUFFICIENT_BUFFER)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * LPSTR mszGroups;
+ * DWORD dwGroups;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardListReaderGroups(hContext, NULL, &dwGroups);
+ * mszGroups = malloc(sizeof(char)*dwGroups);
+ * rv = SCardListReaderGroups(hContext, mszGroups, &dwGroups);
+ * @endcode
+ */
+LONG SCardListReaderGroups(SCARDCONTEXT hContext, LPSTR mszGroups,
+ LPDWORD pcchGroups)
+{
+ LONG rv = SCARD_S_SUCCESS;
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ const char ReaderGroup[] = "SCard$DefaultReaders";
+ const int dwGroups = strlen(ReaderGroup) + 2;
+
+ if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+ return SCARD_E_NO_SERVICE;
+
+ /*
+ * Make sure this context has been opened
+ */
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ SYS_MutexLock(psContextMap[dwContextIndex].mMutex);
+
+ if (mszGroups)
+ {
+
+ if (*pcchGroups < dwGroups)
+ rv = SCARD_E_INSUFFICIENT_BUFFER;
+ else
+ {
+ memset(mszGroups, 0, dwGroups);
+ memcpy(mszGroups, ReaderGroup, strlen(ReaderGroup));
+ }
+ }
+
+ *pcchGroups = dwGroups;
+
+ SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * This function cancels all pending blocking requests on the
+ * SCardGetStatusChange() function.
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid \p hContext handle (\ref SCARD_E_INVALID_HANDLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * DWORD cReaders;
+ * SCARD_READERSTATE rgReaderStates;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rgReaderStates.szReader = strdup("Reader X");
+ * rgReaderStates.dwCurrentState = SCARD_STATE_EMPTY;
+ * ...
+ * / * Spawn off thread for following function * /
+ * ...
+ * rv = SCardGetStatusChange(hContext, 0, rgReaderStates, cReaders);
+ * rv = SCardCancel(hContext);
+ * @endcode
+ */
+LONG SCardCancel(SCARDCONTEXT hContext)
+{
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ dwContextIndex = SCardGetContextIndice(hContext);
+
+ if (dwContextIndex == -1)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*
+ * Set the block status for this Context so blocking calls will
+ * complete
+ */
+ psContextMap[dwContextIndex].contextBlockStatus = BLOCK_STATUS_RESUME;
+
+ PROFILE_END
+
+ return SCARD_S_SUCCESS;
+}
+
+/**
+ * @brief check if a \ref SCARDCONTEXT is valid.
+ *
+ * Call this function to determine whether a smart card context handle is still
+ * valid. After a smart card context handle has been set by \ref
+ * SCardEstablishContext, it may become not valid if the resource manager
+ * service has been shut down.
+ *
+ * @param[in] hContext Connection context to the PC/SC Resource Manager.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Successful (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE Invalid Handle (\ref SCARD_E_INVALID_HANDLE)
+ *
+ * @test
+ * @code
+ * SCARDCONTEXT hContext;
+ * LONG rv;
+ * ...
+ * rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+ * rv = SCardIsValidContext(hContext);
+ * @endcode
+ */
+LONG SCardIsValidContext(SCARDCONTEXT hContext)
+{
+ LONG rv;
+ LONG dwContextIndex;
+
+ PROFILE_START
+
+ rv = SCARD_S_SUCCESS;
+
+ /*
+ * Make sure this context has been opened
+ */
+ dwContextIndex = SCardGetContextIndice(hContext);
+ if (dwContextIndex == -1)
+ rv = SCARD_E_INVALID_HANDLE;
+
+ PROFILE_END
+
+ return rv;
+}
+
+/**
+ * Functions for managing instances of SCardEstablishContext These functions
+ * keep track of Context handles and associate the blocking
+ * variable contextBlockStatus to an hContext
+ */
+
+/**
+ * @brief Adds an Application Context to the vector \c psContextMap.
+ *
+ * @param[in] hContext Application Context ID.
+ * @param[in] dwClientID Client connection ID.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Success (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NO_MEMORY There is no free slot to store \p hContext (\ref SCARD_E_NO_MEMORY)
+ */
+static LONG SCardAddContext(SCARDCONTEXT hContext, DWORD dwClientID)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
+ {
+ if (psContextMap[i].hContext == 0)
+ {
+ psContextMap[i].hContext = hContext;
+ psContextMap[i].dwClientID = dwClientID;
+ psContextMap[i].contextBlockStatus = BLOCK_STATUS_RESUME;
+ psContextMap[i].mMutex = malloc(sizeof(PCSCLITE_MUTEX));
+ SYS_MutexInit(psContextMap[i].mMutex);
+ return SCARD_S_SUCCESS;
+ }
+ }
+
+ return SCARD_E_NO_MEMORY;
+}
+
+/**
+ * @brief Get the index from the Application Context vector \c psContextMap
+ * for the passed context.
+ *
+ * This function is a thread-safe wrapper to the function
+ * SCardGetContextIndiceTH().
+ *
+ * @param[in] hContext Application Context whose index will be find.
+ *
+ * @return Index corresponding to the Application Context or -1 if it is
+ * not found.
+ */
+static LONG SCardGetContextIndice(SCARDCONTEXT hContext)
+{
+ LONG rv;
+
+ SCardLockThread();
+ rv = SCardGetContextIndiceTH(hContext);
+ SCardUnlockThread();
+
+ return rv;
+}
+
+/**
+ * @brief Get the index from the Application Context vector \c psContextMap
+ * for the passed context.
+ *
+ * This functions is not thread-safe and should not be called. Instead, call
+ * the function SCardGetContextIndice().
+ *
+ * @param[in] hContext Application Context whose index will be find.
+ *
+ * @return Index corresponding to the Application Context or -1 if it is
+ * not found.
+ */
+static LONG SCardGetContextIndiceTH(SCARDCONTEXT hContext)
+{
+ int i;
+
+ if (hContext == 0)
+ return -1;
+
+ /*
+ * Find this context and return its spot in the array
+ */
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
+ if (hContext == psContextMap[i].hContext)
+ return i;
+
+ return -1;
+}
+
+/**
+ * @brief Removes an Application Context from a control vector.
+ *
+ * @param[in] hContext Application Context to be removed.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Success (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_INVALID_HANDLE The context \p hContext was not found (\ref SCARD_E_INVALID_HANDLE)
+ */
+static LONG SCardRemoveContext(SCARDCONTEXT hContext)
+{
+ LONG retIndice;
+
+ retIndice = SCardGetContextIndiceTH(hContext);
+
+ if (retIndice == -1)
+ return SCARD_E_INVALID_HANDLE;
+ else
+ {
+ int i;
+
+ psContextMap[retIndice].hContext = 0;
+ SHMClientCloseSession(psContextMap[retIndice].dwClientID);
+ psContextMap[retIndice].dwClientID = 0;
+ free(psContextMap[retIndice].mMutex);
+ psContextMap[retIndice].mMutex = NULL;
+ psContextMap[retIndice].contextBlockStatus = BLOCK_STATUS_RESUME;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ /*
+ * Reset the \c hCard structs to zero
+ */
+ psContextMap[retIndice].psChannelMap[i].hCard = 0;
+ free(psContextMap[retIndice].psChannelMap[i].readerName);
+ psContextMap[retIndice].psChannelMap[i].readerName = NULL;
+ }
+
+ return SCARD_S_SUCCESS;
+ }
+}
+
+/*
+ * Functions for managing hCard values returned from SCardConnect.
+ */
+
+static LONG SCardAddHandle(SCARDHANDLE hCard, DWORD dwContextIndex,
+ LPSTR readerName)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ if (psContextMap[dwContextIndex].psChannelMap[i].hCard == 0)
+ {
+ psContextMap[dwContextIndex].psChannelMap[i].hCard = hCard;
+ psContextMap[dwContextIndex].psChannelMap[i].readerName = strdup(readerName);
+ return SCARD_S_SUCCESS;
+ }
+ }
+
+ return SCARD_E_NO_MEMORY;
+}
+
+static LONG SCardRemoveHandle(SCARDHANDLE hCard)
+{
+ DWORD dwContextIndice, dwChannelIndice;
+ LONG rv;
+
+ rv = SCardGetIndicesFromHandle(hCard, &dwContextIndice, &dwChannelIndice);
+
+ if (rv == -1)
+ return SCARD_E_INVALID_HANDLE;
+ else
+ {
+ psContextMap[dwContextIndice].psChannelMap[dwChannelIndice].hCard = 0;
+ free(psContextMap[dwContextIndice].psChannelMap[dwChannelIndice].readerName);
+ psContextMap[dwContextIndice].psChannelMap[dwChannelIndice].readerName = NULL;
+ return SCARD_S_SUCCESS;
+ }
+}
+
+static LONG SCardGetIndicesFromHandle(SCARDHANDLE hCard, PDWORD pdwContextIndice, PDWORD pdwChannelIndice)
+{
+ LONG rv;
+
+ if (0 == hCard)
+ return -1;
+
+ SCardLockThread();
+ rv = SCardGetIndicesFromHandleTH(hCard, pdwContextIndice, pdwChannelIndice);
+ SCardUnlockThread();
+
+ return rv;
+}
+
+static LONG SCardGetIndicesFromHandleTH(SCARDHANDLE hCard, PDWORD pdwContextIndice, PDWORD pdwChannelIndice)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
+ {
+ if (psContextMap[i].hContext != 0)
+ {
+ int j;
+
+ for (j = 0; j < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; j++)
+ {
+ if (psContextMap[i].psChannelMap[j].hCard == hCard)
+ {
+ *pdwContextIndice = i;
+ *pdwChannelIndice = j;
+ return SCARD_S_SUCCESS;
+ }
+ }
+
+ }
+ }
+
+ return -1;
+}
+
+/**
+ * @brief This function locks a mutex so another thread must wait to use this
+ * function.
+ *
+ * Wrapper to the function SYS_MutexLock().
+ */
+inline static LONG SCardLockThread(void)
+{
+ return SYS_MutexLock(&clientMutex);
+}
+
+/**
+ * @brief This function unlocks a mutex so another thread may use the client.
+ *
+ * Wrapper to the function SYS_MutexUnLock().
+ */
+inline static LONG SCardUnlockThread(void)
+{
+ return SYS_MutexUnLock(&clientMutex);
+}
+
+/**
+ * @brief Checks if the Server is running.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Server is running (\ref SCARD_S_SUCCESS)
+ * @retval SCARD_E_NO_SERVICE Server is not running (\ref SCARD_E_NO_SERVICE)
+ */
+static LONG SCardCheckDaemonAvailability(void)
+{
+ LONG rv;
+ struct stat statBuffer;
+
+ rv = SYS_Stat(PCSCLITE_PUBSHM_FILE, &statBuffer);
+
+ if (rv != 0)
+ {
+ Log1(PCSC_LOG_ERROR, "PCSC Not Running");
+ return SCARD_E_NO_SERVICE;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+/**
+ * free resources allocated by the library
+ * You _shall_ call this function if you use dlopen/dlclose to load/unload the
+ * library. Otherwise you will exhaust the ressources available.
+ */
+#ifdef __SUNPRO_C
+#pragma fini (SCardUnload)
+#endif
+
+void DESTRUCTOR SCardUnload(void)
+{
+ int i;
+
+ if (!isExecuted)
+ return;
+
+ /* unmap public shared file from memory */
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ if (readerStates[i] != NULL)
+ {
+ SYS_PublicMemoryUnmap(readerStates[i], sizeof(READER_STATE));
+ readerStates[i] = NULL;
+ }
+ }
+
+ SYS_CloseFile(mapAddr);
+ isExecuted = 0;
+}
+
+static int SCardInitializeOnce()
+{
+ int pageSize;
+ int i;
+
+ /*
+ * Do any system initilization here
+ */
+ SYS_Initialize();
+
+ /*
+ * Set up the memory mapped reader stats structures
+ */
+ mapAddr = SYS_OpenFile(PCSCLITE_PUBSHM_FILE, O_RDONLY, 0);
+ if (mapAddr < 0)
+ {
+ Log2(PCSC_LOG_ERROR, "Cannot open public shared file: %s",
+ PCSCLITE_PUBSHM_FILE);
+ return SCARD_E_NO_SERVICE;
+ }
+
+ pageSize = SYS_GetPageSize();
+
+ /*
+ * Allocate each reader structure in the memory map
+ */
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ readerStates[i] =
+ (PREADER_STATE)SYS_PublicMemoryMap(sizeof(READER_STATE),
+ mapAddr, (i * pageSize));
+ if (readerStates[i] == NULL)
+ {
+ Log1(PCSC_LOG_ERROR, "Cannot public memory map");
+ SYS_CloseFile(mapAddr); /* Close the memory map file */
+ return SCARD_F_INTERNAL_ERROR;
+ }
+ }
+
+ /*
+ * Initializes the application contexts and all channels for each one
+ */
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
+ {
+ int j;
+
+ /*
+ * Initially set the context struct to zero
+ */
+ psContextMap[i].dwClientID = 0;
+ psContextMap[i].hContext = 0;
+ psContextMap[i].contextBlockStatus = BLOCK_STATUS_RESUME;
+ psContextMap[i].mMutex = NULL;
+
+ for (j = 0; j < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; j++)
+ {
+ /*
+ * Initially set the hcard structs to zero
+ */
+ psContextMap[i].psChannelMap[j].hCard = 0;
+ psContextMap[i].psChannelMap[j].readerName = NULL;
+ }
+ }
+
+ /*
+ * Is there a free slot for this connection ?
+ */
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
+ {
+ if (psContextMap[i].dwClientID == 0)
+ break;
+ }
+
+ if (i == PCSCLITE_MAX_APPLICATION_CONTEXTS)
+ {
+ return SCARD_E_NO_MEMORY;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+static int SHMClientCommunicationTimeout()
+{
+ /*
+ This is a param to e.g. SHMClientReadMessage, and is a timeout in milliseconds.
+ The constant PCSCLITE_SERVER_ATTEMPTS is very poorly named; it is a time value
+ in milliseconds, not the number of attempts. Some values to use:
+ 5 default if PCSCLITE_ENHANCED_MESSAGING not defined
+ 200 if PCSCLITE_ENHANCED_MESSAGING is defined
+ 12000 might be a good value to set while debugging
+ */
+
+ static int baseTimeout = 12000;//PCSCLITE_CLIENT_ATTEMPTS;
+ volatile int timeOut = baseTimeout;
+
+ return timeOut;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and are
+ * subject to the Apple Public Source License Version 1.2 (the 'License').
+ * You may not use this file except in compliance with the License. Please
+ * obtain a copy of the License at http://www.apple.com/publicsource and
+ * read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please
+ * see the License for the specific language governing rights and
+ * limitations under the License.
+ */
+
+/******************************************************************
+
+ Title : winscard_msg.c
+ Package: PC/SC Lite
+ Author : David Corcoran
+ Date : 04/19/01
+ License: Copyright (C) 2001 David Corcoran
+ <corcoran at linuxnet.com>
+ Purpose: This is responsible for client/server transport.
+
+$Id: winscard_msg.c,v 1.4 2004/10/21 01:17:53 mb Exp $
+
+********************************************************************/
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "config.h"
+
+#ifdef PCSC_TARGET_SOLARIS
+#include <sys/filio.h>
+#endif
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "winscard.h"
+#include "winscard_msg.h"
+#include "sys_generic.h"
+#include "debuglog.h"
+
+int MSGSendData(int filedes, int blockAmount, const void *data,
+ unsigned int dataSize)
+{
+ /*
+ * default is success
+ */
+ int retval = 0;
+ /*
+ * record the time when we started
+ */
+ time_t start = time(0);
+ /*
+ * data to be written
+ */
+ unsigned char *buffer = (unsigned char *) data;
+ /*
+ * how many bytes remains to be written
+ */
+ size_t remaining = dataSize;
+
+ /*
+ * repeat until all data is written
+ */
+ while (remaining > 0)
+ {
+ fd_set write_fd;
+ struct timeval timeout;
+ int selret;
+
+ FD_ZERO(&write_fd);
+ FD_SET(filedes, &write_fd);
+
+ timeout.tv_usec = 0;
+ if ((timeout.tv_sec = start + blockAmount - time(0)) < 0)
+ {
+ /*
+ * we already timed out
+ */
+ retval = -1;
+ break;
+ }
+
+ selret = select(filedes + 1, NULL, &write_fd, NULL, &timeout);
+
+ /*
+ * try to write only when the file descriptor is writable
+ */
+ if (selret > 0)
+ {
+ int written;
+
+ if (!FD_ISSET(filedes, &write_fd))
+ {
+ /*
+ * very strange situation. it should be an assert really
+ */
+ retval = -1;
+ break;
+ }
+ written = write(filedes, buffer, remaining);
+
+ if (written > 0)
+ {
+ /*
+ * we wrote something
+ */
+ buffer += written;
+ remaining -= written;
+ } else if (written == 0)
+ {
+ /*
+ * peer closed the socket
+ */
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore the signals and socket full situations, all
+ * other errors are fatal
+ */
+ if (errno != EINTR && errno != EAGAIN)
+ {
+ retval = -1;
+ break;
+ }
+ }
+ } else if (selret == 0)
+ {
+ /*
+ * timeout
+ */
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * ignore signals
+ */
+ if (errno != EINTR)
+ {
+ DebugLogB
+ ("MSGServerProcessEvents: Select returns with failure: %s",
+ strerror(errno));
+ retval = -1;
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
+
+int MSGRecieveData(int filedes, int blockAmount, void *data,
+ unsigned int dataSize)
+{
+ /*
+ * default is success
+ */
+ int retval = 0;
+ /*
+ * record the time when we started
+ */
+ time_t start = time(0);
+ /*
+ * buffer where we place the readed bytes
+ */
+ unsigned char *buffer = (unsigned char *) data;
+ /*
+ * how many bytes we must read
+ */
+ size_t remaining = dataSize;
+
+ /*
+ * repeat until we get the whole message
+ */
+ while (remaining > 0)
+ {
+ fd_set read_fd;
+ struct timeval timeout;
+ int selret;
+
+ FD_ZERO(&read_fd);
+ FD_SET(filedes, &read_fd);
+
+ timeout.tv_usec = 0;
+ if ((timeout.tv_sec = start + blockAmount - time(0)) < 0)
+ {
+ /*
+ * we already timed out
+ */
+ retval = -1;
+ break;
+ }
+
+ selret = select(filedes + 1, &read_fd, NULL, NULL, &timeout);
+
+ /*
+ * try to read only when socket is readable
+ */
+ if (selret > 0)
+ {
+ int readed;
+
+ if (!FD_ISSET(filedes, &read_fd))
+ {
+ /*
+ * very strange situation. it should be an assert really
+ */
+ retval = -1;
+ break;
+ }
+ readed = read(filedes, buffer, remaining);
+
+ if (readed > 0)
+ {
+ /*
+ * we got something
+ */
+ buffer += readed;
+ remaining -= readed;
+ } else if (readed == 0)
+ {
+ /*
+ * peer closed the socket
+ */
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore the signals and empty socket situations, all
+ * other errors are fatal
+ */
+ if (errno != EINTR && errno != EAGAIN)
+ {
+ retval = -1;
+ break;
+ }
+ }
+ } else if (selret == 0)
+ {
+ /*
+ * timeout
+ */
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore signals, all other errors are fatal
+ */
+ if (errno != EINTR)
+ {
+ DebugLogB
+ ("MSGServerProcessEvents: Select returns with failure: %s",
+ strerror(errno));
+ retval = -1;
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,1000 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard_msg.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2001-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludoic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard_msg.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This is responsible for client/server communication.
+ *
+ * A file based socket (\c commonSocket) is used to send/receive only messages
+ * among clients and server.\n
+ * The messages' data are passed throw a memory mapped file: \c sharedSegmentMsg.
+ */
+
+#include "config.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "pcscexport.h"
+#include "winscard.h"
+#include "debug.h"
+#include "winscard_msg.h"
+#include "sys_generic.h"
+
+#include <libkern/OSByteOrder.h>
+/*
+ #define bswap_16 OSSwapInt16
+#define bswap_32 OSSwapInt32
+#define bswap_64 OSSwapInt64
+*/
+
+#include <security_utilities/debugging.h>
+
+/**
+ * @brief Wrapper for the SHMMessageReceive() function.
+ *
+ * Called by clients to read the server responses.
+ *
+ * @param[out] msgStruct Message read.
+ * @param[in] dwClientID Client socket handle.
+ * @param[in] blockamount Timeout in milliseconds.
+ *
+ * @return Same error codes as SHMMessageReceive().
+ */
+INTERNAL int32_t SHMClientRead(psharedSegmentMsg msgStruct, uint32_t dwClientID, int32_t blockamount)
+{
+ int rv = SHMMessageReceive(msgStruct, sizeof(*msgStruct), dwClientID, blockamount);
+ SHSharedSegmentMsgToHostOrder(msgStruct);
+ return rv;
+}
+
+/**
+ * @brief Wrapper for the SHMMessageReceive() function.
+ *
+ * Called by clients to read the server responses. This reads the exact number of bytes expected for the struct
+ *
+ * @param[out] msgStruct Message read.
+ * @param[in] dwClientID Client socket handle.
+ * @param[in] dataSize Size of the data at msgStruct->data
+ * @param[in] blockamount Timeout in milliseconds.
+ *
+ * @return Same error codes as SHMMessageReceive().
+ */
+INTERNAL int32_t SHMClientReadMessage(psharedSegmentMsg msgStruct, uint32_t dwClientID, size_t dataSize, int32_t blockamount)
+{
+ // Read the basic header first so we know the size of the rest
+ // The special case of "dataSize == 0" means that we should deduce the size of the
+ // data from the header
+ size_t headerSize = sizeof(sharedSegmentMsg) - sizeof(msgStruct->data);
+ Log2(PCSC_LOG_DEBUG, "SHMClientReadMessage: Issuing read for %d bytes (header)", headerSize);
+ secdebug("pcscd", "SHMClientReadMessage: Issuing read for %ld bytes (header)", headerSize);
+ int rv = SHMMessageReceive(msgStruct, headerSize, dwClientID, blockamount);
+ Log3(rv?PCSC_LOG_CRITICAL:PCSC_LOG_DEBUG, "SHMClientReadMessage: read message header error: 0x%08X [0x%08X]", rv, rv);
+ secdebug("pcscd", "SHMClientReadMessage: read message header error: 0x%08X [0x%08X]", rv, rv);
+ if (rv)
+ return rv;
+ SHSharedSegmentMsgToHostOrder(msgStruct);
+
+ // Integrity check
+ if (msgStruct->headerTag != WINSCARD_MSG_HEADER_TAG)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Error: read message header tag of: 0x%08X for possible command 0x%08X",
+ msgStruct->headerTag, msgStruct->command);
+ secdebug("pcscd", "Error: read message header tag of: 0x%08X for possible command 0x%08X",
+ msgStruct->headerTag, msgStruct->command);
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ if (dataSize == 0)
+ dataSize = msgStruct->msgSize - headerSize; // message size includes header
+ else
+ if (msgStruct->msgSize != (headerSize + dataSize))
+ {
+ Log2(PCSC_LOG_CRITICAL, "Error: create on client socket: %s", strerror(errno));
+ secdebug("pcscd", "Error: create on client socket: %s", strerror(errno));
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ Log2(PCSC_LOG_DEBUG, "SHMClientReadMessage: Issuing read for %d bytes", dataSize);
+ secdebug("pcscd", "SHMClientReadMessage: Issuing read for %ld bytes", dataSize);
+ if (blockamount == 0)
+ blockamount = PCSCLITE_SERVER_ATTEMPTS;
+ rv = SHMMessageReceive(msgStruct->data, dataSize, dwClientID, blockamount);
+ Log3(rv?PCSC_LOG_CRITICAL:PCSC_LOG_DEBUG, "SHMClientReadMessage: read message body error: 0x%08X [0x%08X]", rv, rv);
+ secdebug("pcscd", "SHMClientReadMessage: read message body error: 0x%08X [0x%08X]", rv, rv);
+
+ return rv;
+}
+
+/**
+ * @brief Prepares a communication channel for the client to talk to the server.
+ *
+ * This is called by the application to create a socket for local IPC with the
+ * server. The socket is associated to the file \c PCSCLITE_CSOCK_NAME.
+ *
+ * @param[out] pdwClientID Client Connection ID.
+ *
+ * @retval 0 Success.
+ * @retval -1 Can not create the socket.
+ * @retval -1 The socket can not open a connection.
+ * @retval -1 Can not set the socket to non-blocking.
+ */
+INTERNAL int SHMClientSetupSession(uint32_t *pdwClientID)
+{
+ struct sockaddr_un svc_addr;
+ int one;
+ int ret;
+
+ ret = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (ret < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Error: create on client socket: %s",
+ strerror(errno));
+ return -1;
+ }
+ *pdwClientID = ret;
+
+ svc_addr.sun_family = AF_UNIX;
+ strncpy(svc_addr.sun_path, PCSCLITE_CSOCK_NAME,
+ sizeof(svc_addr.sun_path));
+
+ if (connect(*pdwClientID, (struct sockaddr *) &svc_addr,
+ sizeof(svc_addr.sun_family) + strlen(svc_addr.sun_path) + 1) < 0)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Error: connect to client socket %s: %s",
+ PCSCLITE_CSOCK_NAME, strerror(errno));
+ SYS_CloseFile(*pdwClientID);
+ return -1;
+ }
+
+ one = 1;
+ if (ioctl(*pdwClientID, FIONBIO, &one) < 0)
+ {
+ Log3(PCSC_LOG_CRITICAL, "Error: cannot set socket %s nonblocking: %s",
+ PCSCLITE_CSOCK_NAME, strerror(errno));
+ SYS_CloseFile(*pdwClientID);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Closes the socket used by the client to communicate with the server.
+ *
+ * @param[in] dwClientID Client socket handle to be closed.
+ *
+ * @retval 0 Success.
+ */
+INTERNAL int SHMClientCloseSession(uint32_t dwClientID)
+{
+ SYS_CloseFile(dwClientID);
+ return 0;
+}
+
+/**
+ * @brief CalculateMessageSize
+ *
+ * @param[in] dataSize Size of the additional data to send in the message.
+ *
+ * @retval total message size.
+ */
+INTERNAL size_t SHMCalculateMessageSize(size_t dataSize)
+{
+ // PCSCLITE_MAX_MESSAGE_SIZE == sizeof(sharedSegmentMsg.data)
+ return sizeof(sharedSegmentMsg) - PCSCLITE_MAX_MESSAGE_SIZE + dataSize;;
+}
+
+
+/**
+ * @brief Sends a menssage from client to server or vice-versa.
+ *
+ * Writes the message in the shared file \c filedes.
+ *
+ * @param[in] buffer_void Message to be sent.
+ * @param[in] buffer_size Size of the message to send
+ * @param[in] filedes Socket handle.
+ * @param[in] blockAmount Timeout in milliseconds.
+ *
+ * @retval 0 Success
+ * @retval -1 Timeout.
+ * @retval -1 Socket is closed.
+ * @retval -1 A signal was received.
+ */
+INTERNAL int SHMMessageSend(void *buffer_void, uint64_t buffer_size,
+ int32_t filedes, int32_t blockAmount)
+{
+ char *buffer = (char *)buffer_void;
+
+ /*
+ * default is success
+ */
+ int retval = 0;
+ /*
+ * record the time when we started
+ */
+ time_t start = time(0);
+ /*
+ * how many bytes remains to be written
+ */
+ size_t remaining = buffer_size;
+
+ LogXxd(PCSC_LOG_DEBUG, "==> SHMMessageSend:\n", (const unsigned char *)buffer, buffer_size);
+
+ /*
+ * repeat until all data is written
+ */
+ while (remaining > 0)
+ {
+ fd_set write_fd;
+ struct timeval timeout;
+ int selret;
+
+ FD_ZERO(&write_fd);
+ FD_SET(filedes, &write_fd);
+
+ timeout.tv_usec = 0;
+ if ((timeout.tv_sec = start + blockAmount - time(0)) < 0)
+ {
+ /*
+ * we already timed out
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: we already timed out");
+ retval = -1;
+ break;
+ }
+
+ selret = select(filedes + 1, NULL, &write_fd, NULL, &timeout);
+
+ /*
+ * try to write only when the file descriptor is writable
+ */
+ if (selret > 0)
+ {
+ int written;
+
+ if (!FD_ISSET(filedes, &write_fd))
+ {
+ /*
+ * very strange situation. it should be an assert really
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: very strange situation: !FD_ISSET");
+ retval = -1;
+ break;
+ }
+ written = write(filedes, buffer, remaining);
+
+ if (written > 0)
+ {
+ /*
+ * we wrote something
+ */
+ buffer += written;
+ remaining -= written;
+ } else if (written == 0)
+ {
+ /*
+ * peer closed the socket
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: peer closed the socket");
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore the signals and socket full situations, all
+ * other errors are fatal
+ */
+ if (errno != EINTR && errno != EAGAIN)
+ {
+ retval = -1;
+ break;
+ }
+ }
+ } else if (selret == 0)
+ {
+ /*
+ * timeout
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: selret == 0 [timeout]");
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * ignore signals
+ */
+ if (errno != EINTR)
+ {
+ Log2(PCSC_LOG_ERROR, "select returns with failure: %s",
+ strerror(errno));
+ retval = -1;
+ break;
+ }
+ }
+ }
+
+ if (remaining > 0)
+ Log3(PCSC_LOG_ERROR, "failure to write all bytes, remaining: %d, err: ", remaining, strerror(errno));
+
+ return retval;
+}
+
+/**
+ * @brief Called by the Client to get the reponse from the server or vice-versa.
+ *
+ * Reads the message from the file \c filedes.
+ *
+ * @param[out] buffer_void Message read.
+ * @param[in] buffer_size Size to read
+ * @param[in] filedes Socket handle.
+ * @param[in] blockAmount Timeout in milliseconds.
+ *
+ * @retval 0 Success.
+ * @retval -1 Timeout.
+ * @retval -1 Socket is closed.
+ * @retval -1 A signal was received.
+ */
+INTERNAL int SHMMessageReceive(void *buffer_void, uint64_t buffer_size,
+ int32_t filedes, int32_t blockAmount)
+{
+ char *buffer = (char *)buffer_void;
+
+ /*
+ * default is success
+ */
+ int retval = 0;
+ /*
+ * record the time when we started
+ */
+ time_t start = time(0);
+ /*
+ * how many bytes we must read
+ */
+ size_t remaining = buffer_size;
+
+ /*
+ * repeat until we get the whole message
+ */
+ while (remaining > 0)
+ {
+ fd_set read_fd;
+ struct timeval timeout;
+ int selret;
+
+ FD_ZERO(&read_fd);
+ FD_SET(filedes, &read_fd);
+
+ timeout.tv_usec = 0;
+ if ((timeout.tv_sec = start + blockAmount - time(0)) < 0)
+ {
+ /*
+ * we already timed out
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: we already timed out");
+ retval = -1;
+ break;
+ }
+
+ selret = select(filedes + 1, &read_fd, NULL, NULL, &timeout);
+
+ /*
+ * try to read only when socket is readable
+ */
+ if (selret > 0)
+ {
+ int readed;
+
+ if (!FD_ISSET(filedes, &read_fd))
+ {
+ /*
+ * very strange situation. it should be an assert really
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: very strange situation: !FD_ISSET");
+ retval = -1;
+ break;
+ }
+ readed = read(filedes, buffer, remaining);
+
+ if (readed > 0)
+ {
+ /*
+ * we got something
+ */
+ buffer += readed;
+ remaining -= readed;
+ } else if (readed == 0)
+ {
+ /*
+ * peer closed the socket
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: peer closed the socket");
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore the signals and empty socket situations, all
+ * other errors are fatal
+ */
+ if (errno != EINTR && errno != EAGAIN)
+ {
+ retval = -1;
+ break;
+ }
+ }
+ } else if (selret == 0)
+ {
+ /*
+ * timeout
+ */
+ Log1(PCSC_LOG_ERROR, "SHMMessageReceive: selret == 0 [timeout]");
+ retval = -1;
+ break;
+ } else
+ {
+ /*
+ * we ignore signals, all other errors are fatal
+ */
+ if (errno != EINTR)
+ {
+ Log2(PCSC_LOG_ERROR, "select returns with failure: %s",
+ strerror(errno));
+ retval = -1;
+ break;
+ }
+ }
+ }
+
+ size_t bytesRead = (buffer_size - remaining);
+ Log3(PCSC_LOG_DEBUG, "SHMMessageReceive errno: 0x%08X: %s", errno, errno?strerror(errno):"no error");
+ Log3(retval?PCSC_LOG_ERROR:PCSC_LOG_DEBUG, "SHMMessageReceive retval: 0x%08X, bytes read: %d", retval, bytesRead);
+ LogXxd(PCSC_LOG_DEBUG, "<== SHMMessageReceive:\n", (const unsigned char *)buffer_void, bytesRead);
+ return retval;
+}
+
+/**
+ * @brief Wrapper for the SHMMessageSend() function.
+ *
+ * Called by clients to send messages to the server.
+ * The parameters \p command and \p data are set in the \c sharedSegmentMsg
+ * struct in order to be sent.
+ *
+ * @param[in] command Command to be sent.
+ * @param[in] dwClientID Client socket handle.
+ * @param[in] size Size of the message (\p data).
+ * @param[in] blockAmount Timeout to the operation in ms.
+ * @param[in] data_void Data to be sent.
+ *
+ * @return Same error codes as SHMMessageSend().
+ */
+INTERNAL int32_t WrapSHMWrite(uint32_t command, uint32_t dwClientID,
+ uint64_t size, uint32_t blockAmount, void *data_void)
+{
+ char *data = (char *)data_void;
+
+ sharedSegmentMsg msgStruct;
+ int ret;
+
+ /*
+ * Set the appropriate packet parameters
+ */
+
+ memset(&msgStruct, 0, sizeof(msgStruct));
+ msgStruct.headerTag = WINSCARD_MSG_HEADER_TAG;
+ msgStruct.msgSize = sizeof(sharedSegmentMsg) - sizeof(msgStruct.data) + size;
+ msgStruct.mtype = (command == CMD_VERSION)?CMD_VERSION:CMD_FUNCTION;
+ msgStruct.user_id = SYS_GetUID();
+ msgStruct.group_id = SYS_GetGID();
+ msgStruct.command = command;
+ msgStruct.date = time(NULL);
+ memset(msgStruct.key, 0, sizeof(msgStruct.key));
+
+ if ((SCARD_TRANSMIT_EXTENDED == command)
+ || (SCARD_CONTROL_EXTENDED == command))
+ {
+ /* first block */
+ size_t sizeToSend = (msgStruct.msgSize <= PCSCLITE_MAX_MESSAGE_SIZE)?msgStruct.msgSize:PCSCLITE_MAX_MESSAGE_SIZE;
+ size_t sizeRemaining = (msgStruct.msgSize <= PCSCLITE_MAX_MESSAGE_SIZE)?0:
+ (msgStruct.msgSize - PCSCLITE_MAX_MESSAGE_SIZE);
+ memcpy(msgStruct.data, data, sizeToSend);
+
+ SHSharedSegmentMsgToNetworkOrder(&msgStruct);
+ ret = SHMMessageSend(&msgStruct, sizeToSend, dwClientID, blockAmount);
+ if (ret)
+ return ret;
+
+ // Warning: this code only works for sizes of 2 blocks or less
+ if (sizeRemaining > sizeof(msgStruct.data))
+ {
+ Log2(PCSC_LOG_ERROR, "WrapSHMWrite: cannot send message of size %d", sizeRemaining);
+ return -1;
+ }
+
+ // Message header already has the correct byte order
+ /* do not send an empty second block */
+ if (sizeRemaining > 0)
+ {
+ memcpy(msgStruct.data, data, sizeRemaining);
+ ret = SHMMessageSend(&msgStruct, sizeToSend, dwClientID, blockAmount);
+ if (ret)
+ return ret;
+ }
+ }
+ else
+ if (size > sizeof(msgStruct.data))
+ {
+ Log3(PCSC_LOG_ERROR, "WrapSHMWrite: cannot send message of size %d with this command: %d", size, command);
+ return -1;
+ }
+ else
+ {
+ size_t sizeToSend = msgStruct.msgSize;
+ memcpy(msgStruct.data, data, size);
+ SHSharedSegmentMsgToNetworkOrder(&msgStruct);
+ ret = SHMMessageSend(&msgStruct, sizeToSend, dwClientID, blockAmount);
+ }
+ return ret;
+}
+
+/**
+ * @brief Closes the communications channel used by the server to talk to the
+ * clients.
+ *
+ * The socket used is closed and the file it is bound to is removed.
+ *
+ * @param[in] sockValue Socket to be closed.
+ * @param[in] pcFilePath File used by the socket.
+ */
+INTERNAL void SHMCleanupSharedSegment(int sockValue, const char *pcFilePath)
+{
+ SYS_CloseFile(sockValue);
+ SYS_Unlink((char *)pcFilePath);
+}
+
+#pragma mark -------------------- Byte ordering functions --------------------
+
+/**
+ * @brief Convert fields in the psharedSegmentMsg struct to network byte order for sending
+ *
+ * Call this before each call to SHMMessageSend. Note: the data fields are not processed
+ * and need to be done individually. Also have to look for WrapSHMWrite.
+ *
+ * @param[in/out] msgStruct Message read.
+ *
+ */
+INTERNAL void SHSharedSegmentMsgToNetworkOrder(psharedSegmentMsg msg)
+{
+ if (msg)
+ {
+ msg->headerTag = htonl(msg->headerTag);
+ msg->msgSize = htonl(msg->msgSize);
+ msg->mtype = htonl(msg->mtype);
+ msg->user_id = htonl(msg->user_id);
+ msg->group_id = htonl(msg->group_id);
+ msg->command = htonl(msg->command);
+ msg->date = htonl(msg->date);
+ }
+}
+
+/**
+ * @brief Convert fields in the psharedSegmentMsg struct to host byte order on receive
+ *
+ * Call this after each call to SHMMessageReceive. Note: the data fields are not processed
+ * and need to be done individually, e.g. in MSGFunctionDemarshall
+ *
+ * @param[in/out] msgStruct Message read.
+ *
+ */
+INTERNAL void SHSharedSegmentMsgToHostOrder(psharedSegmentMsg msg)
+{
+ if (msg)
+ {
+ msg->headerTag = ntohl(msg->headerTag);
+ msg->msgSize = ntohl(msg->msgSize);
+ msg->mtype = ntohl(msg->mtype);
+ msg->user_id = ntohl(msg->user_id);
+ msg->group_id = ntohl(msg->group_id);
+ msg->command = ntohl(msg->command);
+ msg->date = ntohl(msg->date);
+ }
+}
+
+INTERNAL void htonlControlStructExtended(control_struct_extended *cs)
+{
+ if (cs)
+ {
+ cs->hCard = htonl(cs->hCard);
+ cs->dwControlCode = htonl(cs->dwControlCode);
+ cs->cbSendLength = htonl(cs->cbSendLength);
+ cs->cbRecvLength = htonl(cs->cbRecvLength);
+ cs->size = OSSwapHostToBigInt64(cs->size);
+ cs->rv = htonl(cs->rv); // so we don't forget about it
+ }
+}
+
+INTERNAL void ntohlControlStructExtended(control_struct_extended *cs)
+{
+ if (cs)
+ {
+ cs->hCard = ntohl(cs->hCard);
+ cs->dwControlCode = ntohl(cs->dwControlCode);
+ cs->cbSendLength = ntohl(cs->cbSendLength);
+ cs->cbRecvLength = ntohl(cs->cbRecvLength);
+ cs->size = OSSwapBigToHostInt64(cs->size);
+ cs->rv = ntohl(cs->rv);
+ }
+}
+
+INTERNAL void htonlTransmitStruct(transmit_struct *ts)
+{
+ if (ts)
+ {
+ ts->hCard = htonl(ts->hCard);
+ ts->pioSendPciProtocol = htonl(ts->pioSendPciProtocol);
+ ts->pioSendPciLength = htonl(ts->pioSendPciLength);
+ ts->cbSendLength = htonl(ts->cbSendLength);
+ ts->pioRecvPciProtocol = htonl(ts->pioRecvPciProtocol);
+ ts->pioRecvPciLength = htonl(ts->pioRecvPciLength);
+ ts->pcbRecvLength = htonl(ts->pcbRecvLength);
+ ts->rv = htonl(ts->rv); // so we don't forget about it
+ }
+}
+
+INTERNAL void ntohlTransmitStruct(transmit_struct *ts)
+{
+ if (ts)
+ {
+ ts->hCard = ntohl(ts->hCard);
+ ts->pioSendPciProtocol = ntohl(ts->pioSendPciProtocol);
+ ts->pioSendPciLength = ntohl(ts->pioSendPciLength);
+ ts->cbSendLength = ntohl(ts->cbSendLength);
+ ts->pioRecvPciProtocol = ntohl(ts->pioRecvPciProtocol);
+ ts->pioRecvPciLength = ntohl(ts->pioRecvPciLength);
+ ts->pcbRecvLength = ntohl(ts->pcbRecvLength);
+ ts->rv = ntohl(ts->rv);
+ }
+}
+
+INTERNAL void htonlTransmitStructExtended(transmit_struct_extended *ts)
+{
+ if (ts)
+ {
+ ts->hCard = htonl(ts->hCard);
+ ts->pioSendPciProtocol = htonl(ts->pioSendPciProtocol);
+ ts->pioSendPciLength = htonl(ts->pioSendPciLength);
+ ts->cbSendLength = htonl(ts->cbSendLength);
+ ts->pioRecvPciProtocol = htonl(ts->pioRecvPciProtocol);
+ ts->pioRecvPciLength = htonl(ts->pioRecvPciLength);
+ ts->pcbRecvLength = htonl(ts->pcbRecvLength);
+ /* Networks generally use big-endian order, and thus it is called network order when sending information over a network in a common format. */
+ ts->size = OSSwapHostToBigInt64(ts->size);
+ ts->rv = htonl(ts->rv); // so we don't forget about it
+ }
+}
+
+INTERNAL void ntohlTransmitStructExtended(transmit_struct_extended *ts)
+{
+ if (ts)
+ {
+ ts->hCard = ntohl(ts->hCard);
+ ts->pioSendPciProtocol = ntohl(ts->pioSendPciProtocol);
+ ts->pioSendPciLength = ntohl(ts->pioSendPciLength);
+ ts->cbSendLength = ntohl(ts->cbSendLength);
+ ts->pioRecvPciLength = ntohl(ts->pioRecvPciLength);
+ ts->pcbRecvLength = ntohl(ts->pcbRecvLength);
+ ts->size = OSSwapBigToHostInt64(ts->size);
+ ts->rv = ntohl(ts->rv);
+ }
+}
+
+INTERNAL void htonlEstablishStruct(establish_struct *es)
+{
+ if (es)
+ {
+ es->dwScope = htonl(es->dwScope);
+ es->phContext = htonl(es->phContext);
+ es->rv = htonl(es->rv);
+ }
+}
+
+INTERNAL void ntohlEstablishStruct(establish_struct *es)
+{
+ if (es)
+ {
+ es->dwScope = ntohl(es->dwScope);
+ es->phContext = ntohl(es->phContext);
+ es->rv = ntohl(es->rv);
+ }
+}
+
+INTERNAL void htonlReleaseStruct(release_struct *rs)
+{
+ if (rs)
+ {
+ rs->hContext = htonl(rs->hContext);
+ rs->rv = htonl(rs->rv);
+ }
+}
+
+INTERNAL void ntohlReleaseStruct(release_struct *rs)
+{
+ if (rs)
+ {
+ rs->hContext = ntohl(rs->hContext);
+ rs->rv = ntohl(rs->rv);
+ }
+}
+
+INTERNAL void htonlConnectStruct(connect_struct *cs)
+{
+ if (cs)
+ {
+ cs->hContext = htonl(cs->hContext);
+ cs->dwShareMode = htonl(cs->dwShareMode);
+ cs->dwPreferredProtocols = htonl(cs->dwPreferredProtocols);
+ cs->phCard = htonl(cs->phCard);
+ cs->pdwActiveProtocol = htonl(cs->pdwActiveProtocol);
+ cs->rv = htonl(cs->rv);
+ }
+}
+
+INTERNAL void ntohlConnectStruct(connect_struct *cs)
+{
+ if (cs)
+ {
+ cs->hContext = ntohl(cs->hContext);
+ cs->dwShareMode = ntohl(cs->dwShareMode);
+ cs->dwPreferredProtocols = ntohl(cs->dwPreferredProtocols);
+ cs->phCard = ntohl(cs->phCard);
+ cs->pdwActiveProtocol = ntohl(cs->pdwActiveProtocol);
+ cs->rv = ntohl(cs->rv);
+ }
+}
+
+INTERNAL void htonlReconnectStruct(reconnect_struct *rc)
+{
+ if (rc)
+ {
+ rc->hCard = htonl(rc->hCard);
+ rc->dwShareMode = htonl(rc->dwShareMode);
+ rc->dwPreferredProtocols = htonl(rc->dwPreferredProtocols);
+ rc->dwInitialization = htonl(rc->dwInitialization);
+ rc->pdwActiveProtocol = htonl(rc->pdwActiveProtocol);
+ rc->rv = htonl(rc->rv);
+ }
+}
+
+INTERNAL void ntohlReconnectStruct(reconnect_struct *rc)
+{
+ if (rc)
+ {
+ rc->hCard = ntohl(rc->hCard);
+ rc->dwShareMode = ntohl(rc->dwShareMode);
+ rc->dwPreferredProtocols = ntohl(rc->dwPreferredProtocols);
+ rc->dwInitialization = ntohl(rc->dwInitialization);
+ rc->pdwActiveProtocol = ntohl(rc->pdwActiveProtocol);
+ rc->rv = ntohl(rc->rv);
+ }
+}
+
+INTERNAL void htonlDisconnectStruct(disconnect_struct *dc)
+{
+ if (dc)
+ {
+ dc->hCard = htonl(dc->hCard);
+ dc->dwDisposition = htonl(dc->dwDisposition);
+ dc->rv = htonl(dc->rv);
+ }
+}
+
+INTERNAL void ntohlDisconnectStruct(disconnect_struct *dc)
+{
+ if (dc)
+ {
+ dc->hCard = ntohl(dc->hCard);
+ dc->dwDisposition = ntohl(dc->dwDisposition);
+ dc->rv = ntohl(dc->rv);
+ }
+}
+
+INTERNAL void htonlBeginStruct(begin_struct *bs)
+{
+ if (bs)
+ {
+ bs->hCard = htonl(bs->hCard);
+ bs->rv = htonl(bs->rv);
+ }
+}
+
+INTERNAL void ntohlBeginStruct(begin_struct *bs)
+{
+ if (bs)
+ {
+ bs->hCard = ntohl(bs->hCard);
+ bs->rv = ntohl(bs->rv);
+ }
+}
+
+INTERNAL void htonlCancelStruct(cancel_struct *cs)
+{
+ if (cs)
+ {
+ cs->hCard = htonl(cs->hCard);
+ cs->rv = htonl(cs->rv);
+ }
+}
+
+INTERNAL void ntohlCancelStruct(cancel_struct *cs)
+{
+ if (cs)
+ {
+ cs->hCard = ntohl(cs->hCard);
+ cs->rv = ntohl(cs->rv);
+ }
+}
+
+INTERNAL void htonlEndStruct(end_struct *es)
+{
+ if (es)
+ {
+ es->hCard = htonl(es->hCard);
+ es->dwDisposition = htonl(es->dwDisposition);
+ es->rv = htonl(es->rv);
+ }
+}
+
+INTERNAL void ntohlEndStruct(end_struct *es)
+{
+ if (es)
+ {
+ es->hCard = ntohl(es->hCard);
+ es->dwDisposition = ntohl(es->dwDisposition);
+ es->rv = ntohl(es->rv);
+ }
+}
+
+INTERNAL void htonlStatusStruct(status_struct *ss)
+{
+ if (ss)
+ {
+ ss->hCard = htonl(ss->hCard);
+ ss->pcchReaderLen = htonl(ss->pcchReaderLen);
+ ss->pdwState = htonl(ss->pdwState);
+ ss->pdwProtocol = htonl(ss->pdwProtocol);
+ ss->pcbAtrLen = htonl(ss->pcbAtrLen);
+ ss->rv = htonl(ss->rv);
+ }
+}
+
+INTERNAL void ntohlStatusStruct(status_struct *ss)
+{
+ if (ss)
+ {
+ ss->hCard = ntohl(ss->hCard);
+ ss->pcchReaderLen = ntohl(ss->pcchReaderLen);
+ ss->pdwState = ntohl(ss->pdwState);
+ ss->pdwProtocol = ntohl(ss->pdwProtocol);
+ ss->pcbAtrLen = ntohl(ss->pcbAtrLen);
+ ss->rv = ntohl(ss->rv);
+ }
+}
+
+INTERNAL void htonlControlStruct(control_struct *cs)
+{
+ if (cs)
+ {
+ cs->hCard = htonl(cs->hCard);
+ cs->dwControlCode = htonl(cs->dwControlCode);
+ cs->cbSendLength = htonl(cs->cbSendLength);
+ cs->cbRecvLength = htonl(cs->cbRecvLength);
+ cs->dwBytesReturned = htonl(cs->dwBytesReturned);
+ cs->rv = htonl(cs->rv);
+ }
+}
+
+INTERNAL void ntohlControlStruct(control_struct *cs)
+{
+ if (cs)
+ {
+ cs->hCard = ntohl(cs->hCard);
+ cs->dwControlCode = ntohl(cs->dwControlCode);
+ cs->cbSendLength = ntohl(cs->cbSendLength);
+ cs->cbRecvLength = ntohl(cs->cbRecvLength);
+ cs->dwBytesReturned = ntohl(cs->dwBytesReturned);
+ cs->rv = ntohl(cs->rv);
+ }
+}
+
+INTERNAL void htonlGetSetStruct(getset_struct *gs)
+{
+ if (gs)
+ {
+ gs->hCard = htonl(gs->hCard);
+ gs->dwAttrId = htonl(gs->dwAttrId);
+ gs->cbAttrLen = htonl(gs->cbAttrLen);
+ gs->rv = htonl(gs->rv);
+ }
+}
+
+INTERNAL void ntohlGetSetStruct(getset_struct *gs)
+{
+ if (gs)
+ {
+ gs->hCard = ntohl(gs->hCard);
+ gs->dwAttrId = ntohl(gs->dwAttrId);
+ gs->cbAttrLen = ntohl(gs->cbAttrLen);
+ gs->rv = ntohl(gs->rv);
+ }
+}
+
+INTERNAL void htonlVersionStruct(version_struct *vs)
+{
+ if (vs)
+ {
+ vs->major = htonl(vs->major);
+ vs->minor = htonl(vs->minor);
+ vs->rv = htonl(vs->rv);
+ }
+}
+
+INTERNAL void ntohlVersionStruct(version_struct *vs)
+{
+ if (vs)
+ {
+ vs->major = ntohl(vs->major);
+ vs->minor = ntohl(vs->minor);
+ vs->rv = ntohl(vs->rv);
+ }
+}
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,423 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard_msg.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2001-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard_msg.h 2900 2008-04-22 13:12:50Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This defines some structures and \#defines to be used over
+ * the transport layer.
+ */
+
+#ifndef __winscard_msg_h__
+#define __winscard_msg_h__
+
+#include "pcscexport.h"
+
+/** Major version of the current message protocol */
+#define PROTOCOL_VERSION_MAJOR 3
+/** Minor version of the current message protocol */
+#define PROTOCOL_VERSION_MINOR 0
+
+#define WINSCARD_MSG_HEADER_TAG 0x12345678
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * @brief General structure for client/serve message data exchange.
+ *
+ * It is used in the calls of \c SHMMessageSend and \c SHMMessageReceive.
+ * The field \c data is interpreted according to the values of the fields
+ * \c mtype and \c command. The possible structs the \c data field can
+ * represent are: \c version_struct \c client_struct \c establish_struct
+ * \c release_struct \c connect_struct \c reconnect_struct
+ * \c disconnect_struct \c begin_struct \c end_struct \c cancel_struct
+ * \c status_struct \c transmit_struct \c control_struct \c getset_struct
+ */
+ typedef struct rxSharedSegment
+ {
+ uint32_t headerTag; /** Always WINSCARD_MSG_HEADER_TAG */
+ uint32_t msgSize; /** size of the whole message being sent/received */
+ uint32_t mtype; /** one of the \c pcsc_adm_commands */
+ uint32_t user_id;
+ uint32_t group_id;
+ uint32_t command; /** one of the \c pcsc_msg_commands */
+ uint64_t date;
+ unsigned char key[PCSCLITE_MSG_KEY_LEN];
+ unsigned char data[PCSCLITE_MAX_MESSAGE_SIZE];
+ }
+ sharedSegmentMsg, *psharedSegmentMsg;
+
+ /**
+ * Command types available to use in the field \c sharedSegmentMsg.mtype.
+ */
+ enum pcsc_adm_commands
+ {
+ CMD_FUNCTION = 0xF1,
+ CMD_FAILED = 0xF2,
+ CMD_SERVER_DIED = 0xF3,
+ CMD_CLIENT_DIED = 0xF4,
+ CMD_READER_EVENT = 0xF5,
+ CMD_SYN = 0xF6,
+ CMD_ACK = 0xF7,
+ CMD_VERSION = 0xF8 /**< version of the IPC */
+ };
+
+ /**
+ * @brief Commands available to use in the field \c sharedSegmentMsg.command.
+ */
+ enum pcsc_msg_commands
+ {
+ SCARD_ESTABLISH_CONTEXT = 0x01, /**< used by SCardEstablishContext() */
+ SCARD_RELEASE_CONTEXT = 0x02, /**< used by SCardReleaseContext() */
+ SCARD_LIST_READERS = 0x03, /**< used by SCardListReaders() */
+ SCARD_CONNECT = 0x04, /**< used by SCardConnect() */
+ SCARD_RECONNECT = 0x05, /**< used by SCardReconnect() */
+ SCARD_DISCONNECT = 0x06, /**< used by SCardDisconnect() */
+ SCARD_BEGIN_TRANSACTION = 0x07, /**< used by SCardBeginTransaction() */
+ SCARD_END_TRANSACTION = 0x08, /**< used by SCardEndTransaction() */
+ SCARD_TRANSMIT = 0x09, /**< used by SCardTransmit() */
+ SCARD_CONTROL = 0x0A, /**< used by SCardControl() */
+ SCARD_STATUS = 0x0B, /**< used by SCardStatus() */
+ SCARD_GET_STATUS_CHANGE = 0x0C, /**< used by SCardGetStatusChange() */
+ SCARD_CANCEL = 0x0D, /**< used by SCardCancel() */
+ SCARD_CANCEL_TRANSACTION = 0x0E,
+ SCARD_GET_ATTRIB = 0x0F, /**< used by SCardGetAttrib() */
+ SCARD_SET_ATTRIB = 0x10, /**< used by SCardSetAttrib() */
+ SCARD_TRANSMIT_EXTENDED = 0x11, /**< used by SCardTransmit() */
+ SCARD_CONTROL_EXTENDED = 0x12 /**< used by SCardControl() */
+ };
+
+ /**
+ * @brief Information transmitted in \ref CMD_VERSION Messages.
+ */
+ struct version_struct
+ {
+ int32_t major; /**< IPC major \ref PROTOCOL_VERSION_MAJOR */
+ int32_t minor; /**< IPC minor \ref PROTOCOL_VERSION_MINOR */
+ uint32_t rv;
+ };
+ typedef struct version_struct version_struct;
+
+ struct client_struct
+ {
+ uint32_t hContext;
+ };
+ typedef struct client_struct client_struct;
+
+ /**
+ * @brief Information contained in \ref SCARD_ESTABLISH_CONTEXT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct establish_struct
+ {
+ uint32_t dwScope;
+ uint32_t phContext;
+ uint32_t rv;
+ };
+ typedef struct establish_struct establish_struct;
+
+ /**
+ * @brief Information contained in \ref SCARD_RELEASE_CONTEXT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct release_struct
+ {
+ uint32_t hContext;
+ uint32_t rv;
+ };
+ typedef struct release_struct release_struct;
+
+ /**
+ * @brief contained in \ref SCARD_CONNECT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct connect_struct
+ {
+ uint32_t hContext;
+ char szReader[MAX_READERNAME];
+ uint32_t dwShareMode;
+ uint32_t dwPreferredProtocols;
+ int32_t phCard;
+ uint32_t pdwActiveProtocol;
+ uint32_t rv;
+ };
+ typedef struct connect_struct connect_struct;
+
+ /**
+ * @brief contained in \ref SCARD_RECONNECT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct reconnect_struct
+ {
+ int32_t hCard;
+ uint32_t dwShareMode;
+ uint32_t dwPreferredProtocols;
+ uint32_t dwInitialization;
+ uint32_t pdwActiveProtocol;
+ uint32_t rv;
+ };
+ typedef struct reconnect_struct reconnect_struct;
+
+ /**
+ * @brief contained in \ref SCARD_DISCONNECT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct disconnect_struct
+ {
+ int32_t hCard;
+ uint32_t dwDisposition;
+ uint32_t rv;
+ };
+ typedef struct disconnect_struct disconnect_struct;
+
+ /**
+ * @brief contained in \ref SCARD_BEGIN_TRANSACTION Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct begin_struct
+ {
+ int32_t hCard;
+ uint32_t rv;
+ };
+ typedef struct begin_struct begin_struct;
+
+ /**
+ * @brief contained in \ref SCARD_END_TRANSACTION Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct end_struct
+ {
+ int32_t hCard;
+ uint32_t dwDisposition;
+ uint32_t rv;
+ };
+ typedef struct end_struct end_struct;
+
+ /**
+ * @brief contained in \ref SCARD_CANCEL Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct cancel_struct
+ {
+ int32_t hCard;
+ uint32_t rv;
+ };
+ typedef struct cancel_struct cancel_struct;
+
+ /**
+ * @brief contained in \ref SCARD_STATUS Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct status_struct
+ {
+ int32_t hCard;
+ char mszReaderNames[MAX_READERNAME];
+ uint32_t pcchReaderLen;
+ uint32_t pdwState;
+ uint32_t pdwProtocol;
+ uint8_t pbAtr[MAX_ATR_SIZE];
+ uint32_t pcbAtrLen;
+ uint32_t rv;
+ };
+ typedef struct status_struct status_struct;
+
+ /**
+ * @brief contained in \ref SCARD_TRANSMIT Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct transmit_struct
+ {
+ int32_t hCard;
+ uint32_t pioSendPciProtocol;
+ uint32_t pioSendPciLength;
+ uint8_t pbSendBuffer[MAX_BUFFER_SIZE];
+ uint32_t cbSendLength;
+ uint32_t pioRecvPciProtocol;
+ uint32_t pioRecvPciLength;
+ uint8_t pbRecvBuffer[MAX_BUFFER_SIZE];
+ uint32_t pcbRecvLength;
+ uint32_t rv;
+ };
+ typedef struct transmit_struct transmit_struct;
+
+ /**
+ * @brief contained in \ref SCARD_TRANSMIT_EXTENDED Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct transmit_struct_extended
+ {
+ int32_t hCard;
+ uint32_t pioSendPciProtocol;
+ uint32_t pioSendPciLength;
+ uint32_t cbSendLength;
+ uint32_t pioRecvPciProtocol;
+ uint32_t pioRecvPciLength;
+ uint32_t pcbRecvLength;
+ uint32_t rv;
+ uint64_t size;
+ uint8_t data[1];
+ };
+ typedef struct transmit_struct_extended transmit_struct_extended;
+
+ /**
+ * @brief contained in \ref SCARD_CONTROL Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct control_struct
+ {
+ int32_t hCard;
+ uint32_t dwControlCode;
+ uint8_t pbSendBuffer[MAX_BUFFER_SIZE];
+ uint32_t cbSendLength;
+ uint8_t pbRecvBuffer[MAX_BUFFER_SIZE];
+ uint32_t cbRecvLength;
+ uint32_t dwBytesReturned;
+ uint32_t rv;
+ };
+ typedef struct control_struct control_struct;
+
+ /**
+ * @brief contained in \ref SCARD_CONTROL_EXTENDED Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct control_struct_extended
+ {
+ int32_t hCard;
+ uint32_t dwControlCode;
+ uint32_t cbSendLength;
+ uint32_t cbRecvLength;
+ uint32_t pdwBytesReturned;
+ uint32_t rv;
+ uint64_t size;
+ uint8_t data[1];
+ };
+ typedef struct control_struct_extended control_struct_extended;
+
+ /**
+ * @brief contained in \ref SCARD_GET_ATTRIB and \c Messages.
+ *
+ * These data are passed throw the field \c sharedSegmentMsg.data.
+ */
+ struct getset_struct
+ {
+ int32_t hCard;
+ uint32_t dwAttrId;
+ uint8_t pbAttr[MAX_BUFFER_SIZE];
+ uint32_t cbAttrLen;
+ uint32_t rv;
+ };
+ typedef struct getset_struct getset_struct;
+
+ /*
+ * Now some function definitions
+ */
+
+ int32_t SHMClientReadMessage(psharedSegmentMsg msgStruct, uint32_t dwClientID, size_t dataSize, int blockamount);
+
+ int32_t SHMClientRead(psharedSegmentMsg, uint32_t, int32_t);
+ int32_t SHMClientSetupSession(uint32_t *);
+ int32_t SHMClientCloseSession(uint32_t);
+ int32_t SHMInitializeCommonSegment(void);
+ int32_t SHMProcessEventsContext(uint32_t, psharedSegmentMsg, int32_t);
+ int32_t SHMProcessEventsServer(uint32_t *, int32_t);
+ int32_t SHMMessageSend(void *buffer, uint64_t buffer_size, int32_t filedes,
+ int32_t blockAmount);
+ int32_t SHMMessageReceive(void *buffer, uint64_t buffer_size,
+ int32_t filedes, int32_t blockAmount);
+ int32_t WrapSHMWrite(uint32_t command, uint32_t dwClientID, uint64_t dataSize,
+ uint32_t blockAmount, void *data);
+ void SHMCleanupSharedSegment(int32_t, const char *);
+
+ void SHSharedSegmentMsgToNetworkOrder(psharedSegmentMsg msg);
+ void SHSharedSegmentMsgToHostOrder(psharedSegmentMsg msg);
+ size_t SHMCalculateMessageSize(size_t dataSize);
+ int32_t SHMCommunicationTimeout();
+
+ // Fix up byte ordering
+ INTERNAL void htonlControlStructExtended(control_struct_extended *cs);
+ INTERNAL void ntohlControlStructExtended(control_struct_extended *cs);
+ INTERNAL void htonlTransmitStructExtended(transmit_struct_extended *ts);
+ INTERNAL void ntohlTransmitStructExtended(transmit_struct_extended *ts);
+ INTERNAL void htonlEstablishStruct(establish_struct *es);
+ INTERNAL void ntohlEstablishStruct(establish_struct *es);
+ INTERNAL void htonlTransmitStruct(transmit_struct *ts);
+ INTERNAL void ntohlTransmitStruct(transmit_struct *ts);
+ INTERNAL void htonlReleaseStruct(release_struct *rs);
+ INTERNAL void ntohlReleaseStruct(release_struct *rs);
+ INTERNAL void htonlConnectStruct(connect_struct *Cs);
+ INTERNAL void ntohlConnectStruct(connect_struct *cs);
+ INTERNAL void htonlReconnectStruct(reconnect_struct *rc);
+ INTERNAL void ntohlReconnectStruct(reconnect_struct *rc);
+ INTERNAL void htonlDisconnectStruct(disconnect_struct *dc);
+ INTERNAL void ntohlDisconnectStruct(disconnect_struct *dc);
+ INTERNAL void htonlBeginStruct(begin_struct *bs);
+ INTERNAL void ntohlBeginStruct(begin_struct *bs);
+ INTERNAL void htonlCancelStruct(cancel_struct *cs);
+ INTERNAL void ntohlCancelStruct(cancel_struct *cs);
+ INTERNAL void htonlEndStruct(end_struct *es);
+ INTERNAL void ntohlEndStruct(end_struct *es);
+ INTERNAL void htonlStatusStruct(status_struct *ss);
+ INTERNAL void ntohlStatusStruct(status_struct *ss);
+ INTERNAL void htonlControlStruct(control_struct *cs);
+ INTERNAL void ntohlControlStruct(control_struct *cs);
+ INTERNAL void htonlGetSetStruct(getset_struct *gs);
+ INTERNAL void ntohlGetSetStruct(getset_struct *gs);
+ INTERNAL void htonlVersionStruct(version_struct *vs);
+ INTERNAL void ntohlVersionStruct(version_struct *vs);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg_srv.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg_srv.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_msg_srv.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,315 @@
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2001-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludoic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard_msg_srv.c 2961 2008-05-16 09:12:53Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief client/server communication (on the server side only)
+ *
+ * A file based socket (\c commonSocket) is used to send/receive only messages
+ * among clients and server.\n
+ * The messages' data are passed throw a memory mapped file: \c sharedSegmentMsg.
+ */
+
+#include "config.h"
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#include "wintypes.h"
+#include "pcscexport.h"
+#include "winscard.h"
+#include "debuglog.h"
+#include "winscard_msg.h"
+#include "sys_generic.h"
+
+/**
+ * Socket to a file, used for clients-server comminication.
+ */
+static int commonSocket = 0;
+extern char AraKiri;
+extern char ReCheckSerialReaders;
+
+/**
+ * @brief Accepts a Client connection.
+ *
+ * Called by \c SHMProcessEventsServer().
+ *
+ * @param[out] pdwClientID Connection ID used to reference the Client.
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 Can not establish the connection.
+ * @retval -1 Can not set the connection to non-blocking mode.
+ */
+static int SHMProcessCommonChannelRequest(uint32_t *pdwClientID)
+{
+ socklen_t clnt_len;
+ int new_sock;
+ struct sockaddr_un clnt_addr;
+ int one;
+
+ clnt_len = sizeof(clnt_addr);
+
+ if ((new_sock = accept(commonSocket, (struct sockaddr *) &clnt_addr,
+ &clnt_len)) < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Accept on common socket: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ *pdwClientID = new_sock;
+
+ one = 1;
+ if (ioctl(*pdwClientID, FIONBIO, &one) < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Error: cannot set socket nonblocking: %s",
+ strerror(errno));
+ SYS_CloseFile(*pdwClientID);
+ *pdwClientID = -1;
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * @brief Prepares the communication channel used by the server to talk to the
+ * clients.
+ *
+ * This is called by the server to create a socket for local IPC with the
+ * clients. The socket is associated to the file \c PCSCLITE_CSOCK_NAME.
+ * Each client will open a connection to this socket.
+ *
+ * @return Error code.
+ * @retval 0 Success
+ * @retval -1 Can not create the socket.
+ * @retval -1 Can not bind the socket to the file \c PCSCLITE_CSOCK_NAME.
+ * @retval -1 Can not put the socket in listen mode.
+ */
+INTERNAL int SHMInitializeCommonSegment(void)
+{
+ static struct sockaddr_un serv_adr;
+
+ /*
+ * Create the common shared connection socket
+ */
+ if ((commonSocket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Unable to create common socket: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ serv_adr.sun_family = AF_UNIX;
+ strncpy(serv_adr.sun_path, PCSCLITE_CSOCK_NAME,
+ sizeof(serv_adr.sun_path));
+ SYS_Unlink(PCSCLITE_CSOCK_NAME);
+
+ if (bind(commonSocket, (struct sockaddr *) &serv_adr,
+ sizeof(serv_adr.sun_family) + strlen(serv_adr.sun_path) + 1) < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Unable to bind common socket: %s",
+ strerror(errno));
+ SHMCleanupSharedSegment(commonSocket, PCSCLITE_CSOCK_NAME);
+ return -1;
+ }
+
+ if (listen(commonSocket, 1) < 0)
+ {
+ Log2(PCSC_LOG_CRITICAL, "Unable to listen common socket: %s",
+ strerror(errno));
+ SHMCleanupSharedSegment(commonSocket, PCSCLITE_CSOCK_NAME);
+ return -1;
+ }
+
+ /*
+ * Chmod the public entry channel
+ */
+ SYS_Chmod(PCSCLITE_CSOCK_NAME, S_IRWXO | S_IRWXG | S_IRWXU);
+
+ return 0;
+}
+
+/**
+ * @brief Looks for messages sent by clients.
+ *
+ * This is called by the Server's function \c SVCServiceRunLoop().
+ *
+ * @param[out] pdwClientID Connection ID used to reference the Client.
+ * @param[in] blocktime Timeout (not used).
+ *
+ * @return Error code.
+ * @retval 0 Success.
+ * @retval -1 Error accessing the communication channel.
+ * @retval -1 Can not set the connection to non-blocking mode.
+ * @retval 2 Timeout.
+ */
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#define DO_TIMEOUT
+#endif
+INTERNAL int32_t SHMProcessEventsServer(uint32_t *pdwClientID, int32_t blocktime)
+{
+ fd_set read_fd;
+ int selret;
+#ifdef DO_TIMEOUT
+ struct timeval tv;
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+#endif
+
+ FD_ZERO(&read_fd);
+
+ /*
+ * Set up the bit masks for select
+ */
+ FD_SET(commonSocket, &read_fd);
+
+ selret = select(commonSocket + 1, &read_fd, (fd_set *) NULL,
+ (fd_set *) NULL,
+#ifdef DO_TIMEOUT
+ &tv
+#else
+ NULL
+#endif
+ );
+
+ if (selret < 0)
+ {
+ if (EINTR == errno)
+ return -2;
+
+ Log2(PCSC_LOG_CRITICAL, "Select returns with failure: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ if (selret == 0)
+ /* timeout. On *BSD only */
+ return 2;
+
+ /*
+ * A common pipe packet has arrived - it could be a new application
+ */
+ if (FD_ISSET(commonSocket, &read_fd))
+ {
+ Log1(PCSC_LOG_DEBUG, "Common channel packet arrival");
+ if (SHMProcessCommonChannelRequest(pdwClientID) == -1)
+ {
+ Log2(PCSC_LOG_ERROR,
+ "error in SHMProcessCommonChannelRequest: %d", *pdwClientID);
+ return -1;
+ } else
+ {
+ Log2(PCSC_LOG_DEBUG,
+ "SHMProcessCommonChannelRequest detects: %d", *pdwClientID);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+/**
+ * @brief
+ *
+ * Called by \c ContextThread().
+ */
+INTERNAL int32_t SHMProcessEventsContext(uint32_t dwClientID,
+ psharedSegmentMsg msgStruct, int32_t blocktime)
+{
+ fd_set read_fd;
+ int selret, rv;
+ struct timeval tv;
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&read_fd);
+ FD_SET(dwClientID, &read_fd);
+
+ selret = select(dwClientID + 1, &read_fd, (fd_set *) NULL,
+ (fd_set *) NULL, &tv);
+
+ if (selret < 0)
+ {
+ Log2(PCSC_LOG_ERROR, "select returns with failure: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ if (selret == 0)
+ {
+// Log3(PCSC_LOG_ERROR, "SHMProcessEventsContext: select timed out, errno: %d, %s", errno,
+// strerror(errno));
+ /* timeout */
+ return 2;
+ }
+
+ if (FD_ISSET(dwClientID, &read_fd))
+ {
+ /*
+ * Return the current handle
+ */
+ /*
+ The 0 for size below means that SHMClientReadMessage should calculate the size from the
+ message header. The size is not sizeof(*msgStruct)
+ */
+ rv = SHMClientReadMessage(msgStruct, dwClientID, 0, SHMCommunicationTimeout());
+ if (rv == -1)
+ { /* The client has died */
+ Log2(PCSC_LOG_DEBUG, "Client has disappeared: %d", dwClientID);
+ msgStruct->mtype = CMD_CLIENT_DIED;
+ msgStruct->command = 0;
+ SYS_CloseFile(dwClientID);
+
+ return 0;
+ }
+
+ /*
+ * Set the identifier handle
+ */
+ Log2(PCSC_LOG_DEBUG, "correctly processed client: %d", dwClientID);
+ return 1;
+ }
+
+ return -1;
+}
+
+INTERNAL int SHMCommunicationTimeout()
+{
+ /*
+ This is a param to e.g. SHMClientReadMessage, and is a timeout in milliseconds.
+ The constant PCSCLITE_SERVER_ATTEMPTS is very poorly named; it is a time value
+ in milliseconds, not the number of attempts. Some values to use:
+ 5 default if PCSCLITE_ENHANCED_MESSAGING not defined
+ 200 if PCSCLITE_ENHANCED_MESSAGING is defined
+ 12000 might be a good value to set while debugging
+ */
+
+ static int baseTimeout = 12000;//PCSCLITE_SERVER_ATTEMPTS;
+ volatile int timeOut = baseTimeout;
+
+ return timeOut;
+}
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.c
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.c (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.c 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,892 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard_svc.c
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2001-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ * Ludovic Rousseau <ludovic.rousseau at free.fr>
+ *
+ * $Id: winscard_svc.c 2377 2007-02-05 13:13:56Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This demarshalls functions over the message queue and keeps
+ * track of clients and their handles.
+ *
+ * Each Client message is deald by creating a thread (\c CreateContextThread).
+ * The thread establishes reands and demarshalls the message and calls the
+ * appropriate function to threat it.
+ */
+
+#include "config.h"
+#include <time.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "wintypes.h"
+#include "pcsclite.h"
+#include "winscard.h"
+#include "debuglog.h"
+#include "winscard_msg.h"
+#include "winscard_svc.h"
+#include "sys_generic.h"
+#include "thread_generic.h"
+#include "readerfactory.h"
+#include "hotplug.h"
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+
+/**
+ * @brief Represents the an Application Context on the Server side.
+ *
+ * An Application Context contains Channels (\c hCard).
+ */
+static struct _psContext
+{
+ SCARDCONTEXT hContext;
+ SCARDHANDLE hCard[PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS];
+ DWORD dwClientID; /* Connection ID used to reference the Client. */
+ PCSCLITE_THREAD_T pthThread; /* Event polling thread's ID */
+ sharedSegmentMsg msgStruct; /* Msg sent by the Client */
+ int protocol_major, protocol_minor; /* Protocol number agreed between client and server*/
+} psContext[PCSCLITE_MAX_APPLICATIONS_CONTEXTS];
+
+LONG MSGCheckHandleAssociation(SCARDHANDLE, DWORD);
+LONG MSGFunctionDemarshall(psharedSegmentMsg, DWORD, uint32_t *replySize);
+LONG MSGAddContext(SCARDCONTEXT, DWORD);
+LONG MSGRemoveContext(SCARDCONTEXT, DWORD);
+LONG MSGAddHandle(SCARDCONTEXT, SCARDHANDLE, DWORD);
+LONG MSGRemoveHandle(SCARDHANDLE, DWORD);
+LONG MSGCleanupClient(DWORD);
+
+static void ContextThread(LPVOID pdwIndex);
+
+LONG ContextsInitialize(void)
+{
+ memset(psContext, 0, sizeof(struct _psContext)*PCSCLITE_MAX_APPLICATIONS_CONTEXTS);
+ return 1;
+}
+
+/**
+ * @brief Creates threads to handle messages received from Clients.
+ *
+ * @param[in] pdwClientID Connection ID used to reference the Client.
+ *
+ * @return Error code.
+ * @retval SCARD_S_SUCCESS Success.
+ * @retval SCARD_F_INTERNAL_ERROR Exceded the maximum number of simultaneous Application Contexts.
+ * @retval SCARD_E_NO_MEMORY Error creating the Context Thread.
+ */
+LONG CreateContextThread(PDWORD pdwClientID)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATIONS_CONTEXTS; i++)
+ {
+ if (psContext[i].dwClientID == 0)
+ {
+ psContext[i].dwClientID = *pdwClientID;
+ *pdwClientID = 0;
+ break;
+ }
+ }
+
+ if (i == PCSCLITE_MAX_APPLICATIONS_CONTEXTS)
+ {
+ SYS_CloseFile(psContext[i].dwClientID);
+ psContext[i].dwClientID = 0;
+ Log2(PCSC_LOG_CRITICAL, "No more context available (max: %d)",
+ PCSCLITE_MAX_APPLICATIONS_CONTEXTS);
+ return SCARD_F_INTERNAL_ERROR;
+ }
+
+ if (SYS_ThreadCreate(&psContext[i].pthThread, THREAD_ATTR_DETACHED,
+ (PCSCLITE_THREAD_FUNCTION( )) ContextThread,
+ (LPVOID) i) != 1)
+ {
+ SYS_CloseFile(psContext[i].dwClientID);
+ psContext[i].dwClientID = 0;
+ Log1(PCSC_LOG_CRITICAL, "SYS_ThreadCreate failed");
+ return SCARD_E_NO_MEMORY;
+ }
+
+ return SCARD_S_SUCCESS;
+}
+
+/*
+ * A list of local functions used to keep track of clients and their
+ * connections
+ */
+
+/**
+ * @brief Handles messages received from Clients.
+ *
+ * For each Client message a new instance of this thread is created.
+ *
+ * @param[in] dwIndex Index of an avaiable Application Context slot in
+ * \c psContext.
+ */
+
+/*
+ To handle the possible case where the client is one architecture and the server is another
+ (e.g. a PPC app running through Rosetta on OS X talking to a native i386 pcscd), we convert
+ everything going OUT over the pipe to network byte order. Conversely, everything coming IN
+ over the pipe is converted to host byte order.
+*/
+
+static void ContextThread(LPVOID dwIndex)
+{
+ LONG rv;
+ DWORD dwContextIndex = (DWORD)dwIndex;
+
+ Log2(PCSC_LOG_DEBUG, "Thread is started: %d",
+ psContext[dwContextIndex].dwClientID);
+
+ while (1)
+ {
+ sharedSegmentMsg msgStruct = {0,};
+
+ systemAwakeAndReadyCheck();
+
+ /*
+ Note: SHSharedSegmentMsgToHostOrder(&msgStruct) was called in SHMProcessEventsContext
+ This means that msgStruct contains host-order fields
+ */
+ switch (rv = SHMProcessEventsContext(psContext[dwContextIndex].dwClientID, &msgStruct, 0))
+ {
+ case 0:
+ if (msgStruct.mtype == CMD_CLIENT_DIED)
+ {
+ /*
+ * Clean up the dead client
+ */
+ Log2(PCSC_LOG_DEBUG, "Client die: %d",
+ psContext[dwContextIndex].dwClientID);
+ MSGCleanupClient(dwContextIndex);
+ SYS_ThreadExit((LPVOID) NULL);
+ }
+ break;
+
+ case 1:
+ if (msgStruct.mtype == CMD_FUNCTION)
+ {
+ /*
+ * Command must be found
+ */
+ uint32_t replySize = 0;
+ MSGFunctionDemarshall(&msgStruct, dwContextIndex, &replySize);
+
+ /* the SCARD_TRANSMIT_EXTENDED anwser is already sent by
+ * MSGFunctionDemarshall */
+ if ((msgStruct.command != SCARD_TRANSMIT_EXTENDED)
+ && (msgStruct.command != SCARD_CONTROL_EXTENDED))
+ {
+ sharedSegmentMsg tmpMsgStruct;
+ replySize += (sizeof(sharedSegmentMsg) - sizeof(msgStruct.data));
+ memcpy(&tmpMsgStruct, &msgStruct, replySize);
+ SHSharedSegmentMsgToNetworkOrder(&tmpMsgStruct);
+ rv = SHMMessageSend(&tmpMsgStruct, replySize,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ }
+ }
+ else
+ /* pcsc-lite client/server protocol version */
+ if (msgStruct.mtype == CMD_VERSION)
+ {
+ version_struct *veStr;
+ veStr = (version_struct *) msgStruct.data;
+ ntohlVersionStruct(veStr);
+
+ /* get the client protocol version */
+ psContext[dwContextIndex].protocol_major = veStr->major;
+ psContext[dwContextIndex].protocol_minor = veStr->minor;
+
+ Log3(PCSC_LOG_DEBUG,
+ "Client is protocol version %d:%d",
+ veStr->major, veStr->minor);
+
+ veStr->rv = SCARD_S_SUCCESS;
+
+ /* client is newer than server */
+ if ((veStr->major > PROTOCOL_VERSION_MAJOR)
+ || (veStr->major == PROTOCOL_VERSION_MAJOR
+ && veStr->minor > PROTOCOL_VERSION_MINOR))
+ {
+ Log3(PCSC_LOG_CRITICAL,
+ "Client protocol is too new %d:%d",
+ veStr->major, veStr->minor);
+ Log3(PCSC_LOG_CRITICAL,
+ "Server protocol is %d:%d",
+ PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR);
+ veStr->rv = SCARD_E_NO_SERVICE;
+ }
+
+ /* set the server protocol version */
+ veStr->major = PROTOCOL_VERSION_MAJOR;
+ veStr->minor = PROTOCOL_VERSION_MINOR;
+ htonlVersionStruct(veStr);
+
+ /* send back the response */
+ sharedSegmentMsg tmpMsgStruct = msgStruct;
+ SHSharedSegmentMsgToNetworkOrder(&tmpMsgStruct);
+ rv = SHMMessageSend(&tmpMsgStruct, SHMCalculateMessageSize(sizeof(version_struct)),
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ }
+ else
+ continue;
+
+ break;
+
+ case 2:
+ /*
+ * timeout in SHMProcessEventsContext(): do nothing
+ * this is used to catch the Ctrl-C signal at some time when
+ * nothing else happens
+ */
+ break;
+
+ case -1:
+ Log1(PCSC_LOG_ERROR, "Error in SHMProcessEventsContext");
+ break;
+
+ default:
+ Log2(PCSC_LOG_ERROR,
+ "SHMProcessEventsContext unknown retval: %d", rv);
+ break;
+ }
+ }
+}
+
+/**
+ * @brief Find out which message was sent by the Client and execute the right task.
+ *
+ * According to the command type sent by the client (\c pcsc_msg_commands),
+ * cast the message data to the correct struct so that is can be demarshalled.
+ * Then call the appropriate function to handle the request.
+ *
+ * Possible structs are: \c establish_struct \c release_struct
+ * \c connect_struct \c reconnect_struct \c disconnect_struct \c begin_struct
+ * \c cancel_struct \c end_struct \c status_struct \c transmit_struct
+ * \c control_struct \c getset_struct.
+ *
+ * @param[in] msgStruct Message to be demarshalled and executed.
+ * @param[in] dwContextIndex
+ */
+LONG MSGFunctionDemarshall(psharedSegmentMsg msgStruct, DWORD dwContextIndex, uint32_t *replySize)
+{
+ LONG rv;
+ establish_struct *esStr;
+ release_struct *reStr;
+ connect_struct *coStr;
+ reconnect_struct *rcStr;
+ disconnect_struct *diStr;
+ begin_struct *beStr;
+ cancel_struct *caStr;
+ end_struct *enStr;
+ status_struct *stStr;
+ transmit_struct *trStr;
+ control_struct *ctStr;
+ getset_struct *gsStr;
+
+ /*
+ * Zero out everything
+ */
+ rv = 0;
+ *replySize = 0;
+
+ /*
+ Note that we need to convert structs back out to network byte order
+ after the various calls are made, as this is how results are passed back
+ to the client
+ */
+ switch (msgStruct->command)
+ {
+
+ case SCARD_ESTABLISH_CONTEXT:
+ esStr = ((establish_struct *) msgStruct->data);
+ ntohlEstablishStruct(esStr);
+ esStr->rv = SCardEstablishContext(esStr->dwScope, 0, 0,
+ (int32_t *)&esStr->phContext);
+
+ if (esStr->rv == SCARD_S_SUCCESS)
+ esStr->rv =
+ MSGAddContext(esStr->phContext, dwContextIndex);
+ htonlEstablishStruct(esStr);
+ *replySize = sizeof(establish_struct);
+ break;
+
+ case SCARD_RELEASE_CONTEXT:
+ reStr = ((release_struct *) msgStruct->data);
+ ntohlReleaseStruct(reStr);
+
+ reStr->rv = SCardReleaseContext(reStr->hContext);
+
+ if (reStr->rv == SCARD_S_SUCCESS)
+ reStr->rv =
+ MSGRemoveContext(reStr->hContext, dwContextIndex);
+
+ htonlReleaseStruct(reStr);
+ *replySize = sizeof(release_struct);
+ break;
+
+ case SCARD_CONNECT:
+ coStr = ((connect_struct *) msgStruct->data);
+ ntohlConnectStruct(coStr);
+ Log3(PCSC_LOG_DEBUG, "SCardConnect hContext: 0x%08X, phCard: 0x%08X", coStr->hContext, coStr->phCard);
+ coStr->rv = SCardConnect(coStr->hContext, coStr->szReader,
+ coStr->dwShareMode, coStr->dwPreferredProtocols,
+ &coStr->phCard, &coStr->pdwActiveProtocol);
+ Log3(PCSC_LOG_DEBUG, "SCardConnect result: %d [0x%08X]", coStr->rv, coStr->rv);
+
+ if (coStr->rv == SCARD_S_SUCCESS)
+ {
+ coStr->rv =
+ MSGAddHandle(coStr->hContext, coStr->phCard, dwContextIndex);
+ Log3(PCSC_LOG_DEBUG, "MSGAddHandle result: %d [0x%08X]", coStr->rv, coStr->rv);
+ }
+ htonlConnectStruct(coStr);
+ *replySize = sizeof(connect_struct);
+ break;
+
+ case SCARD_RECONNECT:
+ rcStr = ((reconnect_struct *) msgStruct->data);
+ ntohlReconnectStruct(rcStr);
+ rv = MSGCheckHandleAssociation(rcStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+
+ rcStr->rv = SCardReconnect(rcStr->hCard, rcStr->dwShareMode,
+ rcStr->dwPreferredProtocols,
+ rcStr->dwInitialization, &rcStr->pdwActiveProtocol);
+ htonlReconnectStruct(rcStr);
+ *replySize = sizeof(reconnect_struct);
+ break;
+
+ case SCARD_DISCONNECT:
+ diStr = ((disconnect_struct *) msgStruct->data);
+ ntohlDisconnectStruct(diStr);
+ rv = MSGCheckHandleAssociation(diStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ diStr->rv = SCardDisconnect(diStr->hCard, diStr->dwDisposition);
+
+ if (diStr->rv == SCARD_S_SUCCESS)
+ diStr->rv =
+ MSGRemoveHandle(diStr->hCard, dwContextIndex);
+ htonlDisconnectStruct(diStr);
+ *replySize = sizeof(disconnect_struct);
+ break;
+
+ case SCARD_BEGIN_TRANSACTION:
+ {
+ beStr = ((begin_struct *) msgStruct->data);
+ int ix;
+ unsigned char *px = &msgStruct->data[sizeof(begin_struct)];
+ for (ix = 0; ix < 32; ++ix)
+ *px++ = 0xEE;
+ beStr->rv = -99; // test
+ ntohlBeginStruct(beStr);
+ rv = MSGCheckHandleAssociation(beStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ beStr->rv = SCardBeginTransaction(beStr->hCard);
+ htonlBeginStruct(beStr);
+ }
+ *replySize = sizeof(begin_struct);
+ break;
+
+ case SCARD_END_TRANSACTION:
+ enStr = ((end_struct *) msgStruct->data);
+ ntohlEndStruct(enStr);
+ rv = MSGCheckHandleAssociation(enStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ enStr->rv =
+ SCardEndTransaction(enStr->hCard, enStr->dwDisposition);
+ htonlEndStruct(enStr);
+ *replySize = sizeof(end_struct);
+ break;
+
+ case SCARD_CANCEL_TRANSACTION:
+ caStr = ((cancel_struct *) msgStruct->data);
+ ntohlCancelStruct(caStr);
+ rv = MSGCheckHandleAssociation(caStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ caStr->rv = SCardCancelTransaction(caStr->hCard);
+ htonlCancelStruct(caStr);
+ *replySize = sizeof(cancel_struct);
+ break;
+
+ case SCARD_STATUS:
+ stStr = ((status_struct *) msgStruct->data);
+ ntohlStatusStruct(stStr);
+ rv = MSGCheckHandleAssociation(stStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ stStr->rv = SCardStatus(stStr->hCard, stStr->mszReaderNames,
+ &stStr->pcchReaderLen, &stStr->pdwState,
+ &stStr->pdwProtocol, stStr->pbAtr, &stStr->pcbAtrLen);
+ htonlStatusStruct(stStr);
+ *replySize = sizeof(status_struct);
+ break;
+
+ case SCARD_TRANSMIT:
+ trStr = ((transmit_struct *) msgStruct->data);
+ ntohlTransmitStruct(trStr);
+ Log2(PCSC_LOG_DEBUG, "SCardTransmit cbSendLength: %d", trStr->cbSendLength);
+ rv = MSGCheckHandleAssociation(trStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+
+ {
+ SCARD_IO_REQUEST ioSendPci;
+ SCARD_IO_REQUEST ioRecvPci;
+ // ioSendPci is only an input parameter
+ ioSendPci.dwProtocol = trStr->pioSendPciProtocol;
+ ioSendPci.cbPciLength = trStr->pioSendPciLength;
+
+ trStr->rv = SCardTransmit(trStr->hCard, &ioSendPci,
+ trStr->pbSendBuffer, trStr->cbSendLength,
+ &ioRecvPci, trStr->pbRecvBuffer,
+ &trStr->pcbRecvLength);
+
+ // ioRecvPci is only an output parameter
+ trStr->pioRecvPciProtocol = ioRecvPci.dwProtocol;
+ trStr->pioRecvPciLength = ioRecvPci.cbPciLength;
+ }
+ Log2(PCSC_LOG_DEBUG, "SCardTransmit pcbRecvLength: %d", trStr->pcbRecvLength);
+ htonlTransmitStruct(trStr);
+ *replySize = sizeof(transmit_struct);
+ break;
+
+ case SCARD_CONTROL:
+ ctStr = ((control_struct *) msgStruct->data);
+ ntohlControlStruct(ctStr);
+ rv = MSGCheckHandleAssociation(ctStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ ctStr->rv = SCardControl(ctStr->hCard, ctStr->dwControlCode,
+ ctStr->pbSendBuffer, ctStr->cbSendLength,
+ ctStr->pbRecvBuffer, ctStr->cbRecvLength,
+ &ctStr->dwBytesReturned);
+ htonlControlStruct(ctStr);
+ *replySize = sizeof(control_struct);
+ break;
+
+ case SCARD_GET_ATTRIB:
+ gsStr = ((getset_struct *) msgStruct->data);
+ ntohlGetSetStruct(gsStr);
+ rv = MSGCheckHandleAssociation(gsStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ gsStr->rv = SCardGetAttrib(gsStr->hCard, gsStr->dwAttrId,
+ gsStr->pbAttr, &gsStr->cbAttrLen);
+ htonlGetSetStruct(gsStr);
+ *replySize = sizeof(getset_struct);
+ break;
+
+ case SCARD_SET_ATTRIB:
+ gsStr = ((getset_struct *) msgStruct->data);
+ ntohlGetSetStruct(gsStr);
+ rv = MSGCheckHandleAssociation(gsStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+ gsStr->rv = SCardSetAttrib(gsStr->hCard, gsStr->dwAttrId,
+ gsStr->pbAttr, gsStr->cbAttrLen);
+ htonlGetSetStruct(gsStr);
+ *replySize = sizeof(getset_struct);
+ break;
+
+ case SCARD_TRANSMIT_EXTENDED:
+ {
+ transmit_struct_extended *treStr;
+ unsigned char pbSendBuffer[MAX_BUFFER_SIZE_EXTENDED];
+ unsigned char pbRecvBuffer[MAX_BUFFER_SIZE_EXTENDED];
+
+ treStr = ((transmit_struct_extended *) msgStruct->data);
+ ntohlTransmitStructExtended(treStr);
+ Log2(PCSC_LOG_DEBUG, "SCardTransmitExt cbSendLength: %d", treStr->cbSendLength);
+ rv = MSGCheckHandleAssociation(treStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+
+ /* one more block to read? */
+ if (treStr->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ /* copy the first APDU part */
+ memcpy(pbSendBuffer, treStr->data,
+ PCSCLITE_MAX_MESSAGE_SIZE-sizeof(*treStr));
+
+ /* receive the second block */
+ rv = SHMMessageReceive(
+ pbSendBuffer+PCSCLITE_MAX_MESSAGE_SIZE-sizeof(*treStr),
+ treStr->size - PCSCLITE_MAX_MESSAGE_SIZE,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "reception failed");
+ }
+ else
+ memcpy(pbSendBuffer, treStr->data, treStr->cbSendLength);
+
+ {
+ SCARD_IO_REQUEST ioSendPci;
+ SCARD_IO_REQUEST ioRecvPci;
+ // ioSendPci is only an input parameter
+ ioSendPci.dwProtocol = treStr->pioSendPciProtocol;
+ ioSendPci.cbPciLength = treStr->pioSendPciLength;
+
+ treStr->rv = SCardTransmit(treStr->hCard, &ioSendPci,
+ pbSendBuffer, treStr->cbSendLength,
+ &ioRecvPci, pbRecvBuffer,
+ &treStr->pcbRecvLength);
+
+ // ioRecvPci is only an output parameter
+ treStr->pioRecvPciProtocol = ioRecvPci.dwProtocol;
+ treStr->pioRecvPciLength = ioRecvPci.cbPciLength;
+ }
+
+ treStr->size = sizeof(*treStr) + treStr->pcbRecvLength;
+ Log3(PCSC_LOG_DEBUG, "SCardTransmitExt pcbRecvLength: %d, size: %d",
+ treStr->pcbRecvLength, treStr->size);
+ Log3(PCSC_LOG_DEBUG, "SCardTransmitExt SCardTransmit result: %d [0x%08X]",
+ treStr->rv, treStr->rv);
+ if (treStr->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ /* two blocks */
+ memcpy(treStr->data, pbRecvBuffer, PCSCLITE_MAX_MESSAGE_SIZE
+ - sizeof(*treStr));
+
+ // sharedSegmentMsg tmpMsgStruct = *msgStruct;
+ // we don't copy because of the size, and because it is not used after here
+ // SHSharedSegmentMsgToNetworkOrder(&tmpMsgStruct);
+ SHSharedSegmentMsgToNetworkOrder(msgStruct);
+ htonlTransmitStructExtended(treStr);
+ rv = SHMMessageSend(msgStruct, sizeof(*msgStruct),
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+
+ rv = SHMMessageSend(pbRecvBuffer + PCSCLITE_MAX_MESSAGE_SIZE
+ - sizeof(*treStr),
+ treStr->size - PCSCLITE_MAX_MESSAGE_SIZE,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+ }
+ else
+ {
+ /* one block only */
+ size_t dataSize = treStr->pcbRecvLength;
+ memcpy(treStr->data, pbRecvBuffer, dataSize);
+
+ // the 4 is to drop the "BYTE data[1]", which rounds to 4 bytes
+ size_t replySize = dataSize + sizeof(transmit_struct_extended) - 4;
+ Log3(PCSC_LOG_DEBUG, "SCardTransmitExt/SHMMessageSend one block: data: %d, total: %d",
+ dataSize, replySize);
+ htonlTransmitStructExtended(treStr);
+ rv = WrapSHMWrite(SCARD_TRANSMIT_EXTENDED, psContext[dwContextIndex].dwClientID,
+ replySize, SHMCommunicationTimeout(), treStr);
+
+#if 0
+ // the 4 is to drop the "BYTE data[1]", which rounds to 4 bytes
+ size_t replySize = sizeof(sharedSegmentMsg) - sizeof(msgStruct->data) + // header portion of msgStruct
+ dataSize + sizeof(transmit_struct_extended) - 4;
+
+ Log3(PCSC_LOG_DEBUG, "SCardTransmitExt/SHMMessageSend one block: data: %d, total: %d",
+ dataSize, replySize);
+ // we don't copy because of the potential size
+ SHSharedSegmentMsgToNetworkOrder(msgStruct);
+ htonlTransmitStructExtended(treStr);
+ rv = SHMMessageSend(msgStruct, replySize,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+#endif
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+ // We flip back the header, since the SHMProcessEventsContext loop
+ // tests msgStruct.command after MSGFunctionDemarshall is called
+#if 0
+ SHSharedSegmentMsgToHostOrder(msgStruct);
+#endif
+ }
+ }
+ break;
+
+ case SCARD_CONTROL_EXTENDED:
+ {
+ control_struct_extended *cteStr;
+ unsigned char pbSendBuffer[MAX_BUFFER_SIZE_EXTENDED];
+ unsigned char pbRecvBuffer[MAX_BUFFER_SIZE_EXTENDED];
+
+ cteStr = ((control_struct_extended *) msgStruct->data);
+ ntohlControlStructExtended(cteStr);
+ Log2(PCSC_LOG_DEBUG, "SCardControlExt cbSendLength: %d", cteStr->cbSendLength);
+ rv = MSGCheckHandleAssociation(cteStr->hCard, dwContextIndex);
+ if (rv != 0) return rv;
+
+ /* one more block to read? */
+ if (cteStr->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ /* copy the first data part */
+ memcpy(pbSendBuffer, cteStr->data,
+ PCSCLITE_MAX_MESSAGE_SIZE-sizeof(*cteStr));
+
+ /* receive the second block */
+ rv = SHMMessageReceive(
+ pbSendBuffer+PCSCLITE_MAX_MESSAGE_SIZE-sizeof(*cteStr),
+ cteStr->size - PCSCLITE_MAX_MESSAGE_SIZE,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "reception failed");
+ }
+ else
+ memcpy(pbSendBuffer, cteStr->data, cteStr->cbSendLength);
+
+ cteStr->rv = SCardControl(cteStr->hCard, cteStr->dwControlCode,
+ pbSendBuffer, cteStr->cbSendLength,
+ pbRecvBuffer, cteStr->cbRecvLength,
+ &cteStr->pdwBytesReturned);
+
+ cteStr->size = sizeof(*cteStr) + cteStr->pdwBytesReturned;
+ Log3(PCSC_LOG_DEBUG, "SCardControlExt pdwBytesReturned: %d, size: %d",
+ cteStr->pdwBytesReturned, cteStr->size);
+ if (cteStr->size > PCSCLITE_MAX_MESSAGE_SIZE)
+ {
+ /* two blocks */
+ memcpy(cteStr->data, pbRecvBuffer, PCSCLITE_MAX_MESSAGE_SIZE
+ - sizeof(*cteStr));
+
+ sharedSegmentMsg tmpMsgStruct = *msgStruct;
+ SHSharedSegmentMsgToNetworkOrder(&tmpMsgStruct);
+ htonlControlStructExtended(cteStr);
+ rv = SHMMessageSend(&tmpMsgStruct, sizeof(tmpMsgStruct),
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+
+ rv = SHMMessageSend(pbRecvBuffer + PCSCLITE_MAX_MESSAGE_SIZE
+ - sizeof(*cteStr),
+ cteStr->size - PCSCLITE_MAX_MESSAGE_SIZE,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+ }
+ else
+ {
+ /* one block only */
+ size_t dataSize = cteStr->pdwBytesReturned;
+ memcpy(cteStr->data, pbRecvBuffer, dataSize);
+ dataSize = dataSize + sizeof(*cteStr) - sizeof(cteStr->data);
+
+ sharedSegmentMsg tmpMsgStruct = *msgStruct;
+ dataSize = SHMCalculateMessageSize(dataSize);
+ tmpMsgStruct.msgSize = dataSize;
+ SHSharedSegmentMsgToNetworkOrder(&tmpMsgStruct);
+ cteStr = ((control_struct_extended *) tmpMsgStruct.data);
+ htonlControlStructExtended(cteStr);
+ rv = SHMMessageSend(&tmpMsgStruct, dataSize,
+ psContext[dwContextIndex].dwClientID,
+ SHMCommunicationTimeout());
+ if (rv)
+ Log1(PCSC_LOG_CRITICAL, "transmission failed");
+ }
+ }
+ break;
+
+ default:
+ Log2(PCSC_LOG_CRITICAL, "Unknown command: %d", msgStruct->command);
+ return -1;
+ }
+
+ return 0;
+}
+
+LONG MSGAddContext(SCARDCONTEXT hContext, DWORD dwContextIndex)
+{
+ psContext[dwContextIndex].hContext = hContext;
+ return SCARD_S_SUCCESS;
+}
+
+LONG MSGRemoveContext(SCARDCONTEXT hContext, DWORD dwContextIndex)
+{
+ int i;
+ LONG rv;
+
+ if (psContext[dwContextIndex].hContext == hContext)
+ {
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ /*
+ * Disconnect each of these just in case
+ */
+
+ if (psContext[dwContextIndex].hCard[i] != 0)
+ {
+ PREADER_CONTEXT rContext = NULL;
+ DWORD dwLockId;
+
+ /*
+ * Unlock the sharing
+ */
+ rv = RFReaderInfoById(psContext[dwContextIndex].hCard[i],
+ &rContext);
+ if (rv != SCARD_S_SUCCESS)
+ return rv;
+
+ dwLockId = rContext->dwLockId;
+ rContext->dwLockId = 0;
+
+ if (psContext[dwContextIndex].hCard[i] != dwLockId)
+ {
+ /*
+ * if the card is locked by someone else we do not reset it
+ * and simulate a card removal
+ */
+ rv = SCARD_W_REMOVED_CARD;
+ }
+ else
+ {
+ /*
+ * We will use SCardStatus to see if the card has been
+ * reset there is no need to reset each time
+ * Disconnect is called
+ */
+ rv = SCardStatus(psContext[dwContextIndex].hCard[i], NULL,
+ NULL, NULL, NULL, NULL, NULL);
+ }
+
+ if (rv == SCARD_W_RESET_CARD || rv == SCARD_W_REMOVED_CARD)
+ SCardDisconnect(psContext[dwContextIndex].hCard[i],
+ SCARD_LEAVE_CARD);
+ else
+ SCardDisconnect(psContext[dwContextIndex].hCard[i],
+ SCARD_RESET_CARD);
+
+ psContext[dwContextIndex].hCard[i] = 0;
+ }
+ }
+
+ psContext[dwContextIndex].hContext = 0;
+ return SCARD_S_SUCCESS;
+ }
+
+ return SCARD_E_INVALID_VALUE;
+}
+
+LONG MSGAddHandle(SCARDCONTEXT hContext, SCARDHANDLE hCard, DWORD dwContextIndex)
+{
+ int i;
+
+ if (psContext[dwContextIndex].hContext == hContext)
+ {
+
+ /*
+ * Find an empty spot to put the hCard value
+ */
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ if (psContext[dwContextIndex].hCard[i] == 0)
+ {
+ psContext[dwContextIndex].hCard[i] = hCard;
+ break;
+ }
+ }
+
+ if (i == PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS)
+ {
+ return SCARD_F_INTERNAL_ERROR;
+ } else
+ {
+ return SCARD_S_SUCCESS;
+ }
+
+ }
+
+ return SCARD_E_INVALID_VALUE;
+}
+
+LONG MSGRemoveHandle(SCARDHANDLE hCard, DWORD dwContextIndex)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ if (psContext[dwContextIndex].hCard[i] == hCard)
+ {
+ psContext[dwContextIndex].hCard[i] = 0;
+ return SCARD_S_SUCCESS;
+ }
+ }
+
+ return SCARD_E_INVALID_VALUE;
+}
+
+
+LONG MSGCheckHandleAssociation(SCARDHANDLE hCard, DWORD dwContextIndex)
+{
+ int i;
+
+ for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
+ {
+ if (psContext[dwContextIndex].hCard[i] == hCard)
+ {
+ return 0;
+ }
+ }
+
+ /* Must be a rogue client, debug log and sleep a couple of seconds */
+ Log2(PCSC_LOG_ERROR, "Client failed to authenticate (hCard: 0x%08X)", hCard);
+ SYS_Sleep(2);
+
+ return SCARD_E_INVALID_HANDLE;
+}
+
+LONG MSGCleanupClient(DWORD dwContextIndex)
+{
+ if (psContext[dwContextIndex].hContext != 0)
+ {
+ SCardReleaseContext(psContext[dwContextIndex].hContext);
+ MSGRemoveContext(psContext[dwContextIndex].hContext, dwContextIndex);
+ }
+
+ psContext[dwContextIndex].dwClientID = 0;
+ psContext[dwContextIndex].protocol_major = 0;
+ psContext[dwContextIndex].protocol_minor = 0;
+
+ return 0;
+}
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/winscard_svc.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2000-2007 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * winscard_svc.h
+ * SmartCardServices
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 2001-2004
+ * David Corcoran <corcoran at linuxnet.com>
+ * Damien Sauveron <damien.sauveron at labri.fr>
+ *
+ * $Id: winscard_svc.h 1421 2005-04-12 12:09:21Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This demarshalls functions over the message queue and
+ * keeps track of clients and their handles.
+ */
+
+#ifndef __winscard_svc_h__
+#define __winscard_svc_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+ LONG ContextsInitialize(void);
+ LONG CreateContextThread(PDWORD);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/wintypes.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/wintypes.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/wintypes.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+/*
+ * MUSCLE SmartCard Development ( http://www.linuxnet.com )
+ *
+ * Copyright (C) 1999
+ * David Corcoran <corcoran at linuxnet.com>
+ *
+ * $Id: wintypes.h 2071 2006-06-06 09:20:19Z rousseau $
+ */
+
+/**
+ * @file
+ * @brief This keeps a list of Windows(R) types.
+ */
+
+#ifndef __wintypes_h__
+#define __wintypes_h__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if !defined(WIN32)
+
+#include <stdint.h>
+
+#ifndef BYTE
+ typedef uint8_t BYTE;
+#endif
+ typedef uint8_t UCHAR;
+ typedef uint8_t *PUCHAR;
+ typedef uint16_t USHORT;
+
+#ifndef __COREFOUNDATION_CFPLUGINCOM__
+ typedef uint32_t ULONG;
+ typedef void *LPVOID;
+ typedef int16_t BOOL;
+#endif
+
+ typedef uint32_t *PULONG;
+ typedef const void *LPCVOID;
+ typedef uint32_t DWORD;
+ typedef uint32_t *PDWORD;
+ typedef uint16_t WORD;
+ typedef int32_t LONG;
+ typedef int32_t RESPONSECODE;
+ typedef const char *LPCSTR;
+ typedef const BYTE *LPCBYTE;
+ typedef BYTE *LPBYTE;
+ typedef DWORD *LPDWORD;
+ typedef char *LPSTR;
+
+ /* these types are deprecated but still used by old drivers and applications
+ * You should use LPSTR instead */
+ typedef char *LPTSTR
+#ifdef __GNUC__
+ /* __attribute__ is a GCC only extension */
+ __attribute__ ((deprecated))
+#endif
+ ;
+ typedef const char *LPCTSTR
+#ifdef __GNUC__
+ /* __attribute__ is a GCC only extension */
+ __attribute__ ((deprecated))
+#endif
+ ;
+ typedef char *LPCWSTR
+#ifdef __GNUC__
+ /* __attribute__ is a GCC only extension */
+ __attribute__ ((deprecated))
+#endif
+ ;
+
+#else
+#include <windows.h>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.cpp
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.cpp (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.cpp 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+//
+// xiodevices - additional code for finding and tracking devices via IOKit
+// >>> move this iodevices.cpp when final
+//
+#include "xiodevices.h"
+#include <security_utilities/cfutilities.h>
+#include <security_utilities/mach++.h>
+#include <IOKit/IOMessage.h>
+#include <IOKit/usb/IOUSBLib.h>
+
+using namespace MachPlusPlus;
+
+namespace Security {
+namespace IOKit {
+
+void XNotificationPort::add(DeviceMatch match, XReceiver &receiver, const char *type)
+{
+ // The kIOProviderClassKey key is required in a matching dictionary. We extract it
+ // here only for debugging purposes
+
+ CFTypeRef valueRef = NULL;
+ const char *pclass = "";
+ CFRef<CFMutableDictionaryRef> theDict = match.dict();
+ if (theDict && CFDictionaryGetValueIfPresent(theDict, CFSTR(kIOProviderClassKey), &valueRef) &&
+ CFGetTypeID(valueRef) == CFStringGetTypeID())
+ pclass = cfString(static_cast<CFStringRef>(valueRef)).c_str();
+
+ // type is usually IOServiceMatched
+ mach_port_t pp = NotificationPort::port();
+ secdebug("iokit", "XNotificationPort::add - type: %s [port: %p (0x%08X), class: %s]",
+ type, mPortRef, pp, pclass);
+
+// CFShow(match.dict());
+ // p (void)CFShow(match.dict())
+ io_iterator_t iterator;
+ Error::check(::IOServiceAddMatchingNotification(mPortRef, type,
+ match, ioNotify, &receiver, &iterator));
+ CFRetain(match); // compensate for IOSAMN not retaining its argument
+
+ // run initial iterator to process existing devices
+ secdebug("iokit", "dispatching INITIAL device match iterator %p", reinterpret_cast<void *>(iterator));
+ DeviceIterator it(iterator);
+ receiver.ioChange(it);
+}
+
+void XNotificationPort::addInterestNotification(XReceiver &receiver, io_service_t service,
+ const io_name_t interestType)
+{
+ io_iterator_t iterator;
+ mach_port_t pp = NotificationPort::port();
+// MachPlusPlus::Port(pp).dump(0);
+ secdebug("iokit", "XNotificationPort::addInterest - type: %s [port: %p (0x%08X), service: 0x%08X]",
+ interestType, mPortRef, pp, service); // IOServiceMatched
+#if 1
+ CFRunLoopSourceRef notificationRunLoopSource = IONotificationPortGetRunLoopSource(mPortRef);
+ CFRunLoopSourceRef classRunLoopSource = NotificationPort::source();
+// IONotificationPortRef r_notify_port = IONotificationPortCreate(0);
+ kern_return_t kr = ::IOServiceAddInterestNotification(mPortRef, //,r_notify_port
+ service, interestType, ioDeviceNotification, &receiver, &iterator);
+ const char *msgstr = mach_error_string(kr);
+ const char *msgtyp = mach_error_type(kr);
+ if (msgstr && msgtyp)
+ secdebug("iokit", " msg: %s, typ: %s", msgstr, msgtyp);
+// Error::check(kr);
+// if(r_notify_port) IOObjectRelease((io_object_t)r_notify_port);
+#else
+ Error::check(::IOServiceAddInterestNotification(mPortRef,
+ service, interestType, ioDeviceNotification, &receiver, &iterator));
+#endif
+}
+
+// callbacks
+
+void XNotificationPort::ioNotify(void *refCon, io_iterator_t iterator)
+{
+ secdebug("iokit", "dispatching NEW device match iterator %p", reinterpret_cast<void *>(iterator));
+ DeviceIterator it(iterator);
+ reinterpret_cast<XReceiver *>(refCon)->ioChange(it);
+}
+
+void XNotificationPort::ioDeviceNotification(void *refCon, io_service_t service,
+ natural_t messageType, void *messageArgument)
+{
+ secdebug("iokit", "dispatching NEW device notification iterator, service 0x%08X, msg: 0x%04X, arg: %p",
+ service, messageType, messageArgument);
+
+ const char *msgstr = mach_error_string(messageType);
+ const char *msgtyp = mach_error_type(messageType);
+ if (msgstr && msgtyp)
+ secdebug("iokit", " msg: %s, typ: %s", msgstr, msgtyp);
+
+#if 0
+ secdebug("iokit", "kIOMessageServiceIsTerminated: 0x%04X", kIOMessageServiceIsTerminated);
+ secdebug("iokit", "kIOMessageServiceIsSuspended: 0x%04X", kIOMessageServiceIsSuspended);
+ secdebug("iokit", "kIOMessageServiceIsResumed: 0x%04X", kIOMessageServiceIsResumed);
+ secdebug("iokit", "kIOMessageServiceIsRequestingClose: 0x%04X", kIOMessageServiceIsRequestingClose);
+ secdebug("iokit", "kIOMessageServiceIsAttemptingOpen: 0x%04X", kIOMessageServiceIsAttemptingOpen);
+ secdebug("iokit", "kIOMessageServiceWasClosed: 0x%04X", kIOMessageServiceWasClosed);
+ secdebug("iokit", "kIOMessageServiceBusyStateChange: 0x%04X", kIOMessageServiceBusyStateChange);
+ secdebug("iokit", "kIOMessageServicePropertyChange: 0x%04X", kIOMessageServicePropertyChange);
+ secdebug("iokit", "kIOMessageCanDevicePowerOff: 0x%04X", kIOMessageCanDevicePowerOff);
+ secdebug("iokit", "kIOMessageDeviceWillPowerOff: 0x%04X", kIOMessageDeviceWillPowerOff);
+ secdebug("iokit", "kIOMessageDeviceWillNotPowerOff: 0x%04X", kIOMessageDeviceWillNotPowerOff);
+ secdebug("iokit", "kIOMessageDeviceHasPoweredOn: 0x%04X", kIOMessageDeviceHasPoweredOn);
+ secdebug("iokit", "kIOMessageCanSystemPowerOff: 0x%04X", kIOMessageCanSystemPowerOff);
+ secdebug("iokit", "iokit_vendor_specific_msg(0x000A): 0x%04X", iokit_vendor_specific_msg(0x000A));
+#endif
+
+// assert(service!=io_service_t(-1));
+ if (service!=io_service_t(-1))
+ reinterpret_cast<XReceiver *>(refCon)->ioServiceChange(refCon, service, messageType, messageArgument);
+}
+
+
+} // end namespace IOKit
+} // end namespace Security
+
+
Added: releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.h
===================================================================
--- releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.h (rev 0)
+++ releases/Apple/Mac OS X 10.6.0/SmartCardServices-36160/src/PCSC/xiodevices.h 2009-09-07 21:57:09 UTC (rev 65)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+//
+// xiodevices - code for finding and tracking devices via IOKit
+//
+#ifndef _H_XIODEVICES
+#define _H_XIODEVICES
+
+#include <security_utilities/iodevices.h>
+
+#if defined(__cplusplus)
+
+namespace Security {
+namespace IOKit {
+
+//
+// An IOKit notification port object
+//
+class XNotificationPort : public MachPortNotificationPort
+{
+public:
+ XNotificationPort() : MachPortNotificationPort() {}
+ ~XNotificationPort() {}
+
+ class XReceiver : public Receiver
+ {
+ public:
+ virtual void ioChange(DeviceIterator &iterator) = 0;
+ virtual void ioServiceChange(void *refCon, io_service_t service, //IOServiceInterestCallback
+ natural_t messageType, void *messageArgument) = 0;
+ };
+
+ void add(DeviceMatch match, XReceiver &receiver, const char *type = kIOFirstMatchNotification);
+ void addInterestNotification(XReceiver &receiver, io_service_t service,
+ const io_name_t interestType = kIOGeneralInterest);
+
+private:
+
+ static void ioDeviceNotification(void *refCon, io_service_t service,
+ natural_t messageType, void *messageArgument);
+ static void ioNotify(void *refCon, io_iterator_t iterator);
+};
+
+} // end namespace MachPlusPlus
+} // end namespace Security
+
+#endif /* __cplusplus__ */
+
+#endif //_H_XIODEVICES
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/smartcardservices-changes/attachments/20090907/22efdecb/attachment-0001.html>
More information about the SmartcardServices-Changes
mailing list