libgcr410-2.4.0.orig/0040755000175000017500000000000007355062670011605 5ustar p2p2libgcr410-2.4.0.orig/apdubuil.c0100644000175000017500000002447707354047734013574 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : ApduBuil.c * * Description : Module which builds APDU commands according to the 7816-4 * standard 1995. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ #define G_NAME "ApduBuil" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #include "gemgcr.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "apdubuil.h" /*------------------------------------------------------------------------------ Constant section - Length of different APDU cases, without data field. * CASE_1_LEN 4lu * CASE_2S_LEN 5lu * CASE_2E_LEN 7lu * CASE_3S_LEN 5lu * CASE_3E_LEN 7lu * CASE_4S_LEN 6lu * CASE_4E_LEN 9lu ------------------------------------------------------------------------------*/ #define CASE_1_LEN 4lu #define CASE_2S_LEN 5lu #define CASE_2E_LEN 7lu #define CASE_3S_LEN 5lu #define CASE_3E_LEN 7lu #define CASE_4S_LEN 6lu #define CASE_4E_LEN 9lu /*------------------------------------------------------------------------------ - EXTEND_FLAG is a flag used in extended cases. ------------------------------------------------------------------------------*/ #define EXTEND_FLAG 0 INT16 G_DECL ApduBuilder (const G4_APDU_COMM G_FAR * ApduComm, WORD8 G_HUGE * Buffer, WORD32 G_FAR * Length) { /*------------------------------------------------------------------------------ Local variables: - ptr is a huge pointer used to avoid wraparound. ------------------------------------------------------------------------------*/ WORD8 G_HUGE *ptr; /*------------------------------------------------------------------------------ The command bytes are copied in the given buffer. <= Test available space (>= COMMAND_LEN): GE_HI_CMD_LEN The command byte are copied. ------------------------------------------------------------------------------*/ if (*Length < COMMAND_LEN) { return (GE_HI_CMD_LEN); } _fmemcpy(Buffer, ApduComm->Command, COMMAND_LEN); /*------------------------------------------------------------------------------ APDU cases are decoded and the buffer is filled according to the recognized case. If no data are sent Then If no data are awaited Then APDU case 1 is recognized: <= Test available space (>= CASE_1_LEN): GE_HI_CMD_LEN Updates the Length parameter. ------------------------------------------------------------------------------*/ if (ApduComm->LengthIn == 0) { if (ApduComm->LengthExpected == 0) { if (*Length < CASE_1_LEN) { return (GE_HI_CMD_LEN); } *Length = CASE_1_LEN; } /*------------------------------------------------------------------------------ Else If the data awaited length is lower or equal to 256 Then APDU case 3S is recognized: <= Test available space (>= CASE_3S_LEN): GE_HI_CMD_LEN Adds the awaited length low byte (0 if val = 256, val if val<256) and updates the Length parameters. ------------------------------------------------------------------------------*/ else { if (ApduComm->LengthExpected <= 256) { if (*Length < CASE_3S_LEN) { return (GE_HI_CMD_LEN); } *(Buffer + COMMAND_LEN) = LOBYTE(ApduComm->LengthExpected); *Length = CASE_3S_LEN; } /*------------------------------------------------------------------------------ Else APDU case 3E is recognized: <= Test available space (>= CASE_3E_LEN): GE_HI_CMD_LEN <= Test the awaited data size (<= 65536): GE_APDU_LE Adds the extended flag and Adds the awaited length low word (0 if val=65536, val if val<65536) and updates the Length parameters. ------------------------------------------------------------------------------*/ else { if (*Length < CASE_3E_LEN) { return (GE_HI_CMD_LEN); } if (ApduComm->LengthExpected > 65536L) { return (GE_APDU_LE); } *(Buffer + COMMAND_LEN) = EXTEND_FLAG; *(Buffer + COMMAND_LEN + 1) = HIBYTE(ApduComm->LengthExpected); *(Buffer + COMMAND_LEN + 2) = LOBYTE(ApduComm->LengthExpected); *Length = CASE_3E_LEN; } } } /*------------------------------------------------------------------------------ Else If no data are awaited Then If sending data length is lower than 256 Then APDU case 2S is recognized: <= Test available space (>= CASE_2S_LEN + sending data length): GE_HI_CMD_LEN Adds the sending data length low byte (<256), adds the data and updates the Length parameter. ------------------------------------------------------------------------------*/ else { if (ApduComm->LengthExpected == 0) { if (ApduComm->LengthIn < 256) { if (*Length < CASE_2S_LEN + ApduComm->LengthIn) { return (GE_HI_CMD_LEN); } *(Buffer + COMMAND_LEN) = LOBYTE(ApduComm->LengthIn); ptr = Buffer + CASE_2S_LEN; _fmemcpy(ptr, ApduComm->DataIn, ApduComm->LengthIn); *Length = CASE_2S_LEN + ApduComm->LengthIn; } /*------------------------------------------------------------------------------ Else APDU case 2E is recognized: <= Test available space (>= CASE_2E_LEN + sending data length): GE_HI_CMD_LEN <= Test sending data length (< 65536): GE_APDU_LE Adds the extend flag, adds the sending data length low WORD (<65536), adds the data and updates the Length parameter. ------------------------------------------------------------------------------*/ else { if (*Length < CASE_2E_LEN + ApduComm->LengthIn) { return (GE_HI_CMD_LEN); } if (ApduComm->LengthIn > 65535L) { return (GE_APDU_LE); } *(Buffer + COMMAND_LEN) = EXTEND_FLAG; *(Buffer + COMMAND_LEN + 1) = HIBYTE(ApduComm->LengthIn); *(Buffer + COMMAND_LEN + 2) = LOBYTE(ApduComm->LengthIn); ptr = Buffer + CASE_2E_LEN; _fmemcpy(ptr, ApduComm->DataIn, ApduComm->LengthIn); *Length = CASE_2E_LEN + ApduComm->LengthIn; } } /*------------------------------------------------------------------------------ Else If sending data length is lower than 256 and awaited data length is lower or equal to 256 Then APDU case 4S is recognized: <= Test available space (>= CASE_4S_LEN + sending data length): GE_HI_CMD_LEN Adds the sending data length low byte (<256), adds the data, adds the awaited length low byte (0 if val = 256, val is val < 256) and updates the Length parameter. ------------------------------------------------------------------------------*/ else { if ((ApduComm->LengthIn < 256) && (ApduComm->LengthExpected <= 256)) { if (*Length < CASE_4S_LEN + ApduComm->LengthIn) { return (GE_HI_CMD_LEN); } *(Buffer + COMMAND_LEN) = LOBYTE(ApduComm->LengthIn); ptr = Buffer + COMMAND_LEN + 1; _fmemcpy(ptr, ApduComm->DataIn, ApduComm->LengthIn); ptr += ApduComm->LengthIn; *ptr = LOBYTE(ApduComm->LengthExpected); *Length = CASE_4S_LEN + ApduComm->LengthIn; } /*------------------------------------------------------------------------------ Else APDU case 4E is recognized: <= Test available space (>= CASE_4E_LEN + sending data length): GE_HI_CMD_LEN <= Test the awaited length (<= 65536): GE_APDU_LE Adds the extend flag, adds the sending data length low word (<65535), adds the data, adds the awaited length low word (0 if val=65536, val is val < 65536) and updates the Length parameter. ------------------------------------------------------------------------------*/ else { if ((ApduComm->LengthIn > 0xFFFFFFFFL - CASE_4E_LEN) || (*Length < CASE_4E_LEN + ApduComm->LengthIn)) { return (GE_HI_CMD_LEN); } if (ApduComm->LengthExpected > 65536L) { return (GE_APDU_LE); } *(Buffer + COMMAND_LEN) = EXTEND_FLAG; *(Buffer + COMMAND_LEN + 1) = HIBYTE(ApduComm->LengthIn); *(Buffer + COMMAND_LEN + 2) = LOBYTE(ApduComm->LengthIn); ptr = Buffer + COMMAND_LEN + 3; _fmemcpy(ptr, ApduComm->DataIn, ApduComm->LengthIn); ptr += ApduComm->LengthIn; *ptr++ = HIBYTE(ApduComm->LengthExpected); *ptr = LOBYTE(ApduComm->LengthExpected); *Length = CASE_4E_LEN + ApduComm->LengthIn; } } } /*------------------------------------------------------------------------------ <= G_OK. ------------------------------------------------------------------------------*/ return (G_OK); } libgcr410-2.4.0.orig/apdubuil.h0100644000175000017500000000403007354047734013560 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : ApduBuil.h * * Description : Module which builds APDU commands according to the 7816-4 * standard 1995(E). * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _APDUBUIL_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _APDUBUIL_H #define _APDUBUIL_H /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototype section ------------------------------------------------------------------------------*/ INT16 G_DECL ApduBuilder ( const G4_APDU_COMM G_FAR * ApduComm, WORD8 G_HUGE * Buffer, WORD32 G_FAR * Length); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/apduspli.c0100644000175000017500000000772207354047734013602 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : ApduSpli.c * * Description : Module which splits APDU commands for T=0 protocole. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : The 7616-4 standard indicates that only the transmission system * can initiate GET_RESPONSE and ENVELOPE command. This two * commands cannot be transmitted by this module. * * Remark : The true cases 2E and 4E.2 are not supported because the command * ENVELOPE is not supported by this module. * *******************************************************************************/ #define G_NAME "ApduSpli" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "gemgcr.h" #include "t0cases.h" #include "apduspli.h" INT16 G_DECL ApduSpliter (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]), INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { // 2001 Modif-- // printf("ApduSpliter\n") ; // --2001 Modif if (ApduComm->LengthExpected == 0) { if (ApduComm->LengthIn == 0) { // 2001 Modif-- // printf("Case 0\n") ; // --2001 Modif return (G_T0Case1(Timeout, ApduComm, ApduResp, IsoIn)); } else if (ApduComm->LengthIn <= HT0CASES_LIN_SHORT_MAX) { // 2001 Modif-- // printf("Case 2S\n") ; // --2001 Modif return (G_T0Case2S(Timeout, ApduComm, ApduResp, IsoIn)); } ApduResp->LengthOut = 0; ApduResp->Status = HT0CASES_WRONG_LENGTH; return (G_OK); } else if (ApduComm->LengthIn == 0) { if (ApduComm->LengthExpected <= HT0CASES_LEX_SHORT_MAX) { // 2001 Modif-- // printf("Case 3S\n") ; // --2001 Modif return (G_T0Case3S(Timeout, ApduComm, ApduResp, IsoOut)); } else { return (G_T0Case3E(Timeout, ApduComm, ApduResp, IsoOut)); } } else if ((ApduComm->LengthIn <= HT0CASES_LIN_SHORT_MAX) && (ApduComm->LengthExpected <= HT0CASES_LEX_SHORT_MAX)) { // 2001 Modif-- // printf("T=0 Case 4S\n") ; // --2001 Modif return (G_T0Case4S(Timeout, ApduComm, ApduResp, IsoIn, IsoOut)); } else { return (G_T0Case4E(Timeout, ApduComm, ApduResp, IsoIn, IsoOut)); } } libgcr410-2.4.0.orig/apduspli.h0100644000175000017500000000520107354047734013575 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : ApduSpli.c * * Description : Module which splits APDU commands for being transported * according to T=0 protocole. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : The 7616-4 standard indicates that only the transmission system * can initiate GET_RESPONSE and ENVELOPE command. This two * commands cannot be transmitted by this module. * * Remark : The true cases 2E and 4E.2 are not supported because the command * ENVELOPE is not supported by this module. * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _APDUSPLI_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _APDUSPLI_H #define _APDUSPLI_H /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototype section ------------------------------------------------------------------------------*/ INT16 G_DECL ApduSpliter ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]), INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/COPYING0100644000175000017500000004311007354047734012637 0ustar p2p2 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. libgcr410-2.4.0.orig/debug.c0100644000175000017500000000442307354047734013042 0ustar p2p2/* * debug.c: log (or not) messages using syslog * Copyright (C) 2001 Ludovic Rousseau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * $Id */ #include #include #include #include #include "debug.h" #define DEBUG_BUF_SIZE (256*3+30) #ifdef DEBUG void DEBUG_MSG(char *fmt, ...) { char debug_buf[DEBUG_BUF_SIZE]; va_list argptr; va_start(argptr, fmt); vsnprintf(debug_buf, DEBUG_BUF_SIZE, fmt, argptr); va_end(argptr); syslog(LOG_DEBUG, "%s", debug_buf); } /* DEBUG_MSG */ void DEBUG_XXD(char *msg, unsigned char *buffer, int len) { char debug_buf[DEBUG_BUF_SIZE]; int i; char *c, *debug_buf_end; c = debug_buf; debug_buf_end = debug_buf + DEBUG_BUF_SIZE - 5; strncpy(c, msg, DEBUG_BUF_SIZE); c += strlen(c); for (i = 0; (i < len) && (c < debug_buf_end); ++i) { sprintf(c, "%02X ", buffer[i]); c += strlen(c); } syslog(LOG_DEBUG, "%s", debug_buf); } #ifdef OLD_CODE void DEBUG_XXD(char *buffer, int size) { char ligne[80]; int col, lig = 0; unsigned char c; long address = 0; ligne[59+16] = '\0'; while (size>0) { sprintf(ligne, "%08lX ", address); for (col=0; col<16; col++) { c = *buffer++; /* octet courant */ sprintf(&ligne[col*3+10], "%02X ", c); /* Hexa */ if (c < 32) c = '.'; ligne[col+59] = c; /* ASCII */ } ligne[58] = ' '; lig += 16; address += 16; size -= 16; if (size < 0) { for (col=16+size; col<16; col++) { strcpy(&ligne[col*3+10], " "); ligne[col+59] = ' '; } ligne[58] = ' '; } printf("%s\n", ligne); } } /* DEBUG_XXD */ #endif #endif libgcr410-2.4.0.orig/debug.h0100644000175000017500000000202407354047734013042 0ustar p2p2/* * debug.h: log (or not) messages using syslog * Copyright (C) 2001 Ludovic Rousseau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * $Id */ #ifdef DEBUG void DEBUG_MSG(char *fmt, ...); void DEBUG_XXD(char *msg, unsigned char *buffer, int size); #else #define DEBUG_MSG(fmt, ...) #define DEBUG_XXD(msg, buffer, size) #endif libgcr410-2.4.0.orig/defines.h0100644000175000017500000000304407354047734013374 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef _defines_h_ #define _defines_h_ /* * $Id: defines.h,v 1.1.1.1 2001/09/07 20:19:18 rousseau Exp $ * * NAME: * defines.h -- Copyright (C) 1998 David Corcoran * corcordt@cs.purdue.edu * * DESCRIPTION: * Some global definitions and typedefs * * AUTHOR: * David Corcoran, 3/17/98 * * Modified for Macintosh by Mark Hartman */ /* * Boolean constants */ #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif /* * Type definitions */ #ifndef _BYTE typedef unsigned char BYTE; #endif #ifndef HANDLE #ifdef CPU_MAC_PPC typedef Handle HANDLE; #endif #ifdef CPU_ICAP_PC typedef int HANDLE; #endif #ifdef CPU_SUN_SPARC typedef int HANDLE; #endif #endif #ifndef bool typedef short bool; #endif /* * Simple Max Defines */ #define MAX_BUFFER_SIZE 264 #define STATUS_SIZE 2 /* * Compiler dependencies */ #ifdef __GNUC__ #define UNUSED __attribute__((unused)) #else #define UNUSED #endif #endif libgcr410-2.4.0.orig/gemansi.h0100644000175000017500000000650307354047734013405 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : ANSI.H * * Description : Replace NON-ANSI keywords with ANSI keywords. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : This library may be distributed and compiled with ANSI compiler * * Remarks : Nothing * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMANSI_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMANSI_H #define _GEMANSI_H #define _fmemccpy memccpy #define _fmemchr memchr #define _fmemcmp memcmp #define _fmemcpy memcpy #define _fmemicmp memicmp #define _fmemmove memmove #define _fmemset memset #define _fstrcat strcat #define _fstrchr strchr #define _fstrcmp strcmp #define _fstrcpy strcpy #define _fstrcspn strcspn #define _fstrdup _strdup #define _fstricmp _stricmp #define _fstrlen strlen #define _fstrlwr _strlwr #define _fstrncat strncat #define _fstrncmp strncmp #define _fstrncpy strncpy #define _fstrnicmp _strnicmp #define _fstrnset _strnset #define _fstrpbrk strpbrk #define _fstrrchr strrchr #define _fstrrev _strrev #define _fstrset _strset #define _fstrspn strspn #define _fstrstr strstr #define _fstrtok strtok #define _fstrupr _strupr #define _fmalloc malloc #define _nmalloc malloc #define _bmalloc malloc #define _frealloc realloc #define _nrealloc realloc #define _brealloc realloc #define _fcalloc calloc #define _ncalloc calloc #define _bcalloc calloc #define _fexpand _expand #define _nexpand _expand #define _bexpand _expand #define _fmsize msize #define _nmsize msize #define _bmsize msize #define _ffree free #define _nfree free #define _bfree free #define _fheapchk heapchk #define _nheapchk heapchk #define _bheapchk heapchk #define _fheapmin heapmin #define _nheapmin heapmin #define _bheapmin heapmin #define _fheapset heapset #define _nheapset heapset #define _bheapset heapset #define _fheapwalk heapwalk #define _nheapwalk heapwalk #define _bheapwalk heapwalk #define _fmblen mblen #define _fmbstowcs mbstowcs #define _fmbtowc mbtowc #define _fwcstombs wcstombs #endif /* * _GEMANSI_H */ libgcr410-2.4.0.orig/gemcard.h0100644000175000017500000000563007354047734013364 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1995 - 2001 Gemplus * * Name : GemCARD.h * * Description : General definition for GEMPLUS programs using Card Identifier. * * Release : 4.31.002 * * Last Modif : 30/03/98: V4.31.002 Add JAVACARD definition. * 13/10/97: V4.31.001 * 06/02/97: V4.30.001 Add GCL8K and GCR680_ASIC cards definitions * 16/07/96: V4.30.000 Use OROS cards definitions. * 27/10/95: V4.10.001 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMCARD_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMCARD_H #define _GEMCARD_H /*------------------------------------------------------------------------------ Card section: ------------------------------------------------------------------------------*/ #define ISOCARD 0x02 #define COSCARD 0x02 #define JAVACARD 0x02 #define FASTISOCARD 0x12 #define GFM 0x06 #define GPM103 0x07 #define GPM256 0x03 #define GPM271 0x0E #define GPM276 0x0D #define GPM416 0x04 /* * 0V on the pad fuse C4 of IFD. * */ #define GPM416R 0x14 /* * 5V on the pad fuse C4 of IFD. * */ #define GPM896 0x04 /* * Simulate a fuse blown on ICC. * */ #define GPM896R 0x14 /* * To have the real comportment. * */ #define GPM2K 0x09 #define GPM8K 0x08 #define GAM 0x0A #define GAM144 0x0A #define GAM226 0x0F #define GSM1K 0xF4 #define GSM4K 0xF6 #define GCL8K 0x02 #define GCR680_ASIC 0x02 #endif libgcr410-2.4.0.orig/gemcom.h0100644000175000017500000001744607354047734013241 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1996 - 2001 Gemplus * * Name : GemCom.h * * Description : General definition for GEMPLUS programs using Communication. * * Release : 4.31.002 * * Last Modif : 07/01/97: V4.31.002 - Add the G_KEYBOARD connection mode. * 13/10/97: V4.31.001 - Add the G_PCSC connection mode. * 11/04/97: V4.10.006 - Modify conditionnal compilation for * Borland compatibility. * 02/01/97: V4.10.003 - Add the G_HOOK and G_TCPIP connection mode * 22/04/96: V4.10.002 - Update structure for 32 bits alignement. * 01/12/95: V4.10.001 - Update to new Gemplus 4.10 Version. * 27/10/95: V4.10.001 - First version. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMCOM_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMCOM_H #define _GEMCOM_H /*------------------------------------------------------------------------------ Connexion section: COM_TYPE defines the today supported Gemplus peripheral connection type. ------------------------------------------------------------------------------*/ typedef enum { G_SERIAL, G_LPT, G_SCSI, G_PCCARD, G_ASPI, G_HOOK, G_TCPIP, G_PCSC, G_KEYBOARD } COM_TYPE; /*------------------------------------------------------------------------------ Serial port definitions. COM_SERIAL structure gathers the serial port parameters: - Port holds the port key word or directly the port address. Under Windows, it is not possible to give directly the address. - BaudRate holds the baud rate for the selected communication port. - ITNumber is used to select the interrupt which will be used to drive the selected port. Under Windows, it is not possible to give directly the ITNumber. G_COMx must be used for automatic address selection. GCRx_y must be used with Gemplus GRI200 card. The first digit declares serial port in use and the second digit declares card port in use. DEFAULT_IT is used for automatic interrupt selection. ------------------------------------------------------------------------------*/ typedef struct { #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) WORD32 Port; WORD32 BaudRate; WORD32 ITNumber; #else WORD16 Port; WORD32 BaudRate; WORD16 ITNumber; #endif } COM_SERIAL; #define G_COM1 1 #define G_COM2 2 #define G_COM3 3 #define G_COM4 4 #define GRI1_1 0x11 #define GRI1_2 0x21 #define GRI2_1 0x12 #define GRI2_2 0x22 #define GRI3_1 0x13 #define GRI3_2 0x23 #define GRI4_1 0x14 #define GRI4_2 0x24 #define DEFAULT_IT 0xFF /*------------------------------------------------------------------------------ LPT port definitions. COM_LPT structure gathers the LPT port parameters: - Port holds the port key word or directly the port address. G_LPTx must be used for automatic address selection. ------------------------------------------------------------------------------*/ typedef struct { #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) INT32 Port; #else INT16 Port; #endif } COM_LPT; #define G_LPT1 (-1) #define G_LPT2 (-2) #define G_LPT3 (-3) #define G_LPT4 (-4) /*------------------------------------------------------------------------------ SCSI port definitions. COM_SCSI structure gathers the SCSI port parameters: - Address holds the SCSI port base address. - HostId holds the host SCSI identifier and PeriphId holds the target SCSI identifier in {0,1,2,3,4,5,6,7} ------------------------------------------------------------------------------*/ typedef struct { #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) WORD32 Address; WORD32 HostId; WORD32 PeriphId; #else WORD16 Address; WORD16 HostId; WORD16 PeriphId; #endif } COM_SCSI; /*------------------------------------------------------------------------------ PCCARD port definitions. COM_PCCARD structure gathers the PCMCIA port parameters: - Socket holds a logical socket number from 0 to 5. - ITNumber is used to select the interrupt which will be used to drive the selected port. DEFAULT_IT is used for automatic interrupt selection. NO_IT is used when the PCCARD is not interrupt driven. ------------------------------------------------------------------------------*/ typedef struct { #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) WORD32 Socket; WORD32 ITNumber; #else WORD16 Socket; WORD16 ITNumber; #endif } COM_PCCARD; #define NO_IT 0xFE /*------------------------------------------------------------------------------ ASPI SCSI port definitions. COM_ASPI structure gathers the SCSI port parameters (ASPI Driven): - HostId holds the host SCSI identifier and PeriphId holds the target SCSI identifier in {0,1,2,3,4,5,6,7} - BoardNumber holds the SCSI Board Number if more than one is installed. The first board is associated to 0. ------------------------------------------------------------------------------*/ typedef struct { #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) WORD32 HostId; WORD32 PeriphId; WORD32 BoardNumber; #else WORD16 HostId; WORD16 PeriphId; WORD16 BoardNumber; #endif } COM_ASPI; /*------------------------------------------------------------------------------ Hook port definitions. COM_HOOK structure gathers the Hook port parameters: - Port holds the port key word. ------------------------------------------------------------------------------*/ typedef struct { WORD32 Port; } COM_HOOK; /*------------------------------------------------------------------------------ TCP IP port definitions. COM_TCPIP structure gathers the Hook port parameters: - Port holds the port key word. - Address holds the TCP IP address. ------------------------------------------------------------------------------*/ typedef struct { WORD32 Port; BYTE Address[4]; } COM_TCPIP; /*------------------------------------------------------------------------------ PC/SC port definitions. COM_PCSC structure gathers the PC/SC port parameters: - ReaderIdentification holds the reader's name. ------------------------------------------------------------------------------*/ typedef struct { BYTE ReaderIdentification[100]; } COM_PCSC; /*------------------------------------------------------------------------------ Generic port definitions. COM_GENERIC defines the today supported Gemplus peripheral connection type. ------------------------------------------------------------------------------*/ typedef union { COM_SERIAL Serial; COM_LPT Lpt; COM_SCSI Scsi; COM_PCCARD PcCard; COM_ASPI Aspi; COM_HOOK Hook; COM_TCPIP TcpIp; COM_PCSC Pcsc; } COM_GENERIC; #endif libgcr410-2.4.0.orig/gemdef.h0100644000175000017500000001667007354047734013217 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GemDef.h * * Description : General definition for GEMPLUS programs. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 * 11/04/97: V4.20.000 - Modify conditionnal compilation for * Borland compatibility.. * 22/04/96: V4.20.000 - Update structure for 32 bits alignement. * 01/12/95: V4.10.001 - Update to new Gemplus 4.10 Version. * 15/06/95: V4.01.002 * 06/07/94: V4.00.000 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMDEF_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMDEF_H #define _GEMDEF_H /*------------------------------------------------------------------------------ Compatibility section: G_WINDOWS must be defined for Windows target. This can be made - by the addition of #include before this file inclusion or - by added /DG_WINDOWS as a compilation flag. ------------------------------------------------------------------------------*/ #ifndef G_WINDOWS #ifdef _INC_WINDOWS #define G_WINDOWS #endif #ifdef __WINDOWS_H #define G_WINDOWS #endif #ifdef _WINDOWS_ #define G_WINDOWS #endif #endif /*------------------------------------------------------------------------------ G_DECL is used for function declaration to be adapted to target OS. Today, only Windows 3.1 and DOS are supported by this file. ------------------------------------------------------------------------------*/ #ifdef G_WINDOWS #define G_DECL FAR PASCAL #else #define G_DECL #endif /*------------------------------------------------------------------------------ G_FAR and G_HUGE are defined to prepare development under 32 bits environment. They are adapted for Borland and Microsoft compilers. ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ - Borland Turbo C version < 4.10 ------------------------------------------------------------------------------*/ #ifdef __TURBOC__ #if __TURBOC__ < 0x410 #define __far far #define _far far #define __huge huge #define _huge huge #endif #else /*------------------------------------------------------------------------------ - Microsoft C version < 7 ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #if _MSC_VER < 700 #define __far _far #define __huge _huge #endif /*------------------------------------------------------------------------------ - Others cases ------------------------------------------------------------------------------*/ #else #define __far far #define _far far #define __huge huge #define _huge huge #endif #endif /*------------------------------------------------------------------------------ - Windows 32 bits ------------------------------------------------------------------------------*/ #ifdef WIN32 #define G_FAR #define G_HUGE #else /*------------------------------------------------------------------------------ - Unix systems ------------------------------------------------------------------------------*/ #ifdef G_UNIX #define G_FAR #define G_HUGE // typedef int HANDLE; //typedef long LONG; #define NOPARITY 0 #define ODDPARITY 8 #define EVENPARITY 24 #define ONESTOPBIT 1 #define TWOSTOPBITS 2 #else /*------------------------------------------------------------------------------ - OS/2 systems ------------------------------------------------------------------------------*/ #ifdef G_OS2 #define G_FAR #define G_HUGE typedef int HANDLE; #define NOPARITY 0 #define ODDPARITY 1 #define EVENPARITY 2 #define MARKPARITY 3 #define SPACEPARITY 4 #define ONESTOPBIT 1 #define ONEHALFSTOPBIT 2 #define TWOSTOPBITS 3 /*------------------------------------------------------------------------------ - Others cases ------------------------------------------------------------------------------*/ #else #define G_FAR __far #define G_HUGE __huge #endif /* * #ifdef G_OS2 */ #endif /* * #ifdef G_UNIX */ #endif /* * #ifdef WIN32 */ /*------------------------------------------------------------------------------ Type definitions: ------------------------------------------------------------------------------*/ /* #ifndef G_WINDOWS #ifndef BYTE typedef unsigned char BYTE; #define _BYTE #endif typedef unsigned short WORD; #ifdef G_UNIX // typedef unsigned int DWORD; #define _DWORD #else // G_UNIX typedef unsigned long DWORD; #endif // G_UNIX typedef unsigned short HINSTANCE; #endif */ typedef unsigned char WORD8; typedef unsigned short WORD16; #ifdef G_UNIX typedef unsigned int WORD32; #else /* * G_UNIX */ typedef unsigned long WORD32; #endif /* * G_UNIX */ typedef signed char INT8; typedef signed short INT16; typedef signed short INTEGER; #ifdef G_UNIX typedef signed int INT32; #else /* * G_UNIX */ typedef signed int INT32; #endif /* * G_UNIX */ #if !defined (G_WINDOWS) && !defined (G_OS2) && !defined (G_UNIX) typedef signed short BOOL; #endif #ifdef G_OS2 typedef unsigned int UINT; #endif #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif /*------------------------------------------------------------------------------ TLV_TYPE structure holds: - a type field (T) which indicates the V field type: - a length field (L) which indicates the size of the V field, in bytes. - a value field (V) which is the data part of the message. ------------------------------------------------------------------------------*/ typedef struct { WORD8 T; WORD8 L; void G_FAR *V; } TLV_TYPE; /*------------------------------------------------------------------------------ Constant definitions: EOS is the End Of String character. MAX_FILE_NAME is the maximal length for a full file name, with path. MAX_LINE_LENGTH is the maximal length for an ASCII line in our configuration files. ------------------------------------------------------------------------------*/ #define EOS '\0' #define MAX_FILE_NAME 129 #define MAX_LINE_LENGTH 120 #define OFF 0 #define ON 1 #define CLEAR 2 #ifndef NULL #define NULL 0 #endif #endif libgcr410-2.4.0.orig/gemerror.h0100644000175000017500000005720607354047734013612 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GemError.h * * Description : Errors and Warning definitions for all GEMPLUS API (GCR/GPS). * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 * 17/01/97: V4.10.003 - Add GE_IFD_BUSY, GW_ALREADY_DONE and * GW_ICC_STATUS. * 04/01/96: V4.10.002 - Replace LPSTR by char G_FAR *. * 01/12/95: V4.10.001 - Update to new Gemplus 4.10 Version. * 08/09/95: V4.01.005 * 06/07/94: V4.00.000 * ******************************************************************************** * * Warning : * * Remark : The following convention applies to all definitions: * OK is coded by a null value, * Error are coded with negative values, * Warning are coded with positive values. * * The following definitions are used: * ICC : Integrated Circuit Card * IFD : InterFace Device * GPS : Gemplus Personalization System. * Host: Machine which drives the reader. * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMERROR_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMERROR_H #define _GEMERROR_H /*------------------------------------------------------------------------------ Successful operation: G_OK (0) if everything is under control. ------------------------------------------------------------------------------*/ #define G_OK 0 /*------------------------------------------------------------------------------ Errors definitions: Error codes from ICC. GE_ICC_ABSENT (- 1) (FB) No ICC is present in IFD. GE_ICC_MUTE (- 2) (A2) ICC is mute. GE_ICC_UNKNOWN (- 3) (14) ICC is not supported. GE_ICC_PULL_OUT (- 4) (F7) ICC has been removed during command execution. Database may be corrupted. GE_ICC_NOT_POWER (- 5) (15) ICC not reveiving power or has been removed-inserted between commands. GE_ICC_INCOMP (- 6) ICC has caused a short circuit or is physically incompatible with IFD. GE_ICC_ABORT (-10) (A4) ICC sends an abort block (T=1 only). ------------------------------------------------------------------------------*/ #define GE_ICC_ABSENT (-1) #define GE_ICC_MUTE (-2) #define GE_ICC_UNKNOWN (-3) #define GE_ICC_PULL_OUT (-4) #define GE_ICC_NOT_POWER (-5) #define GE_ICC_INCOMP (-6) #define GE_ICC_ABORT (-10) /*------------------------------------------------------------------------------ Error codes between ICC and IFD (II). GE_II_COMM (-100) (13) Communication is not possible between ICC and IFD. GE_II_PARITY (-101) (A3) Character parity error between ICC and IFD. GE_II_EDC (-102) Error detection code raised. GE_II_ATR (-110) Incoherence in ATR. GE_II_ATR_TS (-111) (10) Bad TS in ATR. GE_II_ATR_TCK (-112) (1D) Bad TCK in ATR. GE_II_ATR_READ (-113) (03) Impossible to read some ATR bytes. GE_II_PROTOCOL (-120) Inconsistent protocol. GE_II_UNKNOWN (-121) (17) Unknown protocol. GE_II_PTS (-122) (18) PTS is required for this choice. GE_II_IFSD_LEN (-123) Received block length > IFSD (T=1 only). GE_II_PROC_BYTE (-124) (E4) Bad procedure byte from ICC (T=0 only). GE_II_INS (-125) (11) Bad INS in a command (6X or 9X) (T=0 only). GE_II_RES_LEN (-126) Message length from ICC not supported. GE_II_RESYNCH (-127) 3 failures ! Resynch required by ICC. ------------------------------------------------------------------------------*/ #define GE_II_COMM (-100) #define GE_II_PARITY (-101) #define GE_II_EDC (-102) #define GE_II_ATR (-110) #define GE_II_ATR_TS (-111) #define GE_II_ATR_TCK (-112) #define GE_II_ATR_READ (-113) #define GE_II_PROTOCOL (-120) #define GE_II_UNKNOWN (-121) #define GE_II_PTS (-122) #define GE_II_IFSD_LEN (-123) #define GE_II_PROC_BYTE (-124) #define GE_II_INS (-125) #define GE_II_RES_LEN (-126) #define GE_II_RESYNCH (-127) /*------------------------------------------------------------------------------ Error codes from IFD. GE_IFD_ABSENT (-200) No IFD connected. GE_IFD_MUTE (-201) No response from IFD/GPS. GE_IFD_UNKNOWN (-202) IFD is not supported. GE_IFD_BUSY (-203) IFD is busy by an other process. GE_IFD_FN_PROG (-210) (16) Insufficient power for programming. GE_IFD_FN_UNKNOWN (-211) (1C) The function is not available in the IFD. GE_IFD_FN_FORMAT (-212) (1B or 04) Incoherence in the argument number or type. GE_IFD_FN_DEF (-213) (19, 1E, 1F, 20) A macro definition generates an internal problem. GE_IFD_FN_FAIL (-214) The called IFD function has failed. GE_IFD_MEM_PB (-215) This memory option is not available. GE_IFD_MEM_ACCESS (-216) This memory access is forbidden. GE_IFD_MEM_ACTIVATION (-217) Impossible to activate the selected code. GE_IFD_ABORT (-220) (A5) IFD sends an abort block.Buffer istoo small to receive data from card (T=1 only). GE_IFD_RESYNCH (-221) (A6) IFD has done a resynchronisation. Data are lost (T=1 only). GE_IFD_TIMEOUT (-290) (04) Returned by the IFD keyboard when no key has been pressed during the given time. GE_IFD_OVERSTRIKED (-291) (CF) Returned by the IFD keyboard when two keys are pressed at the same time. ------------------------------------------------------------------------------*/ #define GE_IFD_ABSENT (-200) #define GE_IFD_MUTE (-201) #define GE_IFD_UNKNOWN (-202) #define GE_IFD_BUSY (-203) #define GE_IFD_FN_PROG (-210) #define GE_IFD_FN_UNKNOWN (-211) #define GE_IFD_FN_FORMAT (-212) #define GE_IFD_FN_DEF (-213) #define GE_IFD_FN_FAIL (-214) #define GE_IFD_MEM_PB (-215) #define GE_IFD_MEM_ACCESS (-216) #define GE_IFD_MEM_ACTIVATION (-217) #define GE_IFD_ABORT (-220) #define GE_IFD_RESYNCH (-221) #define GE_IFD_TIMEOUT (-290) #define GE_IFD_OVERSTRIKED (-291) /*------------------------------------------------------------------------------ Error codes between Host and IFD (HI). GE_HI_COMM (-300) Communication error between IFD and Host. GE_HI_PARITY (-301) Character parity error between IFD and Host. GE_HI_LRC (-302) Longitudinal redundancy code error. GE_HI_PROTOCOL (-310) Frame error in the Host-IFD protocol. GE_HI_LEN (-311) (1A) Bad value for LN parameter in header. GE_HI_FORMAT (-312) (09) Header must contain ACK or NACK in TLP protocol. No I/R/S-Block has been detected in Gemplus Block Protocol. GE_HI_CMD_LEN (-313) (12) Message length from Host not supported. GE_HI_NACK (-314) IFD sends a NACK /R-Block. GE_HI_RESYNCH (-315) IFD sends a S-Block. GE_HI_ADDRESS (-316) A bad Source/Target address has been detected in Gemplus Block Protocol GE_HI_SEQUENCE (-317) A bad sequence number has been detected in Gemplus Block Protocol. ------------------------------------------------------------------------------*/ #define GE_HI_COMM (-300) #define GE_HI_PARITY (-301) #define GE_HI_LRC (-302) #define GE_HI_PROTOCOL (-310) #define GE_HI_LEN (-311) #define GE_HI_FORMAT (-312) #define GE_HI_CMD_LEN (-313) #define GE_HI_NACK (-314) #define GE_HI_RESYNCH (-315) #define GE_HI_ADDRESS (-316) #define GE_HI_SEQUENCE (-317) /*------------------------------------------------------------------------------ Error codes from host. GE_HOST_PORT (-400) Port not usable. GE_HOST_PORT_ABS (-401) Port absent. GE_HOST_PORT_INIT (-402) Port not initialized. GE_HOST_PORT_BUSY (-403) Port is always busy. GE_HOST_PORT_BREAK (-404) Port does not sent bytes. GE_HOST_PORT_LOCKED (-405) Port access is locked. GE_HOST_PORT_OS (-410) Unexpected error for operating system. GE_HOST_PORT_OPEN (-411) The port is already opened. GE_HOST_PORT_CLOSE (-412) The port is already closed. GE_HOST_MEMORY (-420) Memory allocation fails. GE_HOST_POINTER (-421) Bad pointer. GE_HOST_BUFFER_SIZE(-422) GE_HOST_RESOURCES (-430) Host runs out of resources. GE_HOST_USERCANCEL (-440) User cancels operation. GE_HOST_PARAMETERS (-450) A parameter is out of the allowed range. GE_HOST_DLL_ABS (-451) A dynamic call to à library fails because the target library was not found. GE_HOST_DLL_FN_ABS (-452) A dynamic call to a function fails because the target library does not implement this function. ------------------------------------------------------------------------------*/ #define GE_HOST_PORT (-400) #define GE_HOST_PORT_ABS (-401) #define GE_HOST_PORT_INIT (-402) #define GE_HOST_PORT_BUSY (-403) #define GE_HOST_PORT_BREAK (-404) #define GE_HOST_PORT_LOCKED (-405) #define GE_HOST_PORT_OS (-410) #define GE_HOST_PORT_OPEN (-411) #define GE_HOST_PORT_CLOSE (-412) #define GE_HOST_MEMORY (-420) #define GE_HOST_POINTER (-421) #define GE_HOST_BUFFER_SIZE (-422) #define GE_HOST_RESOURCES (-430) #define GE_HOST_USERCANCEL (-440) #define GE_HOST_PARAMETERS (-450) #define GE_HOST_DLL_ABS (-451) #define GE_HOST_DLL_FN_ABS (-452) /*------------------------------------------------------------------------------ Error codes from APDU layer. GE_APDU_CHAN_OPEN (-501) Channel is already opened. GE_APDU_CHAN_CLOSE (-502) Channel is already closed. GE_APDU_SESS_CLOSE (-503) OpenSession must be called before. GE_APDU_SESS_SWITCH (-504) The switch session is not possible (ICC type has change or function is not available on the selected reader). GE_APDU_LEN_MAX (-511) ApduLenMax greater than the maximum value 65544. GE_APDU_LE (-512) Le must be < 65536 in an APDU command. GE_APDU_RECEIV (-513) The response must contained SW1 & SW2. GE_APDU_IFDMOD_ABS (-520) The selected IFD module is absent from the system. GE_APDU_IFDMOD_FN_ABS(-521) The selected function is absent from the IFD module. ------------------------------------------------------------------------------*/ #define GE_APDU_CHAN_OPEN (-501) #define GE_APDU_CHAN_CLOSE (-502) #define GE_APDU_SESS_CLOSE (-503) #define GE_APDU_SESS_SWITCH (-504) #define GE_APDU_LEN_MAX (-511) #define GE_APDU_LE (-512) #define GE_APDU_RECEIV (-513) #define GE_APDU_IFDMOD_ABS (-520) #define GE_APDU_IFDMOD_FN_ABS (-521) /*------------------------------------------------------------------------------ Error codes from TLV exchanges. GE_TLV_WRONG (-601) A TLV type is unknown. GE_TLV_SIZE (-602) The value size is not sufficient to hold the data according to TLV type. GE_TLV_NO_ACTION (-603) The TLV function call has not realized the requested operation. ------------------------------------------------------------------------------*/ #define GE_TLV_WRONG (-601) #define GE_TLV_SIZE (-602) #define GE_TLV_NO_ACTION (-603) /*------------------------------------------------------------------------------ Error codes from file operations: GE_FILE_OPEN (-700) A file is already opened or it is impossible to open the selected file. GE_FILE_CLOSE (-701) No file to close or it is impossible to close the selected file. GE_FILE_WRITE (-710) Impossible to write in file. GE_FILE_READ (-720) Impossible to read in file. GE_FILE_FORMAT (-730) The file format is invalid. GE_FILE_HEADER (-731) No header found in file. GE_FILE_QUOT_MARK (-732) Unmatched quotation mark founds in file. GE_FILE_END (-733) File end encountered. GE_FILE_CRC (-734) Invalide CRC value for file. GE_FILE_VERSION (-740) File version not supported. GE_FILE_CONFIG (-750) The read config is invalid. ------------------------------------------------------------------------------*/ #define GE_FILE_OPEN (-700) #define GE_FILE_CLOSE (-701) #define GE_FILE_WRITE (-710) #define GE_FILE_READ (-720) #define GE_FILE_FORMAT (-730) #define GE_FILE_HEADER (-731) #define GE_FILE_QUOT_MARK (-732) #define GE_FILE_END (-733) #define GE_FILE_CRC (-734) #define GE_FILE_VERSION (-740) #define GE_FILE_CONFIG (-750) /*------------------------------------------------------------------------------ Error codes from multi-task system. (SYS) GE_SYS_WAIT_FAILED (-800) A wait for an object is failed (the object cannot be free or the system is instable) GE_SYS_SEMAP_RELEASE (-801) The API cannot release a semaphore ------------------------------------------------------------------------------*/ #define GE_SYS_WAIT_FAILED (-800) #define GE_SYS_SEMAP_RELEASE (-801) /*------------------------------------------------------------------------------ Unknown error code. GE_UNKNOWN_PB (-1000) The origine of error is unknown !! When an unexpected error code has been received, the returned value is calculated by GE_UNKNOWN_PB - Error Code. ------------------------------------------------------------------------------*/ #define GE_UNKNOWN_PB (-1000) /*------------------------------------------------------------------------------ Errors definitions Generic GPS ------------------------------------------------------------------------------*/ #define GE_GPS_CARDABSENT (-1001) /* * CARD is ABSENT in the station * */ #define GE_GPS_MUTE (-1201) /* * GPS is MUTE * */ #define GE_GPS_COMMAND (-1211) /* * COMMAND not available in this GPS * */ #define GE_GPS_FORMAT (-1212) /* * incorrect command FORMAT * */ #define GE_GPS_COMM (-1300) /* * COMMunication error with GPS * */ #define GE_GPS_OPEN (-1411) /* * The port is already opened. * */ #define GE_GPS_CLOSE (-1412) /* * The port is already closed. * */ #define GE_GPS_SYSTEM (-1230) /* * SYSTEM problems on GPS * */ #define GE_GPS_MECHANIC (-1240) /* * MECHANIC problems on GPS * */ #define GE_GPS_BUSY (-1241) /* * the station is BUSY * */ #define GE_GPS_CARDOUTPUT (-1242) /* * CARDOUTPUT is full * */ #define GE_GPS_CARDINPUT (-1243) /* * CARDINPUT is empty * */ #define GE_GPS_GRAPHIC (-1250) /* * error with GRAPHIC head * */ #define GE_GPS_RIBBON (-1251) /* * error with RIBBON on graphic head * */ #define GE_GPS_OVERHEAT (-1252) /* * OVERHEAT on graphic head * */ #define GE_GPS_NOTHING2PRINT (-1253) /* * Nothing to print on card !! * */ #define GE_GPS_ELECTRIC (-1260) /* * error with ELECTRIC head * */ #define GE_GPS_MAGNETIC (-1270) /* * error with MAGNETIC head * */ #define GE_GPS_PCMCIA (-1280) /* * error with PCMCIA station * */ #define GE_GPS_DOWNLOAD (-1303) /* * font or bitmap DOWNLOAD error * */ #define GE_GPS_LENGTH (-1500) /* * Data length > Data max or Data dot */ /* * length. * */ #define GE_GPS_LOGO_FORMAT (-1501) /* * Only PCX file are supported today * */ /* * on GPS1X0. * */ #define GE_GPS_BMP_FORMAT (-1501) /* * Only BMP 24 bits per pixel are * */ /* * supported today on GPS2X0. * */ #define GE_GPS_BAD_OBJECT (-1502) /* * The object is not supported by the */ /* * GPS. * */ #define GE_GPS_BAD_VERSION (-1503) /* * The driver is not adapted to the * */ /* * GPS. * */ #define GE_GPS_RESTART (-1550) /* * The restart command must been * sent. */ #define GE_GPS_RESET (-1551) /* * The GPS must be reseted. * */ #define GE_GPS_FONT (-1560) /* * The selected font is not * available. */ #define GE_GPS_WIDTH (-1570) /* * The object width is too small ! * */ #define GE_GPS_HEIGHT (-1571) /* * The object height is too small ! * */ /*------------------------------------------------------------------------------ File codes -----------------------------------------------------------------------------*/ #define GE_GPS_FILE_OPEN (-1600) #define GE_GPS_FILE_END (-1601) #define GE_GPS_FILE_READ (-1602) #define GE_GPS_FILE_WRITE (-1603) #define GE_GPS_FILE_NOT_OPEN (-1604) #define GE_GPS_FILE_FORMAT (-1610) #define GE_GPS_FILE_HEADER (-1611) #define GE_GPS_FILE_CARD_INFO (-1612) #define GE_GPS_FILE_DEF_OBJ (-1613) #define GE_GPS_FILE_OBJECT (-1614) #define GE_GPS_FILE_CONFIG (-1620) #define GE_GPS_FILE_QUOT_MARK (-1621) #define GE_GPS_FILE_LOGO_PARAM (-1622) #define GE_GPS_FILE_VERSION (-1630) #define GE_GPS_FILE_PRINT_PARAM (-1640) #define GE_GPS_FILE_CRC (-1641) /*------------------------------------------------------------------------------ TLV codes for GPS ------------------------------------------------------------------------------*/ #define GE_TLV_TYPE (-1700) #define GE_TLV_LEN (-1701) /*------------------------------------------------------------------------------ Warning definitions GW_ATR (1) (A0) The card is not fully supported. GW_APDU_LEN_MAX (2) APDU cannot be transported with this value. GW_APDU_LE (3) (E5) Le != Response length. For example, data are requested but are not available. GW_ALREADY_DONE (4) The action is already perform. GW_ICC_STATUS (5) (E7) The ICC status is different from 0x9000. GW_HI_NO_EOM (300) The decoded message has no EOM character. ------------------------------------------------------------------------------*/ #define GW_ATR 1 #define GW_APDU_LEN_MAX 2 #define GW_APDU_LE 3 #define GW_ALREADY_DONE 4 #define GW_ICC_STATUS 5 #define GW_HI_NO_EOM 300 #define GW_GPS_FONT_DISAGREE 1001 #define GW_GPS_BARCODE_DISAGREE 1002 /*------------------------------------------------------------------------------ GTV100 Warning GW_GTV_ERASE_NEEDED (1101) The down loader has detected that the programming area is already programmed. A preliminary erase is needed. GW_GTV_DOWNLOADING (1102) the firmware's downloading processus is still active ------------------------------------------------------------------------------*/ #define GW_GTV_ERASE_NEEDED 1101 #define GW_GTV_DOWNLOADING 1102 /*------------------------------------------------------------------------------ Prototypes section ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif INT16 G_DECL G_SetReaderName(const char G_FAR * lpszReaderName); INT16 G_DECL G_SetGpsName(const char G_FAR * lpszGpsName); INT16 G_DECL G_GetError(const INT16 nErrCode, char G_FAR * lpszErrMsg); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/gemgcr.h0100644000175000017500000001721607354047734013231 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GemGCR.h * * Description : General definition for GEMPLUS programs using APDU API. * * Release : 4.31.002 * * Last Modif : 07/01/98: V4.31.002 - Add PCSC Keyboard protocol type * 13/10/97: V4.31.001 - Add COMM_PCSC. * 23/04/97: V4.30.002 - Modify prototype function G4_ICCSet(Get)PTS. * 04/04/97: V4.30.001 - Add function G4_ICCSet(Get)Voltage and * G4_ICCSet(Get)PTS. * 01/04/97: V4.10.005 - Add the MAX_IFD_CHANNEL * 12/02/97: V4.10.004 - Modify the PERIPHERAL macro. * 07/02/97: V4.10.003 - Add COM_TCPIP and COM_HOOK into the * structure G4_PARAM_CAHNNEL. * 22/04/96: V4.10.002 - Update structure for 32 bits alignement. * 01/12/95: V4.10.001 * 27/10/95: V4.10.001 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMGCR_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMGCR_H #define _GEMGCR_H /*------------------------------------------------------------------------------ Include section: GEMCOM.H contain communication definitions. ------------------------------------------------------------------------------*/ #include "gemcom.h" /*------------------------------------------------------------------------------ Reader section: SECURITY macro gives access to reader embedded security modules. It must be use as SECURITY(GCR500) for example. PERIPHERAL macro gives access to reader embedded peripherals, like security module. SECURITY(GCR500) = PERIPHERAL(1,GCR500). ------------------------------------------------------------------------------*/ #define SECURITY(x) (0x0100 | (x)) #define PERIPHERAL(x,y) (x == 0) ? (y):((0x0080 << (x)) | (y)) /*------------------------------------------------------------------------------ Product Interface Library section: MAX_RESET_LEN holds the maximal length for an answer to reset. MAX_APDU_LEN is the maximal length for an APDU buffer. The maximal value, according to ISO standard is 65544 but today, low level drivers are limited by the size of a segment. MAX_IFD_STRING holds the maximal length for an IFD identier. MAX_OFD_SPECIFIC holds the maximal size for the IFD specific field. MAX_DUMMY_CHANNEL and MAX_DUMMY_SESSION are used in RFU fields. MAX_IFD_CHANNEL defines the maximal IFD supported in a same time by the API. ------------------------------------------------------------------------------*/ #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) #define MAX_RESET_LEN 36 #else #define MAX_RESET_LEN 33 #endif #define MAX_APDU_LEN 65535lu #define MAX_DUMMY_CHANNEL 100 #define MAX_DUMMY_SESSION 100 - MAX_RESET_LEN #define MAX_IFD_STRING 100 #define MAX_IFD_SPECIFIC 100 #define MAX_IFD_CHANNEL 16 /*------------------------------------------------------------------------------ COMMAND_LEN define the size of an ICC command. NULL_LEN is a value used with Gemplus specific ICC products. ------------------------------------------------------------------------------*/ #define COMMAND_LEN 4 #define NULL_LEN 0xFFFFFFFFlu /*------------------------------------------------------------------------------ Defines the available protocols between host and reader: TLP224_PROTOCOL or BLOCK_PROTOCOL on GCI400. PCCARD_PROTOCOL on GPR or GPR400 AT_G_PROTOCOL on GCM TCPIP_PROTOCOL for future use PCSC_KB_PROTOCOL for the PCSC defined protocol for Keyboard readers. ------------------------------------------------------------------------------*/ #define TLP224_PROTOCOL 0 #define BLOCK_PROTOCOL 1 #define PCCARD_PROTOCOL 2 #define AT_G_PROTOCOL 3 #define TCPIP_PROTOCOL 4 #define PCSC_KB_PROTOCOL 5 /*------------------------------------------------------------------------------ Defines the available protocols between reader and card (PTS Mode): - IFD_DEFAULT_MODE -> same as OROS 2.x maximum speed without request, - IFD_WITHOUT_PTS_REQUEST -> no PTS management (baud rate is 9600 bps), - IFD_NEGOTIATE_PTS_OPTIMAL -> PTS management automatically, - IFD_NEGOTIATE_PTS_MANUALLY -> PTS management "manually" by parameters. Defines the PTS format (PTS0) and indicates by the bits b5,b6,b7 set to 1 the presence of the optional parameters PTS1,PTS2,PTS3 respectively. The least significant bits b1 to b4 select protocol type type T. Use the macro - IFD_NEGOTIATE_PTS1, - IFD_NEGOTIATE_PTS2, - IFD_NEGOTIATE_PTS3, - IFD_NEGOTIATE_T0, - IFD_NEGOTIATE_T1 to set these bits. Defines the ICC power supply voltage: - ICC_VCC_5V is the power supply voltage 5V (by default), - ICC_VCC_3V is the power supply voltage 3V, - ICC_VCC_DEFAULT is the power supply voltage by default (5V). ------------------------------------------------------------------------------*/ #define IFD_DEFAULT_MODE 0 #define IFD_WITHOUT_PTS_REQUEST 1 #define IFD_NEGOTIATE_PTS_OPTIMAL 2 #define IFD_NEGOTIATE_PTS_MANUALLY 3 #define IFD_NEGOTIATE_T0 0x00 #define IFD_NEGOTIATE_T1 0x01 #define ICC_VCC_5V 0 #define ICC_VCC_3V 1 #define ICC_VCC_5_3V 2 #define ICC_VCC_DEFAULT ICC_VCC_5V /*------------------------------------------------------------------------------ G4_APDU_COMM structure holds: - Command holds the command bytes to send to ICC. - LengthIn holds the number of bytes to send to ICC. The allowed range is { 0 .. 65535 }. The NULL_LEN is used for Gemplus specific products. - DataIn holds the bytes to send to ICC. WARNING: the user must allocate this buffer. - LengthExpected memorises the maximal length expected in the ICC response. The allowed range is { 0 .. 65536}. ------------------------------------------------------------------------------*/ typedef struct g4_apdu_comm { WORD8 Command[COMMAND_LEN]; WORD32 LengthIn; WORD8 G_FAR *DataIn; WORD32 LengthExpected; } G4_APDU_COMM; /*------------------------------------------------------------------------------ G4_APDU_RESP structure holds: - LengthOut is the real number of received bytes. - DataOut holds the received bytes. WARNING: the user must allocate this buffer. - Status holds the two status bytes SW1 and SW2. ------------------------------------------------------------------------------*/ typedef struct g4_apdu_resp { WORD32 LengthOut; WORD8 G_FAR *DataOut; #if defined (G_UNIX) || defined (WIN32) || defined (G_OS2) WORD32 Status; #else WORD16 Status; #endif } G4_APDU_RESP; #endif libgcr410-2.4.0.orig/gemmac.h0100644000175000017500000000361307354047734013212 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GemMac.h * * Description : General macro definitions for GEMPLUS programs * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 * 01/12/95: V4.10.001 - Update for 4.10 Version. * 22/08/94: V4.00 * 06/07/94: V4.00 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMMAC_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMMAC_H #define _GEMMAC_H /*------------------------------------------------------------------------------ General C macros. ------------------------------------------------------------------------------*/ #ifndef LOWORD #define LOWORD(l) (l & 0xFFFF) #endif #ifndef HIWORD #define HIWORD(l) ((l & 0xFFFF0000) >> 16) #endif #ifndef LOBYTE #define LOBYTE(w) (w & 0xFF) #endif #ifndef HIBYTE #define HIBYTE(w) ((w & 0xFF00) >> 8) #endif #endif libgcr410-2.4.0.orig/gemplus.h0100644000175000017500000000411607354047734013434 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * Name : Gemplus.h * * Description : This file contains general declarations used by Gemplus * software. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 * 01/12/95: V4.10.001 - Update for 4.10 Version. * 22/08/94: V4.00 * 06/07/94: V4.00 * ******************************************************************************** * * Warning : * * Remark : It uses the following files: * #include "gemdef.h" * #include "gemmac.h" * #include "gemerror.h" * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GEMPLUS_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GEMPLUS_H #define _GEMPLUS_H /*------------------------------------------------------------------------------ Inclusion section: GEMDEF.H defines defines general definitions and structures used by Gemplus applications. GEMMAC.H defines general macros. GEMMERROR.H defines the Gemplus error codes. ------------------------------------------------------------------------------*/ #include "gemdef.h" #include "gemmac.h" #include "gemerror.h" #endif libgcr410-2.4.0.orig/gserial.c0100644000175000017500000006726507354047734013417 0ustar p2p2/*************************************************************************** gserial.c - description ------------------- begin : Wed Apr 18 2001 copyright : (C) by 1991 - 2001 Gemplus email : ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ // ///// gserial.c // #define DEBUG //Used to generate gemgcr2 log file. #define G_NAME "Serial" #define G_RELEASE "4.31.002" // changed from "4.31.001"-madhu // ------------------------------------------------- // Pragma section // - comment is called if _MSC_VER is defined. // -------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include #include #include #include #include #include #include #include #include #include #include // #ifdef _LINUX_SOURCE #include #include // #endif // This line is commented by atu #include #include #include #include #include "gemplus.h" #include "gemcom.h" #include "debug.h" // #include "gttimout.h" #ifdef WIN32 #include "gemansi.h" #endif #define DTR_CONTROL_ENABLE 1 #define DTR_CONTROL_DISABLE 0 #define RTS_CONTROL_ENABLE 1 #define RTS_CONTROL_DISABLE 0 #define COM_C_system_error -1 #ifdef _SUN_SOURCE #define _CBAUD CBAUD #endif // ---------------------------------------------- // Module public interface. // - gtser.h // ----------------------------------------------*/ #include "gtser.h" /*------------------------------------------------------------------- Constant section: - DEFAULT_EXCHANGE_TIMEOUT defines the default time-out for an exchange beetween the DLL and the W32GTSER server process (1200ms). - START_TIME_OUT defines the time out for the W32GTSER.EXE start (10 sec). - END_TIME_OUT defines the time out for the W32GTSER.EXE end (2 sec). ------------------------------------------------------------------------------*/ #define DEFAULT_EXCHANGE_TIMEOUT 1200 #define START_TIME_OUT 10000 #define END_TIME_OUT 2000 /*--------------------------------------------------------------------- Macro section: - CTRL_BAUD_RATE control the baud rate parameter. Today, under Windows 3.1, it is not possible to use a value greater than 57600 bauds. - WORD_LEN, PARITY and STOP retreive the configuration values to pass to Windows to configure the port. ----------------------------------------------------------------------*/ #define CTRL_BAUD_RATE(x) (((x) <= 57600u) ? (x) : 57600u) #define WORD_LEN(x) (BYTE)(((x) & 3) + 5) #define PARITY(x) (BYTE)(parity[((BYTE)(x) >> 3) & 3]) #define STOP(x) (BYTE)(stop[((x) >> 2) & 1]) static WORD16 parity[4] = { NOPARITY, ODDPARITY, NOPARITY, EVENPARITY }; static WORD16 stop[2] = { ONESTOPBIT, TWOSTOPBITS }; static int port_fd = -1; static INT16 g_Counter = 0; static INT16 g_Error = 0; static INT32 g_TimeOut = 0; static INT32 g_TxSize = 0, g_RxSize = 0; static WORD16 g_InitRts = 0; static WORD16 g_InitDtr = 0; struct termios save_termios; static INT32 g_iNbByteRead = 0; FILE *fw = NULL; // MAX_INPUT is defined as 255 static BYTE g_szReadBuffer[500]; // --2001 Modif /* * INT16 G_DECL G_SerPortOpen(const TGTSER_PORT G_FAR *Param) { INT16 handle, * response; * * // used to set parameters in the device control block. struct termios * current_termios; int x; * * if ( port_fd >= 0 ) { return GE_HOST_PORT_OPEN; } * * * handle = (INT16)(Param->Port - 1); * * if ((handle < 0) || (handle >= HGTSER_MAX_PORT)) { return * (GE_HOST_PARAMETERS); } * * // Opening of comport.. its in separate block.. { char com_name[20]; char * *dev_name; //char dev_name[20]; * * memset(com_name, 0, sizeof(com_name)); strcpy(com_name, "COM"); * com_name[strlen(com_name)] = (char)('0'+ Param->Port); put_msg("com_name = * %s\n", com_name); dev_name = getenv(com_name); put_msg("device name = * %s\n", dev_name); if ( dev_name == NULL ) { return (GE_HOST_PORT_INIT); } * * //memset(dev_name, 0, sizeof(dev_name)); //strcpy(dev_name, "/dev/cua"); * //dev_name[strlen(dev_name)] = (char)('0' + handle); * * port_fd = open(dev_name, O_RDWR); // O_NOCTTY was used //port_fd = * open("/dev/cua0", O_RDWR|O_NOCTTY); * * put_msg("Opening %s port on Device %s, handle=%d\n", com_name, dev_name, * handle); } * * if ( port_fd == COM_C_system_error ) { fprintf(stderr, "Port Open * Error.\n"); return GE_HOST_PORT_INIT; } * * if ( tcgetattr(port_fd, ¤t_termios) == COM_C_system_error ) { * close(port_fd); port_fd = -1; fprintf(stderr, "tcgetattr() function * error.\n"); return GE_HOST_PORT_INIT; } * * save_termios = current_termios; * * current_termios.c_iflag = 0; current_termios.c_oflag = 0; // Raw output * modes current_termios.c_cflag = 0; // Raw output modes * * // Do not echo characters because if you connect // to a host it or your // * modem will echo characters for you. // Don't generate signals. * current_termios.c_lflag = 0; * * // control flow - enable receiver - ignore modem // control lines * current_termios.c_cflag = CREAD | CLOCAL; * * x = CTRL_BAUD_RATE(Param->BaudRate); //put_msg("Baud Rate=%d\n", x); * * switch((int)CTRL_BAUD_RATE(Param->BaudRate)) { case 50 : * current_termios.c_cflag |= B50; break; case 75 : * current_termios.c_cflag |= B75; break; case 110 : * current_termios.c_cflag |= B110; break; case 134 : * current_termios.c_cflag |= B134; break; case 150 : * current_termios.c_cflag |= B150; break; case 200 : * current_termios.c_cflag |= B200; break; case 300 : * current_termios.c_cflag |= B300; break; case 600 : * current_termios.c_cflag |= B600; break; case 1200 : * current_termios.c_cflag |= B1200; break; case 1800 : * current_termios.c_cflag |= B1800; break; case 2400 : * current_termios.c_cflag |= B2400; break; case 4800 : * current_termios.c_cflag |= B4800; break; case 9600 : * current_termios.c_cflag |= B9600; break; case 19200 : * current_termios.c_cflag |= B19200; break; case 38400 : * current_termios.c_cflag |= B38400; break; default : * current_termios.c_cflag |= B9600; break; } * * x = WORD_LEN(Param->Mode); * * //put_msg("Word Len=%d\n", x); switch((int)WORD_LEN(Param->Mode))// number * of databits { case 5 : current_termios.c_cflag |= CS5; break; case 6 : * current_termios.c_cflag |= CS6; break; case 7 : current_termios.c_cflag |= * CS7; break; case 8 : current_termios.c_cflag |= CS8; break; default : * current_termios.c_cflag |= CS8; break; } * * x = PARITY(Param->Mode); //put_msg("Parity = %d\n", x); * * switch((int)PARITY(Param->Mode)) { case ODDPARITY : current_termios.c_cflag * |= PARENB + PARODD; break; case EVENPARITY : current_termios.c_cflag |= * PARENB; break; default : break; } * * x = STOP(Param->Mode); //put_msg("Stop= %d\n", x); * * if (STOP(Param->Mode) == TWOSTOPBITS) // stop bits { * current_termios.c_cflag |= CSTOPB; } * * // control caracteres * * // Minimum bytes to read // current_termios.c_cc[VMIN] = 0; // Time * between two bytes read (VTIME x 0.10 s) // current_termios.c_cc[VTIME] = 0; * * // This is Non Canonical mode set. // by setting c_cc[VMIN]=0 and * c_cc[VTIME] = 10 // each read operation will wait for 10 10=1sec // If * single byte is received, read function returns. // if timer expires, read() * returns 0. // Minimum bytes to read current_termios.c_cc[VMIN] = 0; // * Time between two bytes read (VTIME x 0.10 s) current_termios.c_cc[VTIME] = * 10; * * if ( tcsetattr(port_fd, TCSANOW, ¤t_termios) == COM_C_system_error ) * { close(port_fd); port_fd = -1; fprintf(stderr, "tcsetattr error\n"); * return GE_HOST_PORT_INIT; } * * g_Counter = 1; g_Error = 0; g_TimeOut = Param->TimeOut; g_TxSize = * Param->TxSize; g_RxSize = Param->RxSize; * * return G_OK; * * } * */ // --2001 Modif // New G_SerPortOpen provided by Ludovic Rousseau. // THis function avoid EXPORT COM1= xxxxxx using. INT16 G_DECL G_SerPortOpen(const TGTSER_PORT G_FAR * Param) { INT16 handle; // used to set parameters in the device control block. struct termios current_termios; int x; if (port_fd >= 0) { return GE_HOST_PORT_OPEN; } handle = (INT16) (Param->Port - 1); if ((handle < 0) || (handle >= HGTSER_MAX_PORT)) { return (GE_HOST_PARAMETERS); } // Opening of comport.. its in separate block.. { char dev_name[PATH_MAX]; sprintf(dev_name, "/dev/ttyS%c", '0' + Param->Port - 1); port_fd = open(dev_name, O_RDWR); // O_NOCTTY was used // port_fd = open("/dev/cua0", O_RDWR|O_NOCTTY); DEBUG_MSG("Opening Device %s, handle=%d", dev_name, handle); } if (port_fd == COM_C_system_error) { DEBUG_MSG("Port Open Error."); return GE_HOST_PORT_INIT; } if (tcgetattr(port_fd, ¤t_termios) == COM_C_system_error) { close(port_fd); port_fd = -1; DEBUG_MSG("tcgetattr() function error."); return GE_HOST_PORT_INIT; } save_termios = current_termios; current_termios.c_iflag = 0; current_termios.c_oflag = 0; // Raw output modes current_termios.c_cflag = 0; // Raw output modes // Do not echo characters because if you connect // to a host it or your // modem will echo characters for you. // Don't generate signals. current_termios.c_lflag = 0; // control flow - enable receiver - ignore modem // control lines current_termios.c_cflag = CREAD | CLOCAL; x = CTRL_BAUD_RATE(Param->BaudRate); // DEBUG_MSG("Baud Rate=%d", x); switch ((int) CTRL_BAUD_RATE(Param->BaudRate)) { case 50: current_termios.c_cflag |= B50; break; case 75: current_termios.c_cflag |= B75; break; case 110: current_termios.c_cflag |= B110; break; case 134: current_termios.c_cflag |= B134; break; case 150: current_termios.c_cflag |= B150; break; case 200: current_termios.c_cflag |= B200; break; case 300: current_termios.c_cflag |= B300; break; case 600: current_termios.c_cflag |= B600; break; case 1200: current_termios.c_cflag |= B1200; break; case 1800: current_termios.c_cflag |= B1800; break; case 2400: current_termios.c_cflag |= B2400; break; case 4800: current_termios.c_cflag |= B4800; break; case 9600: current_termios.c_cflag |= B9600; break; case 19200: current_termios.c_cflag |= B19200; break; case 38400: current_termios.c_cflag |= B38400; break; default: current_termios.c_cflag |= B9600; break; } x = WORD_LEN(Param->Mode); // DEBUG_MSG("Word Len=%d", x); switch ((int) WORD_LEN(Param->Mode)) // number of databits { case 5: current_termios.c_cflag |= CS5; break; case 6: current_termios.c_cflag |= CS6; break; case 7: current_termios.c_cflag |= CS7; break; case 8: current_termios.c_cflag |= CS8; break; default: current_termios.c_cflag |= CS8; break; } x = PARITY(Param->Mode); // DEBUG_MSG("Parity = %d", x); switch ((int) PARITY(Param->Mode)) { case ODDPARITY: current_termios.c_cflag |= PARENB + PARODD; break; case EVENPARITY: current_termios.c_cflag |= PARENB; break; default: break; } x = STOP(Param->Mode); // DEBUG_MSG("Stop= %d", x); if (STOP(Param->Mode) == TWOSTOPBITS) // stop bits { current_termios.c_cflag |= CSTOPB; } // control caracteres // Minimum bytes to read // current_termios.c_cc[VMIN] = 0; // Time between two bytes read (VTIME x 0.10 s) // current_termios.c_cc[VTIME] = 0; // This is Non Canonical mode set. // by setting c_cc[VMIN]=0 and c_cc[VTIME] = 10 // each read operation will wait for 10*/10=1sec // If single byte is received, read function returns. // if timer expires, read() returns 0. // Minimum bytes to read current_termios.c_cc[VMIN] = 0; // Time between two bytes read (VTIME x 0.10 s) current_termios.c_cc[VTIME] = 10; if (tcsetattr(port_fd, TCSANOW, ¤t_termios) == COM_C_system_error) { close(port_fd); port_fd = -1; DEBUG_MSG("tcsetattr error"); return GE_HOST_PORT_INIT; } g_Counter = 1; g_Error = 0; g_TimeOut = Param->TimeOut; g_TxSize = Param->TxSize; g_RxSize = Param->RxSize; return G_OK; } INT16 G_DECL G_SerPortClose(const INT16 dum_Handle) { if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } tcflush(port_fd, TCIOFLUSH); // ///// CHECK #ifdef _LINUX_SOURCE // Restore the termios structure if (tcsetattr(port_fd, TCSANOW, &save_termios[port_config.Handle]) == COM_C_system_error) { #ifdef G_DBG DEBUG_MSG(" tcsetattr->errno=%d", errno); #endif // #ifdef G_DBG } #endif // ////// CHECK tcsetattr(port_fd, TCSANOW, &save_termios); close(port_fd); port_fd = -1; return G_OK; } INT16 G_DECL G_SerPortWrite (const INT16 dum_Handle, const WORD16 Length, const BYTE G_FAR Buffer[]) { INT32 iWriteStat; // set to TRUE if the WriteFile function // succeded WORD16 length = Length; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } iWriteStat = write(port_fd, (BYTE G_FAR *) Buffer, length); if ((WORD16) iWriteStat != length) { return GE_HOST_PORT_BREAK; } tcdrain(port_fd); // function here.. return G_OK; } INT16 G_DECL G_SerPortRead (const INT16 dum_Handle, WORD16 G_FAR * Length, BYTE G_FAR Buffer[]) { WORD16 length = 0, rlength = 0; INT32 iRetour, timeout; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } rlength = *Length; if (g_iNbByteRead > 0) { if (g_iNbByteRead > rlength) { length = rlength; } else { length = g_iNbByteRead; } memcpy(Buffer, g_szReadBuffer, length); g_iNbByteRead -= length; if (g_iNbByteRead > 0) { // For safer reason, can us simple for loop.. memcpy(g_szReadBuffer, g_szReadBuffer + length, g_iNbByteRead); } rlength -= length; } timeout = g_TimeOut; while ((rlength > 0) && (timeout > 0)) // && (response == G_OK)) { iRetour = read(port_fd, (BYTE G_FAR *) Buffer + length, rlength); if (iRetour == COM_C_system_error) { DEBUG_MSG("read::"); return GE_HOST_PARAMETERS; } else if (iRetour > 0) { rlength -= (WORD16) iRetour; length += (WORD16) iRetour; } else { struct pollfd filedes[1]; filedes[0].fd = 0; filedes[0].events = POLLNVAL; iRetour = poll(filedes, 1, 100); timeout -= 100; // AM000 initial value = 100 } } *Length = length; return G_OK; } INT16 G_DECL G_SerPortFlush(const INT16 dum_Handle, const WORD16 Select) { WORD16 select = Select; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } if (select & HGTSER_TX_QUEUE) { tcflush(port_fd, TCOFLUSH); } // ------------------------------------------------------- // If HGTSER_RX_QUEUE is selected // Then // Flushes the Rx queue by calling FlushComm. // Reset port_config.error field. // ------------------------------------------------------- if (select & HGTSER_RX_QUEUE) { tcflush(port_fd, TCIFLUSH); g_Error = 0; g_iNbByteRead = 0; } return G_OK; } INT16 G_DECL G_SerPortStatus (const INT16 dum_Handle, WORD16 G_FAR * TxLength, WORD16 G_FAR * RxLength, TGTSER_STATUS G_FAR * Status) { INT32 iReadStat; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } iReadStat = read(port_fd, &g_szReadBuffer[g_iNbByteRead], MAX_INPUT); if (iReadStat == COM_C_system_error) { DEBUG_MSG(" : read error"); return GE_HOST_PARAMETERS; } else { g_iNbByteRead += iReadStat; *RxLength = (WORD16) iReadStat; *TxLength = 0; } g_Error = 0; return G_OK; } INT16 G_DECL G_SerPortGetState (TGTSER_PORT G_FAR * Param, WORD16 G_FAR * UserNb) { struct termios current_termios; TGTSER_PORT port_param; memset(&port_param, 0, sizeof(TGTSER_PORT)); if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } if (tcgetattr(port_fd, ¤t_termios) == COM_C_system_error) { DEBUG_MSG(":tcgetattr error"); return GE_HOST_PORT_OS; } #if (defined _DEC_SOURCE) || (defined _LINUX_SOURCE) port_param.BaudRate = cfgetispeed(¤t_termios); // / CHECK THIS #else switch (current_termios.c_cflag & CBAUD) { case B50: port_param.BaudRate = 50; break; case B75: port_param.BaudRate = 75; break; case B110: port_param.BaudRate = 110; break; case B134: port_param.BaudRate = 134; break; case B150: port_param.BaudRate = 150; break; case B200: port_param.BaudRate = 200; break; case B300: port_param.BaudRate = 300; break; case B600: port_param.BaudRate = 600; break; case B1200: port_param.BaudRate = 1200; break; case B1800: port_param.BaudRate = 1800; break; case B2400: port_param.BaudRate = 2400; break; case B4800: port_param.BaudRate = 4800; break; case B9600: port_param.BaudRate = 9600; break; case B19200: port_param.BaudRate = 19200; break; case B38400: port_param.BaudRate = 38400; break; default: return GE_HOST_PORT_OS; } #endif switch (current_termios.c_cflag & CSIZE) { case CS5: port_param.Mode = HGTSER_WORD_5; break; case CS6: port_param.Mode = HGTSER_WORD_6; break; case CS7: port_param.Mode = HGTSER_WORD_7; break; case CS8: port_param.Mode = HGTSER_WORD_8; break; default: DEBUG_MSG("probleme nbits data inconnu !"); return GE_HOST_PORT_OS; } switch (current_termios.c_cflag & (PARENB + PARODD)) { case 0: port_param.Mode |= HGTSER_NO_PARITY; break; case PARENB: port_param.Mode |= HGTSER_EVEN_PARITY; break; case PARENB + PARODD: port_param.Mode |= HGTSER_ODD_PARITY; break; default: DEBUG_MSG("SerPortGetState : probleme parite inconnu !"); return GE_HOST_PORT_OS; } switch (current_termios.c_cflag & CSTOPB) { case 0: port_param.Mode |= HGTSER_STOP_BIT_1; break; case CSTOPB: port_param.Mode |= HGTSER_STOP_BIT_2; break; default: DEBUG_MSG("SerPrtGetState probleme stopbit inconnu !"); return GE_HOST_PORT_OS; } *UserNb = 1; memcpy(Param, &port_param, sizeof(TGTSER_PORT)); return G_OK; } INT16 G_DECL G_SerPortSetState(TGTSER_PORT G_FAR * Param) { struct termios current_termios; TGTSER_PORT port_param; // memset(&port_param, 0, sizeof(TGTSER_PORT)); // copying to local variable.. port_param = *Param; port_param = *Param; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } if (tcgetattr(port_fd, ¤t_termios) == COM_C_system_error) { DEBUG_MSG(":tcgetattr error"); return GE_HOST_PORT_INIT; } // iniz. input modes current_termios.c_iflag = 0; // iniz. output modes current_termios.c_oflag = 0; // iniz.control modes current_termios.c_cflag = 0; // iniz.local modes current_termios.c_lflag = 0; // CHECK THIS #if (defined _DEC_SOURCE) speed = (speed_t) CTRL_BAUD_RATE(port_param.BaudRate); cfsetispeed(¤t_termios, (speed_t) speed); cfsetospeed(¤t_termios, (speed_t) speed); #else // _DEC_SOURCE || _LINUX_SOURCE switch ((int) CTRL_BAUD_RATE(port_param.BaudRate)) { case 50: current_termios.c_cflag |= B50; break; case 75: current_termios.c_cflag |= B75; break; case 110: current_termios.c_cflag |= B110; break; case 134: current_termios.c_cflag |= B134; break; case 150: current_termios.c_cflag |= B150; break; case 200: current_termios.c_cflag |= B200; break; case 300: current_termios.c_cflag |= B300; break; case 600: current_termios.c_cflag |= B600; break; case 1200: current_termios.c_cflag |= B1200; break; case 1800: current_termios.c_cflag |= B1800; break; case 2400: current_termios.c_cflag |= B2400; break; case 4800: current_termios.c_cflag |= B4800; break; case 9600: current_termios.c_cflag |= B9600; break; case 19200: current_termios.c_cflag |= B19200; break; case 38400: current_termios.c_cflag |= B38400; break; default: current_termios.c_cflag |= B9600; break; } #endif // no. of data bits.. switch ((int) WORD_LEN(port_param.Mode)) { case 5: current_termios.c_cflag |= CS5; break; case 6: current_termios.c_cflag |= CS6; break; case 7: current_termios.c_cflag |= CS7; break; case 8: current_termios.c_cflag |= CS8; break; default: current_termios.c_cflag |= CS8; break; } // parity.. switch ((int) PARITY(port_param.Mode)) { case ODDPARITY: current_termios.c_cflag |= PARENB + PARODD; break; case EVENPARITY: current_termios.c_cflag |= PARENB; break; default: break; } if (STOP(port_param.Mode) == TWOSTOPBITS) current_termios.c_cflag |= CSTOPB; // control modes current_termios.c_cflag |= CREAD; // Enable receiver current_termios.c_cflag |= CLOCAL; // pas de gestion ligne modem // control caracteres // Non Canonical mode current_termios.c_cc[VMIN] = 0; // Minimum bytes to read current_termios.c_cc[VTIME] = 10; // Time between two bytes read (VTIME // x 0.10 s) if (tcsetattr(port_fd, TCSANOW, ¤t_termios) == COM_C_system_error) { close(port_fd); // should not make close call here.. port_fd = -1; DEBUG_MSG("SerPortSetSTate fn. tcsetattr() error"); return GE_HOST_PARAMETERS; } return G_OK; } INT16 G_DECL G_SerPortSetLineState (const INT16 dum_Handle, const BYTE Line, const INT32 Enable, const WORD32 Time) { int iRetour; int sStatLine; WORD32 time = Time; struct pollfd filedes[1]; INT32 enable = Enable; BYTE line = Line; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCGETA, &sStatLine); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMGET, &sStatLine); #endif // _HPUX_SOURCE if (iRetour != COM_C_system_error) { return GE_HOST_PARAMETERS; } switch (line) { case HGTSER_DTR_LINE: #ifdef _HPUX_SOURCE g_InitDtr = ((sStatLine & MDTR) == 0 ? DTR_CONTROL_DISABLE : DTR_CONTROL_ENABLE); if (enable) sStatLine |= MDTR; else sStatLine &= ~MDTR; #else // _HPUX_SOURCE g_InitDtr = ((sStatLine & TIOCM_DTR) == 0 ? DTR_CONTROL_DISABLE : DTR_CONTROL_ENABLE); if (enable) sStatLine |= TIOCM_DTR; else sStatLine &= ~TIOCM_DTR; #endif // _HPUX_SOURCE break; case HGTSER_RTS_LINE: #ifdef _HPUX_SOURCE g_InitRts = ((sStatLine & MRTS) == 0 ? RTS_CONTROL_DISABLE : RTS_CONTROL_ENABLE); if (enable) sStatLine |= MRTS; else sStatLine &= ~MRTS; #else // _HPUX_SOURCE g_InitRts = ((sStatLine & TIOCM_RTS) == 0 ? RTS_CONTROL_DISABLE : RTS_CONTROL_ENABLE); if (enable) sStatLine |= TIOCM_RTS; else sStatLine &= ~TIOCM_RTS; #endif // _HPUX_SOURCE break; default: return GE_HOST_PARAMETERS; } #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCSETA, &sStatLine); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMSET, &sStatLine); #endif // _HPUX_SOURCE if ((time > 0) && (iRetour != COM_C_system_error)) { filedes[0].fd = port_fd; // previously it was 0. filedes[0].events = POLLNVAL; poll(filedes, 1, time); switch (line) { case HGTSER_DTR_LINE: #ifdef _HPUX_SOURCE if (g_InitDtr != DTR_CONTROL_DISABLE) sStatLine |= MDTR; else sStatLine &= ~MDTR; #else // _HPUX_SOURCE if (g_InitDtr != DTR_CONTROL_DISABLE) sStatLine |= TIOCM_DTR; else sStatLine &= ~TIOCM_DTR; #endif // _HPUX_SOURCE break; case HGTSER_RTS_LINE: #ifdef _HPUX_SOURCE if (g_InitDtr != RTS_CONTROL_DISABLE) sStatLine |= MRTS; else sStatLine &= ~MRTS; #else // _HPUX_SOURCE if (g_InitDtr != RTS_CONTROL_DISABLE) sStatLine |= TIOCM_RTS; else sStatLine &= ~TIOCM_RTS; #endif // _HPUX_SOURCE break; } #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCSETA, &sStatLine); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMSET, &sStatLine); #endif // _HPUX_SOURCE } if (iRetour != COM_C_system_error) { return G_OK; } else { return GE_UNKNOWN_PB; } } INT16 G_DECL G_SerPortGetLineState (const INT16 dum_Handle, const BYTE Line, INT32 G_FAR * Enable) { int iRetour; #ifdef _HPUX_SOURCE mflag #else // _HPUX_SOURCE int #endif // _HPUX_SOURCE sStatLine; INT32 enable = 0; BYTE line = Line; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCGETA, &sStatLine); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMGET, &sStatLine); #endif // _HPUX_SOURCE if (iRetour == COM_C_system_error) { DEBUG_MSG("GetPortLineState: ioctl fails"); return GE_HOST_PARAMETERS; } switch (line) { case HGTSER_DTR_LINE: #ifdef _HPUX_SOURCE enable = ((sStatLine &= MDTR) == MDTR); #else // _HPUX_SOURCE enable = ((sStatLine &= TIOCM_DTR) == TIOCM_DTR); #endif // _HPUX_SOURCE break; case HGTSER_RTS_LINE: #ifdef _HPUX_SOURCE enable = ((sStatLine &= MRTS) == MRTS); #else // _HPUX_SOURCE enable = ((sStatLine &= TIOCM_RTS) == TIOCM_RTS); #endif // _HPUX_SOURCE break; default: return GE_HOST_PARAMETERS; } *Enable = enable; return G_OK; } #ifdef _HPUX_SOURCE static mflag #else static int #endif g_com_status = 0; // holds the status line of serial port INT16 G_DECL G_SerPortSetEvent( const INT16 dum_Handle, const WORD16 Event) { int iRetour; WORD16 event = Event; if (port_fd < 0) { return GE_HOST_PORT_CLOSE; } #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCGETA, &g_com_status); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMGET, &g_com_status); #endif // _HPUX_SOURCE if (iRetour == COM_C_system_error) { DEBUG_MSG("SerPortSetEvent error in ioctl"); return GE_HOST_PARAMETERS; } switch (event) { case HGTSER_RI_LINE: #ifdef _HPUX_SOURCE g_com_status |= MRI; #elif _LINUX_SOURCE g_com_status |= TIOCM_RI; #endif // _HPUX_SOURCE break; case HGTSER_DCD_LINE: case HGTSER_CTS_LINE: case HGTSER_DSR_LINE: default: break; } return G_OK; } INT16 G_DECL G_SerPortGetEvent (const INT16 dum_Handle, const WORD16 Event, INT32 G_FAR * Found) { int iRetour; #ifdef _HPUX_SOURCE mflag #else // _HPUX_SOURCE int #endif // _HPUX_SOURCE sStatLine; WORD16 event = Event; INT32 found = *Found; #ifdef _HPUX_SOURCE iRetour = ioctl(port_fd, MCGETA, &sStatLine); #else // _HPUX_SOURCE iRetour = ioctl(port_fd, TIOCMGET, &sStatLine); #endif // _HPUX_SOURCE if (iRetour == COM_C_system_error) { DEBUG_MSG("G_SerPortGetEvent() ioctl failed"); return GE_HOST_PARAMETERS; } switch (event) { case HGTSER_RI_LINE: #ifdef _HPUX_SOURCE found = ((g_com_status & MRI) != (sStatLine & MRI)); #else // _HPUX_SOURCE found = ((g_com_status & TIOCM_RI) != (sStatLine & TIOCM_RI)); #endif // _HPUX_SOURCE break; case HGTSER_DCD_LINE: #ifdef _HPUX_SOURCE found = ((g_com_status & MDCD) != (sStatLine & MDCD)); #else // _HPUX_SOURCE found = ((g_com_status & TIOCM_CD) != (sStatLine & TIOCM_CD)); #endif // _HPUX_SOURCE break; case HGTSER_CTS_LINE: #ifdef _HPUX_SOURCE found = ((g_com_status & MCTS) != (sStatLine & MCTS)); #else // _HPUX_SOURCE found = ((g_com_status & TIOCM_CTS) != (sStatLine & TIOCM_CTS)); #endif // _HPUX_SOURCE break; case HGTSER_DSR_LINE: #ifdef _HPUX_SOURCE found = ((g_com_status & MDSR) != (sStatLine & MDSR)); #else // _HPUX_SOURCE found = ((g_com_status & TIOCM_DSR) != (sStatLine & TIOCM_DSR)); #endif // _HPUX_SOURCE break; default: return GE_HOST_PARAMETERS; } *Found = found; return G_OK; } INT16 G_DECL G_SerPortSetTimeouts(const INT16 Handle, DWORD BWT) { return G_OK; } libgcr410-2.4.0.orig/gtgbp.c0100644000175000017500000006375507354047734013074 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GTGBP.C * * Description : This module holds the functions needed for communication on a * serial line according to Gemplus Block protocol. * * Author : * Compiler : * * Host : * Release : 4.31.002 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Information section: - G_NAME is set to "GtGbp" - G_RELEASE is set to "4.31.002" ------------------------------------------------------------------------------*/ #define G_NAME "GtGbp" #define G_RELEASE "4.31.002" /*------------------------------------------------------------------------------ Pragma section - comment is called if _MSC_VER is defined. ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #include "gemgcr.h" #include "gtser.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "debug.h" /*------------------------------------------------------------------------------ Module public interface. - gtgbp.h ------------------------------------------------------------------------------*/ #include "gtgbp.h" /*------------------------------------------------------------------------------ Constant section: - IBLOCK_PCB (0x00) and IBLOCK_MASK (0xA0) are used to detect the I-Block PCB signature (0x0xxxxxb). - IBLOCK_SEQ_POS indicates the number of left shift to apply to 0000000xb for x to be the sequence bit for a I-Block. - RBLOCK_PCB (0x80) and RBLOCK_MASK (0xEC) are used to detect the R-Block PCB signature (100x00xx). - RBLOCK_SEQ_POS indicates the number of left shift to apply to 0000000xb for x to be the sequence bit for a R-Block. - ERR_OTHER and ERR_EDC are the error bits in a R-Block PCB. - RESYNCH_REQUEST (0xC0) and RESYNCH_RESPONSE (0xE0) are the PCB used in S-Blocks. ------------------------------------------------------------------------------*/ #define IBLOCK_PCB 0x00 #define IBLOCK_MASK 0xA0 #define IBLOCK_SEQ_POS 0x06 #define RBLOCK_PCB 0x80 #define RBLOCK_MASK 0xEC #define RBLOCK_SEQ_POS 0x04 #define ERR_OTHER 0x02 #define ERR_EDC 0x01 #define RESYNCH_REQUEST 0xC0 #define RESYNCH_RESPONSE 0xE0 /*------------------------------------------------------------------------------ Macro section: - HOST2IFD (Handle) returns the NAD byte for message from Host to IFD. - IFD2HOST (Handle) returns the NAD byte awaited in an IFD message. - MK_IBLOCK_PCB (x) builds an I-Block PCB where x is the channel handle. - MK_RBLOCK_PCB (x) builds an R-Block PCB where x is the channel handle. - ISA_IBLOCK_PCB (x) return TRUE if the given parameter is a I-Block PCB. - ISA_RBLOCK_PCB (x) return TRUE if the given parameter is a R-Block PCB. - SEQ_IBLOCK (x) return the state of the sequence bit: 0 or 1. - INC_SEQUENCE (x) increment a sequence bit: 0 -> 1 and 1 -> 0. ------------------------------------------------------------------------------*/ #define HOST2IFD ((WORD8) \ ( \ (g_IFDAdd << 4) \ + g_HostAdd \ ) \ ) #define IFD2HOST ((WORD8) \ ( \ (g_HostAdd << 4) \ + g_IFDAdd \ ) \ ) #define MK_IBLOCK_PCB ((WORD8) \ ( \ IBLOCK_PCB \ + (g_SSeq << IBLOCK_SEQ_POS) \ ) \ ) #define MK_RBLOCK_PCB ((WORD8) \ ( \ RBLOCK_PCB \ + (g_RSeq << RBLOCK_SEQ_POS) \ + g_Error \ ) \ ) #define ISA_IBLOCK_PCB(x) (((x) & IBLOCK_MASK) == IBLOCK_PCB) #define ISA_RBLOCK_PCB(x) (((x) & RBLOCK_MASK) == RBLOCK_PCB) #define SEQ_IBLOCK(x) (((x) & (0x01 << IBLOCK_SEQ_POS)) >> IBLOCK_SEQ_POS) #define INC_SEQUENCE(x) (x) = (WORD8)(((x) + 1) % 2) /*------------------------------------------------------------------------------ * HostAdd holds the address identifier for the host in 0..15. * IFDAdd holds the address identifier for the associated IFD in 0..15. * PortCom holds the serial port number * SSeq holds the sequence bit for the next I-Block to send: 0 or 1. * RSeq holds the awaited sequence bit: 0 or 1. * Error gathers the encountered error conditions. ------------------------------------------------------------------------------*/ WORD8 g_UserNb; WORD8 g_HostAdd; WORD8 g_IFDAdd; INT16 g_PortCom; WORD8 g_SSeq; WORD8 g_RSeq; WORD8 g_Error; /*------------------------------------------------------------------------------ Global variable section (Shared): - gtgbp_channel[MAX_IFD_CHANNEL] is an array of TGTGBP_CHANNEL which memorises the communication parameters for each opened channel. - handle_GBP is a conversion for the logical channel to the GBP channel. ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ Force the DLL to share this data section (only with WIN32) ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ Function definition section: ------------------------------------------------------------------------------*/ /******************************************************************************* * INT16 G_DECL G_GBPOpen * ( * const WORD16 HostAdd, * const WORD16 IFDAdd, * const INT16 PortCom * ) * * Description : * ------------- * This function initialises internal variables for communicating in Gemplus * Block protocol through a serial port. * This function must be called before any other in this module. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * - HostAdd is the host address. A valid value must be in 0.. 15. The memorised * value is (HostAdd mod 16). * - AFDAdd is the IFD address. A valid value must be in 0.. 15. The memorised * value is (IFDAdd mod 16). * This value should be different from the HostAdd. * - PortCom holds the serial port number * * Out : * ------------- * Nothing. * * Responses : * ------------- * If everything is Ok: * G_OK ( 0). * If an error condition is raised: * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read and the selected channel is eventually updated. *******************************************************************************/ INT16 G_DECL G_GBPOpen (const WORD16 rHostAdd, const WORD16 rIFDAdd, const INT16 rPortCom) { /*------------------------------------------------------------------------------ Local Variable: - cptHandleLog holds the counter to scan structure - present indicate if the trio (HostAdd, IFDAdd, PortCom) exist ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ The given parameters are controlled: <= Test Handle parameter (0 <= HostAdd < MAX_IFD_CHANNEL): GE_HOST_PARAMETERS ------------------------------------------------------------------------------*/ if ((rHostAdd <= 0) || (rHostAdd >= MAX_IFD_CHANNEL)) { return (GE_HOST_PARAMETERS); } /*------------------------------------------------------------------------------ The given parameters are controlled: <= Test Handle parameter (0 <= IFDAdd < MAX_IFD_CHANNEL): GE_HOST_PARAMETERS ------------------------------------------------------------------------------*/ if ((rIFDAdd <= 0) || (rIFDAdd >= MAX_IFD_CHANNEL)) { return (GE_HOST_PARAMETERS); } /*------------------------------------------------------------------------------ The given parameters are controlled: <= Test Handle parameter (rHostAdd!=IFDAdd): GE_HOST_PARAMETERS ------------------------------------------------------------------------------*/ if (rHostAdd == rIFDAdd) { return (GE_HOST_PARAMETERS); } g_UserNb = 1; g_HostAdd = (WORD8) (rHostAdd & 0x000F); g_IFDAdd = (WORD8) (rIFDAdd & 0x000F); g_PortCom = rPortCom; g_SSeq = 0; g_RSeq = 0; g_Error = 0; /*------------------------------------------------------------------------------ <= G_OK ------------------------------------------------------------------------------*/ return (G_OK); } /******************************************************************************* * INT16 G_DECL G_GBPClose * ( * ) * * Description : * ------------- * This function resets internal variables for communicating in Gemplus Block * protocol through a serial port. * This function must be called for each opened channel (G_GBPOpen). * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * * Out : * ------------- * Nothing. * * Responses : * ------------- * If everything is Ok: * G_OK ( 0). * If an error condition is raised: * - GE_HOST_PORT_CLOSE (-412) if the selected channel has not been opened. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read and the selected channel is eventually updated. *******************************************************************************/ INT16 G_DECL G_GBPClose() { if (g_UserNb == 0) { return (GE_HOST_PORT_CLOSE); } g_UserNb = 0; return (G_OK); } /******************************************************************************* * INT16 G_DECL G_GBPBuildIBlock * ( * const WORD16 CmdLen, * const WORD8 G_FAR Cmd[], * WORD16 G_FAR *MsgLen, * WORD8 G_FAR Msg[] * ) * * Description : * ------------- * This function takes a command and builds an Information Gemplus Block * Protocol. * * Remarks : * ------------- * When this command is successful, the send sequence bit is updated for the next * exchange. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * - CmdLen indicates the number of bytes in the Cmd buffer. * This value must be lower than HGTGBP_MAX_DATA (Today 254). * - Cmd holds the command bytes. * - MsgLen indicates the number of available bytes in Msg. * This value must be at least 4 + CmdLen to allow to build the message. * * Out : * ------------- * - MsgLen and Msg are updated with the message length and the message bytes. * * Responses : * ------------- * If everything is Ok: * G_OK ( 0). * If an error condition is raised: * - GE_HI_CMD_LEN (-313) if the CmdLen is greater than HGTGBP_MAX_DATA or * if MsgLen is too small to receive the built message. * - GE_HOST_PORT_CLOSE (-412) if the selected channel has not been opened. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read. *******************************************************************************/ INT16 G_DECL G_GBPBuildIBlock (const WORD16 CmdLen, const WORD8 G_FAR Cmd[], WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]) { /*------------------------------------------------------------------------------ Local variable: - edc receives the exclusive or between all the character from to the last data byte. - i is the index which allows to read each Cmd byte. - j is the index which allows to write each Msg byte. It indicates the next free position in this buffer and is initialized to 0. ------------------------------------------------------------------------------*/ WORD8 edc; WORD16 i, j = 0; /*------------------------------------------------------------------------------ <= Test channel state (UserNb different from 0): GE_HOST_PORT_CLOSE ------------------------------------------------------------------------------*/ if (g_UserNb == 0) { return (GE_HOST_PORT_CLOSE); } /*------------------------------------------------------------------------------ <= Test CmdLen (<= HGTGBP_MAX_DATA) and MsgLen (>= 4 + CmdLen): GE_HI_CMD_LEN. Msg must be able to receive the following GBP block [ Data ...] ------------------------------------------------------------------------------*/ if ((CmdLen > HGTGBP_MAX_DATA) || (*MsgLen < CmdLen + 4)) { return (GE_HI_CMD_LEN); } /*------------------------------------------------------------------------------ The message is built: NAD holds Target address in high part and Source address in low part. PCB holds I-Block mark: 0 SSeq 0 x x x x x Len is given by CmdLen [.. Data ..] are stored in Cmd. EDC is an exclusive or of all the previous bytes. It is updated when Msg buffer is updated. ------------------------------------------------------------------------------*/ edc = Msg[j++] = HOST2IFD; edc ^= Msg[j++] = MK_IBLOCK_PCB; edc ^= Msg[j++] = (WORD8) CmdLen; for (i = 0; i < CmdLen; i++) { edc ^= Msg[j++] = Cmd[i]; } Msg[j++] = edc; /*------------------------------------------------------------------------------ MsgLen is updated with the number of bytes written in Msg buffer. ------------------------------------------------------------------------------*/ *MsgLen = (WORD16) j; /*------------------------------------------------------------------------------ The sequence number is updated for the next exchange. ------------------------------------------------------------------------------*/ INC_SEQUENCE(g_SSeq); /*------------------------------------------------------------------------------ <= G_OK ------------------------------------------------------------------------------*/ return (G_OK); } /******************************************************************************* * INT16 G_DECL G_GBPBuildRBlock * ( * WORD16 G_FAR *MsgLen, * WORD8 G_FAR Msg[] * ) * * Description : * ------------- * This function builds a Repeat Gemplus Block Protocol. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * - MsgLen indicates the number of available bytes in Msg. * This value must be at least 4 to allow to build the message. * * Out : * ------------- * - MsgLen and Msg are updated with the message length and the message bytes. * * Responses : * ------------- * If everything is Ok: * G_OK ( 0). * If an error condition is raised: * - GE_HI_CMD_LEN (-313) if MsgLen is too small to receive the built * message. * - GE_HOST_PORT_CLOSE (-412) if the selected channel has not been opened. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read. *******************************************************************************/ INT16 G_DECL G_GBPBuildRBlock(WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]) { WORD8 edc; WORD16 j = 0; if (g_UserNb == 0) { return (GE_HOST_PORT_CLOSE); } if (*MsgLen < 4) { return (GE_HI_CMD_LEN); } edc = Msg[j++] = HOST2IFD; // (handle_GBP[Handle]); edc ^= Msg[j++] = MK_RBLOCK_PCB; // (handle_GBP[Handle]); edc ^= Msg[j++] = 0; Msg[j++] = edc; *MsgLen = (WORD16) j; return (G_OK); } /******************************************************************************* * INT16 G_DECL G_GBPBuildSBlock * ( * WORD16 G_FAR *MsgLen, * WORD8 G_FAR Msg[] * ) * * Description : * ------------- * This function builds a Synchro request Gemplus Block Protocol. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * - MsgLen indicates the number of available bytes in Msg. * This value must be at least 4 to allow to build the message. * * Out : * ------------- * - MsgLen and Msg are updated with the message length and the message bytes. * * Responses : * ------------- * If everything is Ok: * G_OK ( 0). * If an error condition is raised: * - GE_HI_CMD_LEN (-313) if MsgLen is too small to receive the built * message. * - GE_HOST_PORT_CLOSE (-412) if the selected channel has not been opened. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read. *******************************************************************************/ INT16 G_DECL G_GBPBuildSBlock(WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]) { WORD8 edc; WORD16 j = 0; if (g_UserNb == 0) { return (GE_HOST_PORT_CLOSE); } if (*MsgLen < 4) { return (GE_HI_CMD_LEN); } edc = Msg[j++] = HOST2IFD; // (handle_GBP[Handle]); edc ^= Msg[j++] = RESYNCH_REQUEST; edc ^= Msg[j++] = 0; Msg[j++] = edc; *MsgLen = (WORD16) j; return (G_OK); } /******************************************************************************* * INT16 G_DECL G_GBPDecodeMessage * ( * const WORD16 MsgLen, * const WORD8 G_FAR Msg[], * WORD16 G_FAR *RspLen, * WORD8 G_FAR Rsp[] * ) * * Description : * ------------- * This function takes a Gemplus Block Protocol message and extract the response * from it. * * Remarks : * ------------- * The awaited sequence bit is updated when a valid I-Block has been received. * The sequence bits are reseted when a valid RESYNCH RESPONSE has been received. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * - MsgLen indicates the number of bytes in the Msg buffer. * - Msg holds the command bytes. * - RspLen indicates the number of available bytes in Msg. * * Out : * ------------- * - RspLen and Rsp are updated with the response length and the response bytes. * * Responses : * ------------- * If everything is Ok: * G_OK (0). * If an error condition is raised: * - GE_HI_LRC (-302) if an EDC error has been detected. * - GE_HI_LEN (-311) if a bad value has been detected in LN field * or if the response buffer is too small. * - GE_HI_FORMAT (-312) if the received message is neither I-Block, * neither R-Block and neither S-Block. * - GE_HI_NACK (-314) if a R-Block has been received. * - GE_HI_RESYNCH (-315) if a S-Block has been received. * - GE_HI_ADDRESS (-316) if the NAD is not valid for the selected channel. * - GE_HI_SEQUENCE (-317) if a bad sequence number has been received. * - GE_HOST_PORT_CLOSE (-412) if the selected channel has not been opened. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the valid range. * Extern var : ------------- Nothing. Global var : ------------- gtgbp_channel is read and the selected channel is eventually updated. *******************************************************************************/ INT16 G_DECL G_GBPDecodeMessage (const WORD16 MsgLen, const WORD8 G_FAR Msg[], WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]) { /*------------------------------------------------------------------------------ Local variables: - edc receives the exclusive or between all the character from to the last data byte. - j will point on next free byte in Rsp. - response is updated with the function status. ------------------------------------------------------------------------------*/ WORD8 edc; WORD16 j; INT16 response; /*------------------------------------------------------------------------------ <= Test channel state (UserNb different from 0): GE_HOST_PORT_CLOSE ------------------------------------------------------------------------------*/ if (g_UserNb == 0) { *RspLen = 0; return (GE_HOST_PORT_CLOSE); } /*------------------------------------------------------------------------------ Reset the associated error field. ------------------------------------------------------------------------------*/ g_Error = 0; /*------------------------------------------------------------------------------ Verifies the message frame and copies the data bytes: <= Test NAD (HostAdd | IFDAdd): GE_HI_ADDRESS ------------------------------------------------------------------------------*/ if (Msg[0] != IFD2HOST) { *RspLen = 0; return (GE_HI_ADDRESS); } edc = Msg[0]; /*------------------------------------------------------------------------------ Updates response variable with the PCB type: - GE_HI_RESYNCH if a S-Block has been detected - GE_HI_NACK if a T-Block has been detected ------------------------------------------------------------------------------*/ if (Msg[1] == RESYNCH_RESPONSE) { response = GE_HI_RESYNCH; } else if (ISA_RBLOCK_PCB(Msg[1])) { response = GE_HI_NACK; } /*------------------------------------------------------------------------------ - For I-Block <= Test PCB sequence bit: GE_HI_SEQUENCE ------------------------------------------------------------------------------*/ else if (ISA_IBLOCK_PCB(Msg[1])) { if ((WORD8) SEQ_IBLOCK(Msg[1]) != g_RSeq) { return (GE_HI_SEQUENCE); } response = G_OK; } /*------------------------------------------------------------------------------ - For other cases <= GE_HI_FORMAT ------------------------------------------------------------------------------*/ else { return (GE_HI_FORMAT); } edc ^= Msg[1]; /*------------------------------------------------------------------------------ <= Test Len (Len + 4 = MsgLen and RspLen >= Len): GE_HI_LEN This error update the Error.other bit. ------------------------------------------------------------------------------*/ if (((WORD16) Msg[2] > *RspLen)) { *RspLen = 0; g_Error |= ERR_OTHER; DEBUG_MSG("G_GBPDecod returning GE_HI_LEN: resplen not match\n"); return (GE_HI_LEN); } if ((WORD16) (Msg[2] + 4) != MsgLen) { *RspLen = 0; g_Error |= ERR_OTHER; DEBUG_MSG("G_GBPDecod returning GE_HI_LEN: msg len not match\n"); return (GE_HI_LEN); } edc ^= Msg[2]; /*------------------------------------------------------------------------------ Copies the data bytes, updates RspLen and calculated edc. ------------------------------------------------------------------------------*/ *RspLen = (WORD16) Msg[2]; for (j = 0; j < *RspLen; j++) { Rsp[j] = Msg[j + 3]; edc ^= Rsp[j]; } /*------------------------------------------------------------------------------ <= Test the read EDC: GE_HI_LRC This error update the Error.EDC bit. ------------------------------------------------------------------------------*/ if (edc != Msg[j + 3]) { *RspLen = 0; g_Error |= ERR_EDC; return (GE_HI_LRC); } /*------------------------------------------------------------------------------ Updates the awaited sequence bit when a valid I-Block has been received. ------------------------------------------------------------------------------*/ if (response == G_OK) { INC_SEQUENCE(g_RSeq); } /*------------------------------------------------------------------------------ Reset the sequence bits when a valid S-Block has been received. ------------------------------------------------------------------------------*/ else if (response == GE_HI_RESYNCH) { g_SSeq = g_RSeq = 0; } /*------------------------------------------------------------------------------ <= GE_HI_RESYNCH / GE_HI_NACK / G_OK ------------------------------------------------------------------------------*/ return (response); } /******************************************************************************* * INT16 G_DECL G_GBPChannelToPortComm * ( * const INT16 Handle * ) * * Description : * ------------- * This function return a physical port associate with the Logical Channel * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the communication handle to associate to the channel. * * Out : * ------------- * Nothing. * * Responses : * ------------- Extern var : ------------- Nothing. Global var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL G_GBPChannelToPortComm() { if (g_UserNb == 0) { return (GE_HOST_PORT_CLOSE); } return (g_PortCom); } libgcr410-2.4.0.orig/gtgbp.h0100644000175000017500000000434607354047734013070 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GTGBP.H * * Description : This module holds the function needed for communication on a * serial line according to Gemplus Block Protocol. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Constant section: HGTGBPP maximal size for a message: ------------------------------------------------------------------------------*/ #define HGTGBP_MAX_DATA 255 #define HGTGBP_MAX_BUFFER_SIZE HGTGBP_MAX_DATA + 4 /*------------------------------------------------------------------------------ Prototype section: ------------------------------------------------------------------------------*/ INT16 G_DECL G_GBPOpen (const WORD16 HostAdd, const WORD16 IFDAdd, const INT16 PortCom); INT16 G_DECL G_GBPClose(); INT16 G_DECL G_GBPBuildIBlock (const WORD16 CmdLen, const WORD8 G_FAR Cmd[], WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]); INT16 G_DECL G_GBPBuildRBlock(WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]); INT16 G_DECL G_GBPBuildSBlock(WORD16 G_FAR * MsgLen, WORD8 G_FAR Msg[]); INT16 G_DECL G_GBPDecodeMessage (const WORD16 MsgLen, const WORD8 G_FAR Msg[], WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]); INT16 G_DECL G_GBPChannelToPortComm(); libgcr410-2.4.0.orig/gtser.h0100644000175000017500000002006007354047734013100 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * Name : GTSer.h * * Description : This module allows serial port management. * * Release : 4.31.001 * * Last Modif : 10/12/97: V4.31.001 New definitinons for OS2 Warp * 14/10/97: V4.31.001 * HGTSER_MAX_PORT is set to 16. * 04/09/96: V4.20.001 * 12/04/96: V4.20.000 * Add functions for Windows 32 bits. * 15/05/95: V4.10.001 * Add functions for line state analysis. * 22/03/95: V4.01.00 * Card detection implementation. * G_SerPortSetDetect and G_SerPortGetDetect. * 16/09/94: V4.00 * Date : 15/07/94: V4.00 * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GTSER_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GTSER_H #define _GTSER_H /*------------------------------------------------------------------------------ Constant section: - HGTSER_MAX_PORT holds the number of managed port. Today 16. - HGTSER_WORD_5, HGTSER_WORD_6, HGTSER_WORD_7 and HGTSER_WORD_8 allow to configure the number of bits per word. - HGTSER_STOP_BIT_1 and HGTSER_STOP_BIT_2 allow to configure the number of stop bit. - HGTSER_NO_PARITY, HGTSER_ODD_PARITY and HGTSER_EVEN_PARITY allow to configure the communication parity. - HGTSER_TX_QUEUE and HGTSER_RX_QUEUE are queues indentifiers. - HGTSER_RX_OVER is set when the reception queue is full and characters has been lost. - HGTSER_RTS_LINE is identifier of RTS line for Line status functions. - HGTSER_DTR_LINE is identifier of DTR line for Line status functions. - HGTSER_EV_RING is identifier of EV_RING line for Line status functions. ------------------------------------------------------------------------------*/ #define HGTSER_MAX_PORT 16 #define HGTSER_WORD_5 0x00 #define HGTSER_WORD_6 0x01 #define HGTSER_WORD_7 0x02 #define HGTSER_WORD_8 0x03 #define HGTSER_STOP_BIT_1 0x00 #define HGTSER_STOP_BIT_2 0x04 #define HGTSER_NO_PARITY 0x00 #define HGTSER_ODD_PARITY 0x08 #define HGTSER_EVEN_PARITY 0x18 #define HGTSER_TX_QUEUE 1 #define HGTSER_RX_QUEUE 2 #define HGTSER_RX_OVER 1 #define HGTSER_RTS_LINE 0 #define HGTSER_DTR_LINE 1 #ifndef G_UNIX #define HGTSER_EV_RING 2 #else #define HGTSER_CTS_LINE 2 #define HGTSER_DSR_LINE 3 #define HGTSER_RI_LINE 4 #define HGTSER_DCD_LINE 5 #endif #ifdef G_OS2 #define EV_RECEP 1 #define EV_TIMEOUT 2 #define EV_TXFIN 4 #define EV_CTS 8 #define EV_DSR 16 #define EV_DCD 32 #define EV_BREAK 64 #define EV_ERROR 128 #ifdef EV_RING #undef EV_RING #endif #define EV_RING 256 #endif /* * G_OS2 */ /*------------------------------------------------------------------------------ Constant section: - WTX_TIMEOUT is the time out used when a WTX REQUEST is send by the CT. - CHAR_TIMEOUT is the timeout at character level: today 1000 ms. ------------------------------------------------------------------------------*/ #define WTX_TIMEOUT 3000 #define CHAR_TIMEOUT 1000 /*------------------------------------------------------------------------------ Type section: - TGTSER_PORT gathers data used to manage a serial port: * Port indicates the selected port. G_COM1, G_COM2, G_COM3 or G_COM4 * BaudRate is used to set port baud rate when open routine is called. 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 * ITNumber indicates the interrupt number to use. The 0XFF value indicates the default value. Allowed number are from 0 to 15. * Mode Memorises WORD size : 5, 6, 7 or 8 stop bit number : 1 or 2 parity : no parity, odd or even parity * TimeOut indicates the time out value, in milli-seconds, at character level. * TxSize is the transmit buffer size, in bytes. * RxSize is the reception buffer size, in mbytes. ------------------------------------------------------------------------------*/ typedef struct { INT16 Port; WORD32 BaudRate; WORD16 ITNumber; WORD16 Mode; WORD16 TimeOut; WORD16 TxSize; WORD16 RxSize; } TGTSER_PORT; /*------------------------------------------------------------------------------ - TGTSER_STATUS holds status bit about the serial communication. Today only HGTSER_RX_OVER can be set or not. ------------------------------------------------------------------------------*/ typedef WORD16 TGTSER_STATUS; #if !(defined G_LINUX) || !(defined G_UNIX) /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototypes section: ------------------------------------------------------------------------------*/ void G_DECL gtser ( INT16 G_FAR * NameLength, char G_FAR Name[], INT16 G_FAR * ReleaseLength, char G_FAR Release[]); INT16 G_DECL G_SerPortOpen(const TGTSER_PORT G_FAR * Param); INT16 G_DECL G_SerPortClose(const INT16 Handle); INT16 G_DECL G_SerPortLockAccess(const INT16 Handle); INT16 G_DECL G_SerPortUnlockAccess(const INT16 Handle); INT16 G_DECL G_SerPortWrite (const INT16 Handle, const WORD16 Length, const BYTE G_FAR Buffer[]); INT16 G_DECL G_SerPortRead (const INT16 Handle, WORD16 G_FAR * Length, BYTE G_FAR Buffer[]); INT16 G_DECL G_SerPortFlush(const INT16 Handle, const WORD16 Select); INT16 G_DECL G_SerPortStatus (const INT16 Handle, WORD16 G_FAR * TxLength, WORD16 G_FAR * RxLength, TGTSER_STATUS G_FAR * Status); INT16 G_DECL G_SerPortSwitch(const INT16 Handle, const WORD16 Channel); INT16 G_DECL G_SerPortAddUser(const INT16 Port); INT16 G_DECL G_SerPortGetState (TGTSER_PORT G_FAR * Param, WORD16 G_FAR * UserNb); INT16 G_DECL G_SerPortSetState(TGTSER_PORT G_FAR * Param); INT16 G_DECL G_SerPortSetLineState(const INT16 Handle, const BYTE Line, #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) const INT32 Enable, #else const BOOL Enable, #endif const WORD32 Time); INT16 G_DECL G_SerPortGetLineState(const INT16 Handle, const BYTE Line, #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) INT32 G_FAR * Enable #else BOOL G_FAR * Enable #endif ); INT16 G_DECL G_SerPortSetEvent(const INT16 Handle, const WORD16 Event); INT16 G_DECL G_SerPortGetEvent(const INT16 Handle, const WORD16 Event, #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) INT32 G_FAR * Found #else BOOL G_FAR * Found #endif ); INT16 G_DECL G_SerPortSetTimeouts(const INT16 Handle, DWORD BWT); INT32 G_DECL G_SerPortAttach(void); void G_DECL G_SerPortDetach( void); INT32 G_DECL G_SerPortLockComm (const INT16 Handle, const DWORD WaitRelease); void G_DECL G_SerPortUnlockComm( const INT16 Handle); #ifdef __cplusplus } #endif #endif #endif libgcr410-2.4.0.orig/gttimout.c0100644000175000017500000001567307354047734013641 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GTTIMOUT.C * * Description : This module manages time out under DOS and WINDOWS. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Information section - G_NAME is set to "GtTimOut" - G_RELEASE is set to "4.31.002" ------------------------------------------------------------------------------*/ #define G_NAME "GtTimOut" #define G_RELEASE "4.31.002" /*------------------------------------------------------------------------------ Pragma section - comment is called if _MSC_VER is defined. ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif /*------------------------------------------------------------------------------ Compatibility section - CLK_TCK, clock_t and clock() are redefined to have a single writing for both DOS and WINDOWS environment. ------------------------------------------------------------------------------*/ #ifdef G_WINDOWS #define CLK_TCK 1000.0 #define clock_t WORD32 #define clock() GetTickCount() #endif /*------------------------------------------------------------------------------ Include section Environment include: - windows.h gives general Windows 3.1 macros, values and functions. STRICT keyword is used to verify stricly variable types. This file is include only if windows version is required. ------------------------------------------------------------------------------*/ #ifdef G_WINDOWS #define STRICT #include #endif #ifdef G_OS2 #include #endif /*------------------------------------------------------------------------------ Compiler include: - time.h is used for clock function under DOS environment. This file is include only if windows version is disabled. ------------------------------------------------------------------------------*/ #ifndef G_WINDOWS #include #endif /*------------------------------------------------------------------------------ Gemplus includes: - gemplus.h is used to define general macros and values. - gemansi.h is used to redefine functions for an Ansi code ------------------------------------------------------------------------------*/ #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #ifdef G_UNIX #include #include #endif /*------------------------------------------------------------------------------ Module public interface. - gttimout.h ------------------------------------------------------------------------------*/ #include "gttimout.h" /*------------------------------------------------------------------------------ Function definitions section ------------------------------------------------------------------------------*/ /******************************************************************************* * WORD32 G_DECL G_EndTime(const WORD32 Timing) * * Description : * ------------- * This function returns a value to test with G_CurrentTime function to check if * the Timing has been overlapped. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Timing is a value in milli-seconds which indicates the available time for * an operation. * * Out : * ------------- * Nothing. * * Responses : * ------------- * The response is the value which will be returned by G_CurrentTime when Timing * milli-seconds will be passed. * Extern Var : ------------- Nothing. Global Var : ------------- Nothing. *******************************************************************************/ WORD32 G_DECL G_EndTime(const WORD32 Timing) { return ( (WORD32) (clock() + (clock_t) (((float) Timing * (float) CLK_TCK / 1000.0) + 0.5))); } /******************************************************************************* * WORD32 G_DECL G_CurrentTime(void) * * Description : * ------------- * This function returns the current time according to an internal unit. This * function has to be used with G_EndTime. * * Remarks : * ------------- * Nothing. * * In : * ------------- * Nothing. * * Out : * ------------- * Nothing. * * Responses : * ------------- * The response is the current timing according to an internal unit. * Extern Var : ------------- Nothing. Global Var : ------------- Nothing. *******************************************************************************/ WORD32 G_DECL G_CurrentTime(void) { return ((WORD32) clock()); } /******************************************************************************* * float G_DECL G_UnitPerSec (void) * * Description : * ------------- * This function returns the number of units per second. * * Remarks : * ------------- * Nothing. * * In : * ------------- * Nothing. * * Out : * ------------- * Nothing. * * Responses : * ------------- * The number of units per second. * Extern Var : ------------- Nothing. Global Var : ------------- Nothing. *******************************************************************************/ float G_DECL G_UnitPerSec(void) { return ((float) CLK_TCK); } DWORD G_DECL wait_ms(DWORD ms) { struct pollfd filedes[1]; filedes[0].fd = 0; filedes[0].events = POLLNVAL; poll(filedes, 1, ms); return ms; } libgcr410-2.4.0.orig/gttimout.h0100644000175000017500000000400607354047734013632 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : GTTIMOUT.H * * Description : Interface for time out utility. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _GTTIMOUT_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _GTTIMOUT_H #define _GTTIMOUT_H /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Function prototype section ------------------------------------------------------------------------------*/ WORD32 G_DECL G_CurrentTime(void); WORD32 G_DECL G_EndTime(const WORD32 Timing); float G_DECL G_UnitPerSec(void); DWORD G_DECL wait_ms(DWORD ms); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/ifd2gem.h0100644000175000017500000000364207354047734013300 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : IFD2Ggem * * Description : Translates IFD status code in GemError codes. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _IFD2GEM_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _IFD2GEM_H #define _IFD2GEM_H /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototype section ------------------------------------------------------------------------------*/ INT16 G_DECL GE_Translate(const BYTE IFDStatus); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/ifdhandler.c0100644000175000017500000007667307354047734014074 0ustar p2p2/***************************************************************** / / ifdhandler for Gemplus Gemcore readers / Copyright (C) 2001 Ludovic Rousseau / / This program is free software; you can redistribute it and/or modify / it under the terms of the GNU General Public License as published by / the Free Software Foundation; either version 2 of the License, or / (at your option) any later version. / / This program is distributed in the hope that it will be useful, / but WITHOUT ANY WARRANTY; without even the implied warranty of / MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / GNU General Public License for more details. / / You should have received a copy of the GNU General Public License / along with this program; if not, write to the Free Software / Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA / / File : ifdhandler.c / Author : David Corcoran / for the empty functions / Ludovic Rousseau / for debug and migration for pcsc API 1.0 to 2.0 / Gemplus / A great part of the code is extracted from the original / ifdhandler.c (C) by 1991 - 2001 Gemplus / / Date : September 2001 / Purpose: This provides reader specific low-level calls. / See http://www.linuxnet.com for more information. / / ******************************************************************/ #include #include #include #include #ifdef HAVE_PTHREAD_H #include #include #endif #include "gemplus.h" #include "gemcom.h" #include "or3gll.h" #include "debug.h" #include "or3utils.h" #include "gemgcr.h" #include "ifd2gem.h" #include "or3icc.h" #include "apduspli.h" #include "apdubuil.h" #include "gemcard.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif /* * The GCR 410 (GemPC 410) returns GemCore-R1.21-GM * The GCR 400 returns nothing */ #define IFD_OS_VERSION "GemCore-R1." /* * Will only use GemCore 1.21 commands if defined */ //#define GEMCORE_121 /* * Constants */ char *vendor_name = "Gemplus"; char *ifd_type = "Gemcore Based Reader"; char *ifd_serial = "Gemcore Serial No. Not used"; /* * Global variables */ DEVICE_CAPABILITIES Device; ICC_STATE Icc; PROTOCOL_OPTIONS ProtocolOptions; /* Private varaibles. Only used in EMV management. */ /*EMV Behaviour Gemplus 2001*/ static unsigned char EMVSupported=FALSE ; /*We suppose that the reader doesn't have an EMV behaviour.*/ /*EMV Behaviour Gemplus 2001*/ #ifdef HAVE_PTHREAD_H static pthread_mutex_t ifdh_status_mutex = PTHREAD_MUTEX_INITIALIZER; #endif /************************************************************************** * * IFDHCreateChannel * *************************************************************************/ RESPONSECODE IFDHCreateChannel(DWORD Lun, DWORD Channel) { /* * Lun - Logical Unit Number, use this for multiple card slots or * multiple readers. 0xXXXXYYYY - XXXX multiple readers, YYYY multiple * slots. The resource manager will set these automatically. By default * the resource manager loads a new instance of the driver so if your * reader does not have more than one smartcard slot then ignore the Lun * in all the functions. Future versions of PC/SC might support loading * multiple readers through one instance of the driver in which XXXX * would be important to implement if you want this. */ /* * Channel - Channel ID. This is denoted by the following: 0x000001 - * /dev/pcsc/1 0x000002 - /dev/pcsc/2 0x000003 - /dev/pcsc/3 * * USB readers may choose to ignore this parameter and query the bus for * the particular reader. */ /* * This function is required to open a communications channel to the * port listed by Channel. For example, the first serial reader on COM1 * would link to /dev/pcsc/1 which would be a sym link to /dev/ttyS0 on * some machines This is used to help with intermachine independance. * * Once the channel is opened the reader must be in a state in which it * is possible to query IFDHICCPresence() for card status. * * returns: * * IFD_SUCCESS IFD_COMMUNICATION_ERROR */ RESPONSECODE response = IFD_SUCCESS; int iPort = G_COM1; unsigned short Unibble; // Upper 16bits of DWORD. (DDDD) unsigned short Lnibble; // Lower 16bits of DWORD. (CCCC) WORD16 major_ver = 0, minor_ver = 0; char *tmp = NULL; WORD16 os_length = HOR3GLL_OS_STRING_SIZE; char os_string[os_length]; WORD16 rlen; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif Unibble = Channel >> 16; // Shift right 16 bits. Lnibble = Channel & 0xFFFF; // Shift left and subtract. switch (Unibble) { case 0x01: // Serial Port. switch (Lnibble) { case 0x3F8: iPort = G_COM1; break; case 0x2F8: iPort = G_COM2; break; case 0x3E8: iPort = G_COM3; break; case 0x2E8: iPort = G_COM4; break; default: response = IFD_NOT_SUPPORTED; goto IFDHCreateChannel_return; } break; default: // case 0xFy where y is vendor defined 0 - F is NOT implemented // 0x02: Parellel, 0x04: PS2, 0x08: SCSI, 0x10: IDE // 0x20: USB Port response = IFD_NOT_SUPPORTED; goto IFDHCreateChannel_return; } DEBUG_MSG("IFDHCreateChannel: iPort=%d", iPort); response = G_Oros3OpenComm(iPort, 9600); if (response < 0) { response = IFD_COMMUNICATION_ERROR; goto IFDHCreateChannel_return; } os_length = HOR3GLL_OS_STRING_SIZE; response = G_Oros3String(&os_length, os_string); if (response < G_OK) { G_Oros3CloseComm(); response = IFD_COMMUNICATION_ERROR; goto IFDHCreateChannel_return; } os_string[os_length] = '\0'; if (_fstrncmp((const char G_FAR *) os_string + 1, IFD_OS_VERSION, _fstrlen(IFD_OS_VERSION)) != G_OK) { G_Oros3CloseComm(); response = IFD_NOT_SUPPORTED; goto IFDHCreateChannel_return; } tmp = (char G_FAR *) _fstrstr(os_string + 1, IFD_OS_VERSION); if (tmp != NULL) { major_ver = atoi(tmp + _fstrlen(IFD_OS_VERSION)); minor_ver = atoi(tmp + _fstrlen(IFD_OS_VERSION) + 2); } /*EMV Behaviour Gemplus 2001*/ /*Now we got the Firmware version. We test it*/ /*We only check the minor version.We suppose that the reader is only a GemCore Reader*/ if(major_ver>= 20) /*Only 1.20 and above manage EMV behaviour*/ { EMVSupported= TRUE ; } /*EMV Behaviour Gemplus 2001*/ /**/ memset(&Device, 0, sizeof(Device)); memset(&Icc, 0, sizeof(Icc)); Device.IFD_Version = major_ver << 24; Device.IFD_Version |= (minor_ver << 16); Device.IFD_Version |= 0x0001; // Build.. to be added later. // Should we change baud rate of reader comm-n here.. if (G_ChangeIFDBaudRate(iPort, 38400) != G_OK) { G_Oros3CloseComm(); DEBUG_MSG("38400 baud setting problem. exiting"); response = IFD_COMMUNICATION_ERROR; goto IFDHCreateChannel_return; } // Removes TLP Compatibility here.. rlen = HOR3GLL_BUFFER_SIZE; response = G_Oros3SetMode(HOR3GLL_LOW_TIME, 0x00, &rlen, rbuff); if (response < G_OK) { G_Oros3CloseComm(); response = IFD_COMMUNICATION_ERROR; goto IFDHCreateChannel_return; } Device.Vendor_Name = vendor_name; Device.IFD_Type = ifd_type; Device.IFD_Serial = ifd_serial; Device.IFD_Channel_ID = Channel; Device.Asynch_Supported = 0x00000003; // Both T=0/T=1 Supported Device.Default_Clock = 3680; Device.Max_Clock = 3680; Device.Default_Data_Rate = 9600; Device.Max_Data_Rate = 115000; Device.Synch_Supported = 0; Device.Power_Mgmt = 1; // IFD Supports powerdown if ICC present; DEBUG_MSG("Vendor Name = %s", Device.Vendor_Name); DEBUG_MSG("IFD Type = %s", Device.IFD_Type); DEBUG_MSG("IFD Version = 0x%04X", Device.IFD_Version); DEBUG_MSG("IFD Serial = %s", Device.IFD_Serial); DEBUG_MSG("IFD Channel ID = 0x%04x", Device.IFD_Channel_ID); // All Others not supported.. IFDHCreateChannel_return: #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHCreateChannel */ /************************************************************************** * * IFDHCloseChannel * *************************************************************************/ RESPONSECODE IFDHCloseChannel(DWORD Lun) { /* * This function should close the reader communication channel for the * particular reader. Prior to closing the communication channel the * reader should make sure the card is powered down and the terminal is * also powered down. * * returns: * * IFD_SUCCESS IFD_COMMUNICATION_ERROR */ RESPONSECODE response = IFD_SUCCESS; DEBUG_MSG("IFDHCloseChannel"); #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif G_Oros3SIOConfigureNewBaudRate(9600); DEBUG_MSG("IFD Handler: IFDHCloseChannel called"); response = G_Oros3CloseComm(); if (response < 0) { DEBUG_MSG("IFDHCloseChannel: IFD_COMMUNICATION_ERROR"); response = IFD_COMMUNICATION_ERROR; } #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHCloseChannel */ /************************************************************************** * * IFDHGetCapabilities * *************************************************************************/ RESPONSECODE IFDHGetCapabilities(DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value) { /* * This function should get the slot/card capabilities for a particular * slot/card specified by Lun. Again, if you have only 1 card slot and * don't mind loading a new driver for each reader then ignore Lun. * * Tag - the tag for the information requested example: TAG_IFD_ATR - * return the Atr and it's size (required). these tags are defined in * ifdhandler.h * * Length - the length of the returned data Value - the value of the * data * * returns: * * IFD_SUCCESS IFD_ERROR_TAG */ RESPONSECODE response = IFD_SUCCESS; DEBUG_MSG("IFDHGetCapabilities: %x", Tag); #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif switch (Tag) { case TAG_IFD_ATR: break; default: response = IFD_ERROR_TAG; } #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHGetCapabilities */ /************************************************************************** * * IFDHSetCapabilities * *************************************************************************/ RESPONSECODE IFDHSetCapabilities(DWORD Lun, DWORD Tag, DWORD Length, PUCHAR Value) { /* * This function should set the slot/card capabilities for a particular * slot/card specified by Lun. Again, if you have only 1 card slot and * don't mind loading a new driver for each reader then ignore Lun. * * Tag - the tag for the information needing set * * Length - the length of the returned data Value - the value of the * data * * returns: * * IFD_SUCCESS IFD_ERROR_TAG IFD_ERROR_SET_FAILURE * IFD_ERROR_VALUE_READ_ONLY */ DEBUG_MSG("IFDHSetCapabilities: %x", Tag); return IFD_NOT_SUPPORTED; } /* IFDHSetCapabilities */ /************************************************************************** * * IFDHSetProtocolParameters * *************************************************************************/ RESPONSECODE IFDHSetProtocolParameters(DWORD Lun, DWORD Protocol, UCHAR Flags, UCHAR PTS1, UCHAR PTS2, UCHAR PTS3) { /* * This function should set the PTS of a particular card/slot using the * three PTS parameters sent * * Protocol - 0 .... 14 T=0 .... T=14 Flags - Logical OR of * possible values: IFD_NEGOTIATE_PTS1 IFD_NEGOTIATE_PTS2 * IFD_NEGOTIATE_PTS3 to determine which PTS values to negotiate. * PTS1,PTS2,PTS3 - PTS Values. * * returns: * * IFD_SUCCESS IFD_ERROR_PTS_FAILURE IFD_COMMUNICATION_ERROR * IFD_PROTOCOL_NOT_SUPPORTED */ RESPONSECODE response = IFD_SUCCESS; INT16 nRes; WORD16 rlen; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; DEBUG_MSG("IFD_Set_Protocol_Parameters with Protocol Type <%X>", Protocol); #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif // if ((ProtocolType & 0x7FFFFFFE) != 0) if ((Protocol != SCARD_PROTOCOL_T0) && (Protocol != SCARD_PROTOCOL_T1)) { response = IFD_PROTOCOL_NOT_SUPPORTED; goto IFDHSetProtocolParameters_exit; } // ICC.ProtocolType = ProtocolType; if (Protocol == SCARD_PROTOCOL_T0) ProtocolOptions.Protocol_Type = 0x00; else ProtocolOptions.Protocol_Type = 0x01; if ((Flags & 0xF0) == 0x00) // No PPS1 !!!! { Flags = 0x10; // At least PPS1 PTS1 = 0x11; // 9600 Bauds } DEBUG_MSG("PPS Power up Selection Flag: %X, PTS1: %X, PTS2: %X, PTS3: %X", Flags | Protocol, PTS1, PTS2, PTS3); // Send Power Up to Reader in order to apply new PPS parameters nRes = G_Oros3IccPowerUp(HOR3GLL_DEFAULT_TIME, ICC_VCC_5_3V, // ICC_VCC_5V, IFD_NEGOTIATE_PTS_MANUALLY, // ICC.SelectionFlags, Flags | Protocol, PTS1, PTS2, PTS3, &rlen, rbuff); if (nRes >= G_OK) { nRes = GE_Translate(rbuff[0]); } if (nRes < G_OK) { DEBUG_MSG("ICC PPS Management returning error"); response = IFD_ERROR_PTS_FAILURE; } else // Update strucuture with new prt ProtocolOptions.Protocol_Type = Protocol; IFDHSetProtocolParameters_exit: #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHSetProtocolParameters */ /************************************************************************** * * IFDHPowerICC * *************************************************************************/ RESPONSECODE IFDHPowerICC(DWORD Lun, DWORD Action, PUCHAR Atr, PDWORD AtrLength) { /* * This function controls the power and reset signals of the smartcard * reader at the particular reader/slot specified by Lun. * * Action - Action to be taken on the card. * * IFD_POWER_UP - Power and reset the card if not done so (store the ATR * and return it and it's length). * * IFD_POWER_DOWN - Power down the card if not done already * (Atr/AtrLength should be zero'd) * * IFD_RESET - Perform a quick reset on the card. If the card is not * powered power up the card. (Store and return the Atr/Length) * * Atr - Answer to Reset of the card. The driver is responsible for * caching this value in case IFDHGetCapabilities is called requesting * the ATR and it's length. This should not exceed MAX_ATR_SIZE. * * AtrLength - Length of the Atr. This should not exceed MAX_ATR_SIZE. * * Notes: * * Memory cards without an ATR should return IFD_SUCCESS on reset but the * Atr should be zero'd and the length should be zero * * Reset errors should return zero for the AtrLength and return * IFD_ERROR_POWER_ACTION. * * returns: * * IFD_SUCCESS IFD_ERROR_POWER_ACTION IFD_COMMUNICATION_ERROR * IFD_NOT_SUPPORTED */ RESPONSECODE response = IFD_SUCCESS; WORD16 rlen = 0; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; BYTE pts0, pts1, pts2, pts3; #ifdef DEBUG if (Action == IFD_POWER_UP) DEBUG_MSG("IFDHPowerICC: IFD_POWER_UP"); else if (Action == IFD_POWER_DOWN) DEBUG_MSG("IFDHPowerICC: IFD_POWER_DOWN"); else if (Action == IFD_RESET) DEBUG_MSG("IFDHPowerICC: IFD_RESET"); #endif #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif pts0 = 0; pts1 = 0; pts2 = 0; pts3 = 0; if (Action == IFD_POWER_UP) { rlen = HOR3GLL_BUFFER_SIZE; response = G_Oros3IccPowerDown(HOR3GLL_DEFAULT_TIME, &rlen, rbuff); if (response >= G_OK) { response = GE_Translate(rbuff[0]); DEBUG_MSG("status: %x, response: %d", rbuff[0], response); } if (response < G_OK) { DEBUG_MSG("ICC Power up-dn returing error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } rlen = HOR3GLL_BUFFER_SIZE; /* if (ICC.SelectionFlags !=IFD_DEFAULT_MODE) if (ICC.SelectionFlags !=0 ) //--2001 Modif { ptsmode = IFD_NEGOTIATE_PTS_MANUALLY; pts0 = ICC.SelectionFlags; pts1 = ICC.PTS1; pts2 = ICC.PTS2; pts3 = ICC.PTS3; } else ptsmode = pts0 = pts1 = pts2 = pts3 = 0; if (pts0 > 0x07) pts0 &= 0x07; */ /*==== EMV Behaviour Gemplus 2001*/ /* Ask to the reader in what mode it is set ? */ response= G_Oros3Exchange(HOR3GLL_DEFAULT_TIME, 3, "\x17\x00\x00", &rlen, rbuff); /* Test status*/ if (response < G_OK) { DEBUG_MSG("ICC Get statut returning error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } rlen = HOR3GLL_BUFFER_SIZE; /*Parse */ if(rbuff[1]== 0x45)/*EMV Mode ?*/ { /*EMV PowerUp*/ response = G_Oros3Exchange(HOR3GLL_DEFAULT_TIME, 1, "\x12", &rlen, rbuff); } else/*ISO Mode*/ { /*ISO Power UP with Class selection and no automatic PTS*/ response = G_Oros3IccPowerUp(HOR3GLL_DEFAULT_TIME, ICC_VCC_5_3V, // ICC_VCC_5V, IFD_DEFAULT_MODE, pts0, pts1, pts2, pts3, &rlen, rbuff); } /*==== EMV Behaviour Gemplus 2001*/ if (response >= G_OK) response = GE_Translate(rbuff[0]); if (response < G_OK) { DEBUG_MSG("ICC Power up returing error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } /* set the ATR */ memset(Icc.ATR, 0, sizeof(Icc.ATR)); memcpy(Icc.ATR, rbuff + 1, rlen - 1); *AtrLength = rlen - 1; memcpy(Atr, Icc.ATR, *AtrLength); /* * l = 1; while (ICC.ATR[l] & 0x80) { offset = 0; for(k = 0x10; k > * 0; k <<=1) { if ( ICC.ATR[l] & k) { offset++; } } l += offset; * Protocol.Protocol_Type = (WORD16)(ICC.ATR[l] & 0x0F); } */ IFDHICCPresence(Lun); } else if (Action == IFD_POWER_DOWN) { rlen = HOR3GLL_BUFFER_SIZE; response = G_Oros3IccPowerDown(HOR3GLL_DEFAULT_TIME, &rlen, rbuff); if (response >= G_OK) { response = GE_Translate(rbuff[0]); } if (response < G_OK) { DEBUG_MSG("ICC Power down returing error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } } else if (Action == IFD_RESET) { rlen = HOR3GLL_BUFFER_SIZE; /* if (ICC.SelectionFlags != IFD_DEFAULT_MODE) if (ICC.SelectionFlags !=0 ) { ptsmode = IFD_NEGOTIATE_PTS_MANUALLY; pts0 = ICC.SelectionFlags; pts1 = ICC.PTS1; pts2 = ICC.PTS2; pts3 = ICC.PTS3; } else ptsmode = pts0 = pts1 = pts2 = pts3 = 0; if (pts0 > 0x07) pts0 &= 0x07; */ /*==== EMV Behaviour Gemplus 2001*/ response= G_Oros3Exchange(HOR3GLL_DEFAULT_TIME, 3, "\x17\x00\x00", &rlen, rbuff); /**/ if (response < G_OK) { DEBUG_MSG("ICC Get statut returning error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } rlen = HOR3GLL_BUFFER_SIZE; /*Parse */ if(rbuff[1]== 0x45)/*EMV Mode*/ { response = G_Oros3Exchange(HOR3GLL_DEFAULT_TIME, 1, "\x12", &rlen, rbuff); } else/*ISO Mode*/ { response = G_Oros3IccPowerUp(HOR3GLL_DEFAULT_TIME, ICC_VCC_5_3V, // ICC_VCC_5V, IFD_DEFAULT_MODE, pts0, pts1, pts2, pts3, &rlen, rbuff); } /*==== EMV Behaviour Gemplus 2001*/ if (response >= G_OK) { response = GE_Translate(rbuff[0]); } if (response < G_OK) { DEBUG_MSG("ICC Power up-reset returing error"); response = IFD_ERROR_POWER_ACTION; goto IFDHPowerICC_exit; } memset(Icc.ATR, 0, sizeof(Icc.ATR)); memcpy(Icc.ATR, rbuff + 1, rlen - 1); *AtrLength = rlen - 1; memcpy(Atr, Icc.ATR, *AtrLength); /* * l = 1; while (ICC.ATR[l] & 0x80) { offset = 0; for(k = 0x10; k > * 0; k <<=1) { if ( ICC.ATR[l] & k) { offset++; } } l += offset; * Protocol.Protocol_Type = (WORD16)(ICC.ATR[l] & 0x0F); } */ IFDHICCPresence(Lun); DEBUG_MSG("IFD Handler: Resetting is done"); } else { response = IFD_ERROR_NOT_SUPPORTED; goto IFDHPowerICC_exit; } if ((Action == IFD_POWER_UP) || (Action == IFD_RESET)) { // IFD_Is_ICC_Present(); // Call this fun which updates params ProtocolOptions.Current_Clock = 0x3680; GetAtrParams(Icc.ATR, &ProtocolOptions); rlen = HOR3GLL_BUFFER_SIZE; response = G_Oros3BufferSize(&rlen, rbuff); if (response == G_OK) ProtocolOptions.Current_IFSC = (WORD32) rbuff[1]; } IFDHPowerICC_exit: #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHPowerICC */ /************************************************************************** * * IFDHTransmitToICC * *************************************************************************/ RESPONSECODE IFDHTransmitToICC(DWORD Lun, SCARD_IO_HEADER SendPci, PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength, PSCARD_IO_HEADER RecvPci) { /* * This function performs an APDU exchange with the card/slot specified * by Lun. The driver is responsible for performing any protocol * specific exchanges such as T=0/1 ... differences. Calling this * function will abstract all protocol differences. * * SendPci Protocol - 0, 1, .... 14 Length - Not used. * * TxBuffer - Transmit APDU example (0x00 0xA4 0x00 0x00 0x02 0x3F 0x00) * TxLength - Length of this buffer. RxBuffer - Receive APDU example * (0x61 0x14) RxLength - Length of the received APDU. This function * will be passed the size of the buffer of RxBuffer and this function is * responsible for setting this to the length of the received APDU. This * should be ZERO on all errors. The resource manager will take * responsibility of zeroing out any temporary APDU buffers for security * reasons. * * RecvPci Protocol - 0, 1, .... 14 Length - Not used. * * Notes: The driver is responsible for knowing what type of card it has. * If the current slot/card contains a memory card then this command * should ignore the Protocol and use the MCT style commands for support * for these style cards and transmit them appropriately. If your * reader does not support memory cards or you don't want to then ignore * this. * * RxLength should be set to zero on error. * * returns: * * IFD_SUCCESS IFD_COMMUNICATION_ERROR IFD_RESPONSE_TIMEOUT * IFD_ICC_NOT_PRESENT IFD_PROTOCOL_NOT_SUPPORTED */ RESPONSECODE PCSCResponse = IFD_SUCCESS,/*Return IFD Error Code*/ TLResponse ;/*Used only in serial communication*/ DWORD lc, Prot; BYTE *CmdData; BYTE data_in[280], data_out[280]; G4_APDU_COMM ApduComm; G4_APDU_RESP ApduResp; // BYTE *tmp; DEBUG_MSG("IFDHTransmitToICC"); #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); pthread_mutex_lock(&ifdh_status_mutex); #endif lc = TxLength; Prot = SendPci.Protocol; CmdData = TxBuffer; *RxLength = 0; // Removed to go faster // IFD_Is_ICC_Present(); DEBUG_MSG("Prot %d ProtType %d\n", Prot, ProtocolOptions.Protocol_Type); if (Prot != ProtocolOptions.Protocol_Type) { DEBUG_MSG("Prot not match"); PCSCResponse = IFD_COMMUNICATION_ERROR; goto IFDHTransmitToICC_exit; } if (lc < 4) { DEBUG_MSG("Lc < 4"); PCSCResponse = IFD_COMMUNICATION_ERROR; goto IFDHTransmitToICC_exit; } // clear structures memset(&ApduComm, 0, sizeof(ApduComm)); memset(&ApduResp, 0, sizeof(ApduResp)); // COMMAND_LEN is defined as 4 (CLA, INS, P1, P2) memcpy(ApduComm.Command, CmdData, COMMAND_LEN); ApduComm.DataIn = data_in; ApduResp.DataOut = data_out; // Case 1 CLA INS P1 P2 // Case 2 CLA INS P1 P2 Le // Case 3 CLA INS P1 P2 Lc // Case 4 CLA INS P1 P2 Lc Le if (lc == 4) // Case1 { ApduComm.LengthIn = ApduComm.LengthExpected = 0; } else if (lc == 5) // Case2..ie Lin=0, Le > 0 { ApduComm.LengthIn = 0; ApduComm.LengthExpected = CmdData[COMMAND_LEN]; if (ApduComm.LengthExpected == 0) // Max Data ApduComm.LengthExpected = 256; } else // Case3 & Case4 { ApduComm.LengthIn = CmdData[COMMAND_LEN]; DEBUG_MSG("Command Len = %d", ApduComm.LengthIn); ApduComm.LengthExpected = 0; // Case3 if (ApduComm.LengthIn > 0) { DEBUG_MSG("Copying %d bytes from CmdData to ApduComm.DataIn", ApduComm.LengthIn); memcpy(ApduComm.DataIn, CmdData + COMMAND_LEN + 1, ApduComm.LengthIn); //DEBUG_XXD(ApduComm.DataIn, ApduComm.LengthIn); } if (lc > COMMAND_LEN + 1 + ApduComm.LengthIn) // Case4 { ApduComm.LengthExpected = *(CmdData + COMMAND_LEN + 1 + ApduComm.LengthIn); if (ApduComm.LengthExpected == 0x00) // Max Data ApduComm.LengthExpected = 256; DEBUG_MSG("Len expected = %d", ApduComm.LengthExpected); } } /* The Reader has an EMV Behaviour. Whatever the protocol (T=0 or T=1) we always send smart card exchange with 15 GemCore Command. So we set the 'Prot' variable with 1 value. */ /*EMV Behaviour Gemplus 2001*/ if(EMVSupported== TRUE) { Prot= 1 ; } if (Prot == 0) // If T=0 protocol... { int i; // 2001 Modif-- // This will prevent to execution of both IsoIn/IsoOut commands. // if ( (ApduComm.LengthIn > 0) && (ApduComm.LengthExpected > 0) ) // { // return (IFD_COMMUNICATION_ERROR); // } // --2001 Modif TLResponse = ApduSpliter(HOR3GLL_DEFAULT_TIME, &ApduComm, &ApduResp, G_Oros3IccIsoInput, G_Oros3IccIsoOutput); if (TLResponse < G_OK) { DEBUG_MSG("ApduSpliter returning < G_OK\n"); PCSCResponse = IFD_COMMUNICATION_ERROR; goto IFDHTransmitToICC_exit; } *RxLength = 2 + ApduResp.LengthOut; // Added by Dave C for (i = 0; i < ApduResp.LengthOut; ++i) RxBuffer[i] = ApduResp.DataOut[i]; RxBuffer[i] = (ApduResp.Status & 0xff00) >> 8; RxBuffer[i] &= 0xff; RxBuffer[i + 1] = (ApduResp.Status & 0x00ff); } else if (Prot == 1) // Here whatever smartcard Protocol T=0 or T=1, the APDU command is // sent by using 15h GemCore Command // This is the Firmware that manages the exchange. { WORD32 slen; WORD16 rlen; WORD8 rbuff[HOR3GLL_BUFFER_SIZE], sbuff[HOR3GLL_BUFFER_SIZE]; if ((ApduComm.LengthExpected > (HOR3GLL_BUFFER_SIZE - 5)) || ((ApduComm.LengthExpected == 0) && (ApduComm.LengthIn > (HOR3GLL_BUFFER_SIZE - 6))) || ((ApduComm.LengthExpected != 0) && // (ApduComm.LengthIn > (HOR3GLL_BUFFER_SIZE - 7)) (ApduComm.LengthIn > (HOR3GLL_BUFFER_SIZE - 6)))) { DEBUG_MSG("Parameters not matching"); PCSCResponse = (IFD_COMMUNICATION_ERROR); goto IFDHTransmitToICC_exit; } slen = HOR3GLL_BUFFER_SIZE; TLResponse = ApduBuilder(&ApduComm, sbuff, &slen); if (TLResponse < G_OK) { DEBUG_MSG("ApduBuilder returning %d", response); PCSCResponse = (IFD_COMMUNICATION_ERROR); goto IFDHTransmitToICC_exit; } rlen = HOR3GLL_BUFFER_SIZE; TLResponse = G_Oros3IccIsoT1(HOR3GLL_DEFAULT_TIME, slen, sbuff, &rlen, rbuff); /*This code was dead code. The TLResponse can never be > G_OK */ /* if (TLResponse > G_OK) { DEBUG_MSG("G_Oros3IccIsoT1 returning %d", response); TLResponse = GE_Translate(rbuff[0]); } */ if ((TLResponse < G_OK) || (rlen < 3)) { PCSCResponse = (IFD_COMMUNICATION_ERROR); goto IFDHTransmitToICC_exit; } // ApduResp.LengthOut = rlen - 3; ApduResp.LengthOut = rlen - 1; DEBUG_MSG("G_Oros3IccIsoT1 returning rlen=%d", rlen); // if ( ApduResp.LengthOut > 0 ) if (ApduResp.LengthOut > 1) { DEBUG_MSG("*ResponseSize = ApduResp.LengthOut = %d", ApduResp.LengthOut); *RxLength = ApduResp.LengthOut; /* Added by Dave C */ memcpy(RxBuffer, rbuff + 1, ApduResp.LengthOut); } else { ApduResp.LengthOut = 0; } RxBuffer[ApduResp.LengthOut] = rbuff[rlen - 2]; RxBuffer[ApduResp.LengthOut + 1] = rbuff[rlen - 1]; } IFDHTransmitToICC_exit: #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return PCSCResponse; } /* IFDHTransmitToICC */ /************************************************************************** * * IFDHControl * *************************************************************************/ RESPONSECODE IFDHControl(DWORD Lun, PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength) { /* * This function performs a data exchange with the reader (not the card) * specified by Lun. Here XXXX will only be used. It is responsible for * abstracting functionality such as PIN pads, biometrics, LCD panels, * etc. You should follow the MCT, CTBCS specifications for a list of * accepted commands to implement. * * TxBuffer - Transmit data TxLength - Length of this buffer. RxBuffer - * Receive data RxLength - Length of the received data. This function * will be passed the length of the buffer RxBuffer and it must set this * to the length of the received data. * * Notes: RxLength should be zero on error. */ DEBUG_MSG("IFDHControl"); return IFD_NOT_SUPPORTED; } /* IFDHControl */ /************************************************************************** * * IFDHICCPresence * *************************************************************************/ RESPONSECODE IFDHICCPresence(DWORD Lun) { /* * This function returns the status of the card inserted in the * reader/slot specified by Lun. It will return either: * * returns: IFD_ICC_PRESENT IFD_ICC_NOT_PRESENT IFD_COMMUNICATION_ERROR */ RESPONSECODE response = IFD_COMMUNICATION_ERROR; WORD16 rlen; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; WORD8 cmd[2]; DEBUG_MSG("IFDHICCPresence"); #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_lock", __FILE__, __LINE__); if (pthread_mutex_trylock(&ifdh_status_mutex) == EBUSY) { DEBUG_MSG("%s:%d mutex is locked", __FILE__, __LINE__); return IFD_ICC_PRESENT; } #endif cmd[0] = HOR3GLL_IFD_CMD_ICC_STATUS; rlen = MAX_IFD_STRING; // If Exchange is running do not send command, do not change ICC // Structure // and leave with no error. /*if (bSemaphore == BUSY) { DEBUG_MSG("IFD_Is_ICC_Present running but Semaphore is set"); return IFD_SUCCESS; } else { bSemaphore == FREE; DEBUG_MSG("IFD_Is_ICC_Present running"); }*/ response = G_Oros3Exchange(HOR3GLL_LOW_TIME, 1, cmd, &rlen, rbuff); if (response != G_OK) response = IFD_NOT_SUPPORTED; // should not return this else { Icc.ICC_Presence = 0; Icc.ICC_Interface_Status = 0; if (rlen == 7) { if ((rbuff[1] & 0x04) == 0) // ICC ABSENT { Icc.ICC_Presence = 0; // Make ATR and everything to 0s.. // memset(&ICC, 0, sizeof(ICC)); Icc.ICC_Presence = 0; Icc.ICC_Interface_Status = 0; memset(Icc.ATR, 0, sizeof(Icc.ATR)); Icc.ICC_Type = 0; response = IFD_ICC_NOT_PRESENT; } else if ((rbuff[1] & 0x02) == 0) // ICC PRESENT. POWER-DN { Icc.ICC_Presence = 2; Icc.ICC_Interface_Status = 0; // Contact Inactive.. response = IFD_ICC_PRESENT; } else if ((rbuff[1] & 0x08) == 0) // ICC PRESENT. POWERUP { Icc.ICC_Presence = 2; Icc.ICC_Interface_Status = 1; // Contact Active.. ProtocolOptions.Protocol_Type = 0; if ((rbuff[2] != ISOCARD) && (rbuff[2] != FASTISOCARD)) Icc.ICC_Type = 0; // Non ISO Card else Icc.ICC_Type = 1; // ISO Card response = IFD_ICC_PRESENT; } else if ((rbuff[2] == ISOCARD) || (rbuff[2] == FASTISOCARD)) { Icc.ICC_Presence = 2; Icc.ICC_Interface_Status = 1; // Contact Active.. ProtocolOptions.Protocol_Type = 1; Icc.ICC_Type = 1; response = IFD_ICC_PRESENT; } else Icc.ICC_Type = 0; } } #ifdef HAVE_PTHREAD_H DEBUG_MSG("%s:%d mutex_unlock", __FILE__, __LINE__); pthread_mutex_unlock(&ifdh_status_mutex); #endif return response; } /* IFDHICCPresence */ libgcr410-2.4.0.orig/ifdhandler.h0100644000175000017500000001027707354047734014065 0ustar p2p2/***************************************************************** / / File : ifdhandler.h / Author : David Corcoran / Date : June 15, 2000 / Purpose: This provides reader specific low-level calls. / See http://www.linuxnet.com for more information. / License: See file LICENSE / ******************************************************************/ #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 /* End of tag list */ /* 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 /* List of Defined Functions Available to IFD_Handler */ 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 IFDHControl ( DWORD, PUCHAR, DWORD, PUCHAR, PDWORD ); RESPONSECODE IFDHICCPresence( DWORD ); #ifdef __cplusplus } #endif #endif /* _ifd_hander_h_ */ libgcr410-2.4.0.orig/LICENSE0100644000175000017500000003751107354047734012621 0ustar p2p2 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS libgcr410-2.4.0.orig/Makefile0100644000175000017500000000073707354047734013254 0ustar p2p2# Makefile for GemPC 410 serial reader CC = gcc CFLAGS = -Wall -O2 -fPIC -I. -DG_UNIX -DHAVE_PTHREAD_H -g #-DDEBUG OBJ = apdubuil.o apduspli.o debug.o gserial.o gtgbp.o gttimout.o \ ifdhandler.o or32gem.o or3confi.o or3gbpcl.o or3gbpco.o \ or3gbpop.o or3icc.o \ or3utils.o t0case1.o t0case2.o t0case3.o t0case4.o all: libgp_core.so clean: rm -f *.o *.so libgp_core.so: $(OBJ) $(CC) -shared $(OBJ) -o libgp_core.so dep: makedepend *.c ctags: ctags-exuberant *h *c libgcr410-2.4.0.orig/or32gem.c0100644000175000017500000001346307354047734013236 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : Or32GEm.c * * Description : The implemented function translates the IFD status in GemError.h * codes. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Information section - G_NAME is set to "Or32Gem" - G_RELEASE is set to "4.31.002" ------------------------------------------------------------------------------*/ #define G_NAME "Or32Gem" #define G_RELEASE "4.31.002" /*------------------------------------------------------------------------------ Pragma section - comment is called if _MSC_VER is defined. ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif /*------------------------------------------------------------------------------ Include section Environment include: - windows.h gives general Windows 3.1 macros, values and functions. STRICT keyword is used to verify stricly variable types. This file is include only if windows version is required. ------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------ Compiler include: Gemplus includes: - gemplus.h is used to define general macros and values. - gemgcr.h holds readers definitions - gemansi.h is used to redefine functions for an Ansi code ------------------------------------------------------------------------------*/ #include #include "gemplus.h" #include "gemgcr.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif /*------------------------------------------------------------------------------ Module public interface. - ifd2gem.h ------------------------------------------------------------------------------*/ #include "ifd2gem.h" /*------------------------------------------------------------------------------ Function definitions section ------------------------------------------------------------------------------*/ /******************************************************************************* * INT16 GE_Translate(const BYTE IFDStatus) * * Description : * ------------- * Translate IFD status in GemError codes. * * Remarks : * ------------- * Nothing. * * In : * ------------- * IFDStatus is the value to translate. * * Out : * ------------- * Nothing. * * Responses : * ------------- * A GemError.h code. * Extern Var : ------------- Nothing. Global Var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL GE_Translate(const BYTE IFDStatus) { switch (IFDStatus) { case 0x00: return G_OK; case 0x01: return GE_IFD_FN_UNKNOWN; case 0x02: return GE_IFD_FN_UNKNOWN; case 0x03: return GE_IFD_FN_FORMAT; case 0x04: return GE_IFD_TIMEOUT; case 0x05: return GE_HI_CMD_LEN; case 0x09: return GE_HI_FORMAT; case 0x10: return GE_II_ATR_TS; case 0x11: return GE_II_INS; case 0x12: return GE_HI_CMD_LEN; case 0x13: return GE_II_COMM; case 0x14: return GE_ICC_UNKNOWN; case 0x15: return GE_ICC_NOT_POWER; case 0x16: return GE_IFD_FN_PROG; case 0x17: return GE_II_PROTOCOL; case 0x18: return GE_II_PROTOCOL; case 0x19: return GE_IFD_FN_DEF; case 0x1A: return GE_HI_LEN; case 0x1B: return GE_IFD_FN_FORMAT; case 0x1C: return GE_IFD_FN_DEF; case 0x1D: return GE_II_ATR_TCK; case 0x1E: return GE_IFD_FN_DEF; case 0x1F: return GE_IFD_FN_DEF; case 0x20: return GE_IFD_FN_UNKNOWN; case 0x30: return GE_IFD_TIMEOUT; case 0xA0: return GW_ATR; case 0xA1: return GE_II_PROTOCOL; case 0xA2: return GE_ICC_MUTE; case 0xA3: return GE_II_PARITY; case 0xA4: return GE_ICC_ABORT; case 0xA5: return GE_IFD_ABORT; case 0xA6: return GE_IFD_RESYNCH; case 0xA7: return GE_II_PTS; case 0xCF: return GE_IFD_OVERSTRIKED; case 0xE4: return GE_II_PROC_BYTE; case 0xE5: return GW_APDU_LE; case 0xE7: return G_OK; case 0xF7: return GE_ICC_PULL_OUT; case 0xF8: return GE_ICC_INCOMP; case 0xFB: return GE_ICC_ABSENT; default: return ((INT16) (GE_UNKNOWN_PB - IFDStatus)); }; } libgcr410-2.4.0.orig/or3comm.h0100644000175000017500000000602207354047734013335 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : Or3COMM.H * * Description : Public interface for OROS 3.x IFD communication module. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _OR3COMM_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _OR3COMM_H #define _OR3COMM_H /*------------------------------------------------------------------------------ Constant section: - HOR3COMM_MAX_TRY communication try is launched before the channel is declared broken. Today 3. ------------------------------------------------------------------------------*/ #define HOR3COMM_MAX_TRY 3 /*------------------------------------------------------------------------------ - HOR3COMM_CHAR_TIMEOUT is the timeout at character level: today 1000 ms. - HOR3COMM_NACK_TIME is the time out used when a nack command is sent to IFD: today 1000 ms are used. - HOR3COMM_CHAR_TIME is the time for IFD to forget any previously received byte: today 300 ms. ------------------------------------------------------------------------------*/ // #define HOR3COMM_CHAR_TIMEOUT 1000 // #define HOR3COMM_NACK_TIME 1000 // Modif 2001-- #define HOR3COMM_CHAR_TIMEOUT 200 #define HOR3COMM_NACK_TIME 200 // --Modif 2001 #define HOR3COMM_CHAR_TIME 300 /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototype section: ------------------------------------------------------------------------------*/ INT16 G_DECL G_Oros3SendCmd ( const WORD16 CmdLen, const WORD8 G_FAR Cmd[], const BOOL Resynch); INT16 G_DECL G_Oros3ReadResp (const WORD32 Timeout, WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/or3confi.c0100644000175000017500000000625007354047734013476 0ustar p2p2/*************************************************************************** or3confi.c - description ------------------- begin : Wed Apr 18 2001 copyright : (C) by 991 - 2001 Gemplus 1 email : ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #define G_NAME "Or3Confi" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #include "gemgcr.h" #include "gttimout.h" #include "or3comm.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "or3gll.h" INT16 G_DECL G_Oros3SIOConfigure (const WORD32 Timeout, const INT16 Parity, const INT16 ByteSize, const WORD32 BaudRate, WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]) { WORD8 cmd[2] = { HOR3GLL_IFD_CMD_SIO_SET }; switch (BaudRate) { case 76800L: { cmd[1] = 0x01; break; } case 38400L: { cmd[1] = 0x02; break; } case 19200L: { cmd[1] = 0x03; break; } case 9600L: { cmd[1] = 0x04; break; } case 4800L: { cmd[1] = 0x05; break; } case 2400L: { cmd[1] = 0x06; break; } case 1200L: { cmd[1] = 0x07; break; } default: { return (GE_HOST_PARAMETERS); } } switch (ByteSize) { case 8: { break; } case 7: { cmd[1] += 0x08; break; } default: { return (GE_HOST_PARAMETERS); } } switch (Parity) { case 0: { break; } case 2: { cmd[1] += 0x10; break; } default: { return (GE_HOST_PARAMETERS); } } return (G_Oros3Exchange(Timeout, 2, cmd, RspLen, Rsp)); } INT16 G_DECL G_Oros3SIOConfigureNewBaudRate(const WORD32 BaudRate) { WORD8 cmd[2] = { HOR3GLL_IFD_CMD_SIO_SET }; switch (BaudRate) { case 76800L: { cmd[1] = 0x01; break; } case 38400L: { cmd[1] = 0x02; break; } case 19200L: { cmd[1] = 0x03; break; } case 9600L: { cmd[1] = 0x04; break; } case 4800L: { cmd[1] = 0x05; break; } case 2400L: { cmd[1] = 0x06; break; } case 1200L: { cmd[1] = 0x07; break; } default: { return (GE_HOST_PARAMETERS); } } G_Oros3SendCmd(2, cmd, FALSE); return (G_OK); } INT16 G_DECL G_Oros3SetMode (const WORD32 Timeout, const WORD16 Option, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { WORD8 cmd[3] = HOR3GLL_IFD_CMD_MODE_SET; cmd[2] = (WORD8) Option; return (G_Oros3Exchange(Timeout, 3, cmd, RespLen, RespBuff)); } libgcr410-2.4.0.orig/or3gbpcl.c0100644000175000017500000001371307354047734013471 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : OR3GBPCl.C * * Description : Implement the function which closes a communication channel with * an GemCore >= 1.x IFD through Gemplus Block Protocl. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * - Manage the logical channel and not the physical port. * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Information section: - G_NAME is set to "Or3GbpCl" - G_RELEASE is set to "4.31.002" ------------------------------------------------------------------------------*/ #define G_NAME "Or3GbpCl" #define G_RELEASE "4.31.002" /*------------------------------------------------------------------------------ Pragma section - comment is called if _MSC_VER is defined. ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif /*------------------------------------------------------------------------------ Include section Environment include: - windows.h gives general Windows 3.1 macros, values and functions. STRICT keyword is used to verify stricly variable types. This file is include only if windows version is required. ------------------------------------------------------------------------------*/ #ifdef G_WINDOWS #define STRICT #include #endif #ifdef G_OS2 #include #endif /*------------------------------------------------------------------------------ Compiler include: - string.h for _fmemcmp function. ------------------------------------------------------------------------------*/ #include #include #include /*------------------------------------------------------------------------------ Gemplus includes: - gemplus.h is used to define general macros and values. - gemgcr.h holds readers definitions - gtser.h manages the serial communication. - gtgbp.h manages the GBP protocol. - gemansi.h is used to redefine functions for an Ansi code ------------------------------------------------------------------------------*/ #include "gemplus.h" #include "gemgcr.h" #include "gtser.h" #include "gtgbp.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif /*------------------------------------------------------------------------------ Module public interface. - or3gll.h ------------------------------------------------------------------------------*/ #include "or3gll.h" /*------------------------------------------------------------------------------ Function definition section: ------------------------------------------------------------------------------*/ /******************************************************************************* * INT16 G_DECL G_Oros3CloseComm * ( * ) * * Description : * ------------- * This function closes a communication channel with an OROS 3.x IFD. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle holds the value returned by the function which has opened the channel. * * Out : * ------------- * Nothing. * * Responses : * ------------- * If everything is Ok: * - G_OK * If an error condition is raised: * - GE_HOST_PARAMETERS (-450) if the given handle is out of the allowed range. * - GE_HOST_PORT_CLOSE (-412) if the selected port is already closed. * Extern var : ------------- Nothing. Global var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL G_Oros3CloseComm() { /*------------------------------------------------------------------------------ Local Variable: - portcom is the com associate with a logical channel ------------------------------------------------------------------------------*/ INT16 portcom; /*------------------------------------------------------------------------------ Associate Handle ( ChannelNb) with potcom ------------------------------------------------------------------------------*/ portcom = G_GBPChannelToPortComm(); /*------------------------------------------------------------------------------ Closes the communication channel. No action is required on an Oros3.x based IFD. <= G_SerPortClose status. ------------------------------------------------------------------------------*/ G_GBPClose(); return (G_SerPortClose(portcom)); } libgcr410-2.4.0.orig/or3gbpco.c0100644000175000017500000004151107354047734013471 0ustar p2p2/*************************************************************************** or3gbpco.c - description ------------------- begin : Wed Apr 18 2001 copyright : (C) by 1991 - 2001 Gemplus email : ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #define G_NAME "Or3GBPCo" #define G_RELEASE "4.31.002" #include #include #include #include #include #include #include "gemplus.h" #include "gemgcr.h" #include "gtser.h" #include "gttimout.h" #include "gtgbp.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "or3comm.h" #include "debug.h" #ifndef G_WINDOWS #define SPRINTF sprintf #define STR_PTR #else #define SPRINTF wsprintf #define STR_PTR (LPSTR) #endif #if (!defined WIN32) && (!defined G_OS2) && (!defined G_UNIX) static BYTE s_buff[HGTGBP_MAX_BUFFER_SIZE]; static WORD16 s_len; static BYTE r_buff[HGTGBP_MAX_BUFFER_SIZE]; static WORD16 r_len; #endif #define TIMEOUT_STEP 50 INT16 G_DECL G_Oros3SendCmd (const WORD16 CmdLen, const WORD8 G_FAR Cmd[], const BOOL Resynch) { INT16 response, portcom; #if (defined WIN32) || (defined G_OS2) || (defined G_UNIX) WORD16 s_len; BYTE s_buff[HGTGBP_MAX_BUFFER_SIZE]; #endif /*------------------------------------------------------------------------------ Associate Handle( or ChannelNb) with portcom ------------------------------------------------------------------------------*/ portcom = G_GBPChannelToPortComm(); /*------------------------------------------------------------------------------ The GBP message to send is build from the given command: If CmdLen is null Then If resynch is true Then a S-Block is built. Else a R-BLOCK message is built: ------------------------------------------------------------------------------*/ s_len = HGTGBP_MAX_BUFFER_SIZE; if (CmdLen == 0) { if (Resynch) { response = G_GBPBuildSBlock(&s_len, s_buff); } else { response = G_GBPBuildRBlock(&s_len, s_buff); } } /*------------------------------------------------------------------------------ Else an I-BLOCK message is built: ------------------------------------------------------------------------------*/ else { response = G_GBPBuildIBlock(CmdLen, Cmd, &s_len, s_buff); } /*------------------------------------------------------------------------------ If the last operation fails Then <= G_GBPBuildSBlock, G_GBPBuildRBlock or G_GBPBuildIBlock status. ------------------------------------------------------------------------------*/ if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ The communication queues are flushed before the writing. If this operation fails Then <= G_SerPortFlush status. ------------------------------------------------------------------------------*/ response = G_SerPortFlush(portcom, HGTSER_TX_QUEUE | HGTSER_RX_QUEUE); if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ The message is written. As the queues have been flushed, it remains enough place in the transmitt queue for the whole message. If this operation fails Then <= G_SerPortWrite status. ------------------------------------------------------------------------------*/ response = G_SerPortWrite(portcom, s_len, s_buff); DEBUG_XXD("Actual Cmd: ", s_buff, s_len); if (response < G_OK) { return (response); } // sleep(1); return (G_OK); } /******************************************************************************* * INT16 G_DECL G_Oros3ReadResp * ( * const WORD32 Timeout, * WORD16 G_FAR *RspLen, * WORD8 G_FAR Rsp[] * * ) * * Description : * ------------- * This function reads the OROS 3.x IFD response to a command according to * Gemplus Block Protocol. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Handle is the serial channel handle. * - Timeout is the command timeout. * - RspLen indicates how many bytes can be stored in Rsp buffer. * * Out : * ------------- * - RspLen and Rsp are updated with the read bytes. * * Responses : * ------------- * If everything is Ok: * - G_OK ( 0). * If an error condition is raised: * - GE_IFD_MUTE (-201) if a character timeout is detected. * - GE_HI_COMM (-300) if a communication error occurs. * - GE_HI_PARITY (-301) if a parity error is encountered. * - GE_HI_LRC (-302) if an EDC error has been detected. * - GE_HI_PROTOCOL (-310) if a frame error is encountered. * - GE_HI_LEN (-311) if a bad value has been detected in LN field * or if the response buffer is too small. * - GE_HI_FORMAT (-312) if the received message is neither I-Block, * neither R-Block and neither S-Block. * - GE_HI_NACK (-314) if a R-Block has been received. * - GE_HI_RESYNCH (-315) if a S-Block has been received. * - GE_HI_ADDRESS (-316) if the NAD is not valid for the selected channel. * - GE_HI_SEQUENCE (-317) if a bad sequence number has been received. * - GE_HOST_PORT_CLOSE (-412) if port is closed. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the allowed range. * Extern var : ------------- Nothing. Global var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL G_Oros3ReadResp (const WORD32 Timeout, WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]) { /*------------------------------------------------------------------------------ Local variables: - response hold the called function responses. - r_buff[HGTGBP_MAX_BUFFER_SIZE] and r_len are used to receive a IFD message. ------------------------------------------------------------------------------*/ INT16 response, portcom; #if (defined WIN32) || (defined G_OS2) || (defined G_UNIX) WORD16 r_len; BYTE r_buff[HGTGBP_MAX_BUFFER_SIZE]; #endif /*------------------------------------------------------------------------------ Associate Handle( or ChannelNb) with portcom ------------------------------------------------------------------------------*/ portcom = G_GBPChannelToPortComm(); /*------------------------------------------------------------------------------ Read the IFD response: The first three bytes are read by calling G_SerPortRead. If the reading fails Then The read length is set to 0 <= G_SerPortRead status ------------------------------------------------------------------------------*/ r_len = 3; response = G_SerPortRead(portcom, &r_len, r_buff); if (response < G_OK) { *RspLen = 0; return (response); } /*------------------------------------------------------------------------------ r_len is udpated with the number of bytes which must be read to receive a complete Gemplus Block Protocol: the number indicated by the length field of the GBP message + one byte for the EDC. ------------------------------------------------------------------------------*/ r_len = (WORD16) (r_buff[2] + 1); /*------------------------------------------------------------------------------ The end of the message is read by calling G_SerPortRead. The character timeout pass to G_SerPortOpen will be used to determine broken communication. If the selected number of bytes can't be read Then The read length is set to 0 <= G_SerPortRead status ------------------------------------------------------------------------------*/ response = G_SerPortRead(portcom, &r_len, r_buff + 3); if (response < G_OK) { *RspLen = 0; return (response); } /*------------------------------------------------------------------------------ The message length is restored by adding 3 to r_len. ------------------------------------------------------------------------------*/ r_len += 3; DEBUG_XXD("BGP Resp: ", r_buff, r_len); /*------------------------------------------------------------------------------ The GBP message is controlled and decoded: <= G_GBPDecodeMessage status. ------------------------------------------------------------------------------*/ response = G_GBPDecodeMessage(r_len, r_buff, RspLen, Rsp); return response; } /******************************************************************************* * INT16 G_DECL G_Oros3Exchange * ( * const WORD32 Timeout, * const WORD8 CmdLen, * const BYTE G_FAR Cmd[], * WORD8 G_FAR *RspLen, * BYTE G_FAR Rsp[] * ) * * Description : * ------------- * This function sends a command to an ORS2.x IFD according to Gemplus Block * Protocol and read its response. * * Remarks : * ------------- * Nothing. * * In : * ------------- * - Timeout holds the command timeout, in ms. * - CmdLen holds the command length. * - Cmd holds the command bytes. * - RspLen indicates how many bytes can be stored in Rsp buffer. * * Out : * ------------- * - RspLen and Rsp are updated with the read bytes. * * Responses : * ------------- * If everything is OK: * - G_OK ( 0). * If an error condition is raised: * - GE_IFD_MUTE (-201) if a character/command timeout is detected. * - GE_HI_COMM (-300) if a communication error occurs. * - GE_HI_PARITY (-301) if a parity error is encountered. * - GE_HI_LRC (-302) if an EDC error has been detected. * - GE_HI_PROTOCOL (-310) if a frame error is encountered. * - GE_HI_LEN (-311) if a bad value has been detected in LN field * or if the response buffer is too small. * - GE_HI_FORMAT (-312) if the received message is neither I-Block, * neither R-Block and neither S-Block. * - GE_HI_CMD_LEN (-313) if the CmdLen is greater than HGTGBP_MAX_DATA or * if MsgLen is too small to receive the built message. * - GE_HI_NACK (-314) if a R-Block has been received. * - GE_HI_RESYNCH (-315) if a S-Block has been received. * - GE_HI_ADDRESS (-316) if the NAD is not valid for the selected channel. * - GE_HI_SEQUENCE (-317) if a bad sequence number has been received. * - GE_HOST_PORT_BREAK (-404) if the bytes cannot be sent. * - GE_HOST_PORT_CLOSE (-412) if port is closed. * - GE_HOST_PARAMETERS (-450) if the given handle is out of the allowed range. * Extern var : ------------- Nothing. Global var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL G_Oros3Exchange (const WORD32 Timeout, const WORD16 CmdLen, const BYTE G_FAR Cmd[], WORD16 G_FAR * RspLen, BYTE G_FAR Rsp[]) { /*------------------------------------------------------------------------------ Local variables: - timeout holds the value in use. It can be modified for NACK message timeout. - end_time is used to detect command timeout. - tx_length, rx_length and status are used to get the serial port status. - cmdlen_used is a copy of CmdLen. It will be set to 0 if we don't understand IFD. It is initialized to CmdLen. - rsplen_save is a copy of RspLen parameter which can be altered during communication tries. It is initialized to RspLen. - try_counter memorises the number of communication try. It is initialized to 0 - resynch_counter memorises the number of S-Block sent to IFD. - response holds the called function responses. - resynch is a boolean which indicates if a resynchronization is needed or if it's only a repeat block. ------------------------------------------------------------------------------*/ WORD32 timeout = Timeout; struct timeval actual_time, end_time; WORD16 tx_length, rx_length; TGTSER_STATUS status; WORD16 cmdlen_used = CmdLen, rsplen_save = *RspLen; INT16 try_counter = 0, sync_counter = 0, response, portcom; BOOL resynch; portcom = G_GBPChannelToPortComm(); /*------------------------------------------------------------------------------ A first try loop for sending the command is launched: This loop allows to try to send the command, then, if the try fails, to resynchronize the reader and then to tru to send the command one more time. ------------------------------------------------------------------------------*/ resynch = FALSE; while (sync_counter++ < 2) { /*------------------------------------------------------------------------------ A second try loop for sending the command is launched: We send the command and, if a communication error occurs, HOR3COMM_MAX_TRY repetitions are allowed before the communication is considered as broken. The given command is sent to IFD. If the operation fails Then RspLen parameter is set to 0. Release the serial communication semaphore. <= G_Oros3SendCmd status. ------------------------------------------------------------------------------*/ try_counter = 0; while (try_counter++ < HOR3COMM_MAX_TRY) { response = G_Oros3SendCmd(cmdlen_used, Cmd, resynch); if (response < G_OK) { *RspLen = 0; return (response); } /*------------------------------------------------------------------------------ The command timeout is armed and we wait for at least three characters to be received (the 3th codes the message length in GBP, so we know the number of characters to read). If this timeout is raised Then If no synchronisation has been made Then we exit from the internal loop to launch a resynchronization. Else RLen parameter is set to 0; Release the serial communication semaphore. <= GE_IFD_MUTE ------------------------------------------------------------------------------*/ gettimeofday(&actual_time, NULL); end_time = actual_time; end_time.tv_usec = actual_time.tv_usec + Timeout*1000; // convert µsec overflow into sec end_time.tv_sec += end_time.tv_usec / 1000000; end_time.tv_usec %= 1000000; G_SerPortStatus(portcom, &tx_length, &rx_length, &status); while (rx_length < 3) { gettimeofday(&actual_time, NULL); if (timercmp(&actual_time, &end_time, >)) { *RspLen = 0; return (GE_IFD_MUTE); } wait_ms(TIMEOUT_STEP); G_SerPortStatus(portcom, &tx_length, &rx_length, &status); } /*------------------------------------------------------------------------------ The IFD response is read (RspLen is restored for the cases where we have received a R-Block from the reader). ------------------------------------------------------------------------------*/ *RspLen = rsplen_save; response = G_Oros3ReadResp(timeout, RspLen, Rsp); /*------------------------------------------------------------------------------ If a good message has been read Then Release the serial communication semaphore. <= G_OK ------------------------------------------------------------------------------*/ if (response == G_OK) { return (G_OK); } /*------------------------------------------------------------------------------ Else if a S-Block response has been received Then try_counter is reseted. ------------------------------------------------------------------------------*/ else if (response == GE_HI_RESYNCH) { try_counter = 0; cmdlen_used = CmdLen; resynch = FALSE; } /*------------------------------------------------------------------------------ If a communication error different from a R-Block message is raised Then cmdlen_used and timeout are initialized to send a R-Block. ------------------------------------------------------------------------------*/ else if (response != GE_HI_NACK) { cmdlen_used = 0; resynch = FALSE; timeout = HOR3COMM_NACK_TIME; } } cmdlen_used = 0; resynch = TRUE; timeout = HOR3COMM_NACK_TIME; } /*------------------------------------------------------------------------------ When we have exceeded the try counter, no communication is possible: RspLen is set to 0 and Release the serial communication semaphore. <= G_Oros3ReadResp status. ------------------------------------------------------------------------------*/ *RspLen = 0; return (response); } libgcr410-2.4.0.orig/or3gbpop.c0100644000175000017500000002551707354047734013516 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : OR3GBPOP.C * * Description : Implement the function which opens a communication channel with * an OROS 3.x IFD through Gemplus Block Protocol. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * - Manage the logical handle and not the physical port number. * 08/07/97: V4.30.002 (TF) * - Modify G_Oros3OpenComm function for Oros2.x reader. * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Information section - G_NAME is set to "Or3GBPOp" - G_RELEASE is set to "4.31.002" ------------------------------------------------------------------------------*/ #define G_NAME "Or3GBPOp" #define G_RELEASE "4.31.002" /*------------------------------------------------------------------------------ Pragma section - comment is called if _MSC_VER is defined. ------------------------------------------------------------------------------*/ #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif /*------------------------------------------------------------------------------ Include section Environment include: - windows.h gives general Windows 3.1 macros, values and functions. STRICT keyword is used to verify stricly variable types. This file is include only if windows version is required. ------------------------------------------------------------------------------*/ #ifdef G_WINDOWS #define STRICT #include #endif #ifdef G_OS2 #include #endif /*------------------------------------------------------------------------------ Compiler include: - string.h for _fmemcmp function. ------------------------------------------------------------------------------*/ #include #include #include /*------------------------------------------------------------------------------ Gemplus includes: - gemplus.h is used to define general macros and values. - gemgcr.h holds readers definitions - gtser.h manages the serial line communication. - gttimout.h manages timeout. - gtgbp.h manages Gemplus Block Protocol. - or3comm.h defines communication parameters. - gemansi.h is used to redefine functions for an Ansi code ------------------------------------------------------------------------------*/ #include "gemplus.h" #include "gemgcr.h" #include "gtser.h" #include "gttimout.h" #include "gtgbp.h" #include "or3comm.h" #include "debug.h" #include "ifd2gem.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif /*------------------------------------------------------------------------------ Module public interface. - or3gll.h ------------------------------------------------------------------------------*/ #include "or3gll.h" #ifdef G_DEBUG extern void G_DECL trace_debug_open(const INT16 Handle); #endif /*------------------------------------------------------------------------------ Function definition section: ------------------------------------------------------------------------------*/ /******************************************************************************* * INT16 G_DECL G_Oros3OpenComm * ( INT16 com_no, WORD32 BaudRate * ) * * Description : * ------------- * This function opens a communication channel with a GemCore >= 1.x IFD. It runs a * sequence to determine the currently in use baud rate and to set the IFD in * an idle mode from the communication protocol point of view. * * Remarks : * ------------- * Nothing. * * * In : * ------------- * - Port, BaudRate and ITNumber of the Param structure must be filled. * - Handle holds the logical number to manage. * * Out : * ------------- * Nothing. * * Responses : * ------------- * If everything is Ok: * - a handle on the communication channel (>= 0). * If an error condition is raised: * - GE_IFD_MUTE (- 201) if no communication is possible. * - GE_HOST_PORT_ABS (- 401) if port is not found on host or is locked by * another device. * - GE_HOST_PORT_OS (- 410) if a unexpected value has been returned by the * operating system. * - GE_HOST_PORT_OPEN (- 411) if the port is already opened. * - GE_HOST_MEMORY (- 420) if a memory allocation fails. * - GE_HOST_PARAMETERS (- 450) if one of the given parameters is out of the * allowed range or is not supported by hardware. * - GE_UNKNOWN_PB (-1000) if an unexpected problem is encountered. * Extern var : ------------- Nothing. Global var : ------------- Nothing. *******************************************************************************/ INT16 G_DECL G_Oros3OpenComm(const INT16 port_no, WORD32 BaudRate) { /*------------------------------------------------------------------------------ Local variables: - comm is used to open a serial communication channel. - r_buff and r_len are used to read IFD responses. - tx_size, rx_size and status are used to read port state. - timeout detects broken communication. - i is a loop index. - portcom memorises the opened port. - response holds the called function responses. ------------------------------------------------------------------------------*/ TGTSER_PORT comm; BYTE r_buff[HOR3GLL_OS_STRING_SIZE]; WORD16 r_len; WORD32 end_time; INT16 portcom, response; comm.Port = port_no; // (WORD16) Param->Comm.Serial.Port; // 2001 Modif-- // comm.BaudRate = 9600; comm.BaudRate = BaudRate; // --2001 Modif // comm.ITNumber = (WORD16) Param->Comm.Serial.ITNumber; comm.Mode = HGTSER_WORD_8 + HGTSER_NO_PARITY + HGTSER_STOP_BIT_1; comm.TimeOut = HOR3COMM_CHAR_TIMEOUT; comm.TxSize = HGTGBP_MAX_BUFFER_SIZE; comm.RxSize = HGTGBP_MAX_BUFFER_SIZE; response = portcom = G_SerPortOpen(&comm); DEBUG_MSG("G_SerPortOpenCalled"); if (response < G_OK) { return (response); } DEBUG_MSG("G_SerPortOpenCalled-checked resp"); /*------------------------------------------------------------------------------ The Gemplus Block Protocol is initialized. ------------------------------------------------------------------------------*/ G_GBPOpen(2, 4, portcom); DEBUG_MSG("Come after G_GBPOpen"); do { end_time = G_EndTime(HOR3COMM_CHAR_TIME); while (G_CurrentTime() < end_time) { } r_len = HOR3GLL_IFD_LEN_VERSION + 1; response = G_Oros3Exchange (HOR3GLL_LOW_TIME, 5, (BYTE G_FAR *) ("\x22\x05\x3F\xE0\x0D"), &r_len, r_buff); DEBUG_MSG("In Oros3OpenComm: resp=%d", response); if (response < G_OK) { // 2001 Modif-- /* * if (comm.BaudRate == 9600lu) { comm.BaudRate = 19200lu; } else * if (comm.BaudRate == 19200lu) { comm.BaudRate = 38400lu; } */ // Two Baud Rate allowed 9600 or 38400 if (comm.BaudRate == 9600L) { comm.BaudRate = 38400L; } // --2001 Modif else { G_GBPClose(); G_SerPortClose(portcom); return (GE_IFD_MUTE); } response = G_SerPortSetState(&comm); if (response < G_OK) { G_GBPClose(); G_SerPortClose(portcom); return (response); } } else { break; } } while (r_len != (HOR3GLL_IFD_LEN_VERSION + 1)); return (G_OK); } INT16 G_DECL G_ChangeIFDBaudRate(const INT16 port_no, DWORD baud_rate) { DWORD br; TGTSER_PORT comm; WORD16 rlen; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; INT16 response= G_OK ; // 2001 Modif-- WORD16 nUserNb; G_SerPortGetState(&comm, &nUserNb); // New BaudRate is the current one.Don't do anything and leave if (comm.BaudRate == baud_rate) return (G_OK); // --2001 Modif comm.Port = port_no; comm.BaudRate = baud_rate; comm.Mode = HGTSER_WORD_8 + HGTSER_NO_PARITY + HGTSER_STOP_BIT_1; comm.TimeOut = HOR3COMM_CHAR_TIMEOUT; comm.TxSize = HGTGBP_MAX_BUFFER_SIZE; comm.RxSize = HGTGBP_MAX_BUFFER_SIZE; // 2001 Modif-- // for(br = baud_rate; br >= 9600lu; br = br / 2) // Now the baud rate tested are 38400 AND 9600 only !!! for (br = baud_rate; br >= 9600L; br = br / 4) // --2001 Modif { // -------------------------------------------------------------- // The reader is switched to the selected value // (G_Oros3SIOConfigure). // The function status is not tested because, as the IFD has switched // immediatly, it is not possible to read its response. // ---------------------------------------------------------------- // 2001 Modif-- // printf("Premier G_Oros3SIOConfigure") ; // --2001 Modif rlen = HOR3GLL_BUFFER_SIZE; G_Oros3SIOConfigureNewBaudRate(br); // ---------------------------------------------------------------- // Host is switched to the selected value (G_SerPortSetState). // If this call is successful, // Then // The last SIO command is re-sent to read the IFD response. // response is optionnaly initialized with the translated IFD status. // ---------------------------------------------------------------- // 2001 Modif-- // printf(" G_SerPortSetState") ; // --2001 Modif comm.BaudRate = br; response = G_SerPortSetState(&comm); if (response == G_OK) { rlen = HOR3GLL_BUFFER_SIZE; // 2001 Modif-- // printf("Second G_Oros3SIOConfigure") ; // --2001 Modif response = G_Oros3SIOConfigure (HOR3GLL_LOW_TIME, 0, 8, comm.BaudRate, &rlen, rbuff); if (response >= G_OK) { response = GE_Translate(rbuff[0]); break; } } } if ((br < 9600) || (response != G_OK)) { return (GE_HI_COMM); } DEBUG_MSG("%d Baud Rate set", br); return (G_OK); } libgcr410-2.4.0.orig/or3gll.h0100644000175000017500000003124607354047734013166 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : or3GLL.H * * Description : Public interface for low level GemCore IFD module. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _OR3GLL_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _OR3GLL_H #define _OR3GLL_H /*------------------------------------------------------------------------------ Constant section: - HOR3GLL_DEFAULT_TIME is the default timeout for a command to be proceeded by an OROS3.X IFD. Today 5s (5000ms). - HOR3GLL_LOW_TIME is the timeout used for IFD management commands. Today 1s. - HOR3GLL_DEFAULT_VPP is the default VPP value. Today 0. - HOR3GLL_DEFAULT_PRESENCE is the default presence byte. Today 3 for no presence detection. - HOR3GLL_BUFFER_SIZE holds the size for the exchange buffers. We used the maximal size for TLP protocol to allow OROS3.X upgrades. - HOR3GLL_OS_STRING_SIZE is the size for a GemCore OS string. 13 characters are used for "GemCore-R1.00". ------------------------------------------------------------------------------*/ #define HOR3GLL_DEFAULT_TIME 5000 #define HOR3GLL_LOW_TIME 500 #define HOR3GLL_DEFAULT_VPP 0 #define HOR3GLL_DEFAULT_PRESENCE 3 #define HOR3GLL_BUFFER_SIZE 261 #define HOR3GLL_OS_STRING_SIZE HOR3GLL_IFD_LEN_VERSION+2 /*------------------------------------------------------------------------------ Reader list of commands: ------------------------------------------------------------------------------*/ #define HOR3GLL_IFD_CMD_MODE_SET "\x01\x00" #define HOR3GLL_IFD_CMD_SIO_SET 0x0A #define HOR3GLL_IFD_CMD_DIR "\x17\x00" #define HOR3GLL_IFD_CMD_ICC_DEFINE_TYPE 0x17 #define HOR3GLL_IFD_CMD_ICC_POWER_DOWN 0x11 #define HOR3GLL_IFD_CMD_ICC_POWER_UP 0x12 #define HOR3GLL_IFD_CMD_ICC_ISO_OUT 0x13 #define HOR3GLL_IFD_CMD_ICC_ISO_IN 0x14 #define HOR3GLL_IFD_CMD_ICC_APDU 0x15 #define HOR3GLL_IFD_CMD_ICC_SYNCHRONE 0x16 #define HOR3GLL_IFD_CMD_ICC_DISPATCHER "\x17\x01" #define HOR3GLL_IFD_CMD_ICC_STATUS 0x17 #define HOR3GLL_IFD_CMD_MOD_DEFINE_TYPE 0x1F #define HOR3GLL_IFD_CMD_MOD_POWER_DOWN 0x19 #define HOR3GLL_IFD_CMD_MOD_POWER_UP 0x1A #define HOR3GLL_IFD_CMD_MOD_ISO_OUT 0x1B #define HOR3GLL_IFD_CMD_MOD_ISO_IN 0x1C #define HOR3GLL_IFD_CMD_MOD_APDU 0x1D #define HOR3GLL_IFD_CMD_MOD_SYNCHRONE 0x1E #define HOR3GLL_IFD_CMD_MOD_DISPATCHER "\x1F\x01" #define HOR3GLL_IFD_CMD_MOD_STATUS 0x1F #define HOR3GLL_IFD_CMD_MEM_RD 0x22 #define HOR3GLL_IFD_CMD_MEM_WR 0x23 #define HOR3GLL_IFD_CMD_CPU_RD 0x24 #define HOR3GLL_IFD_CMD_CPU_WR 0x25 #define HOR3GLL_IFD_CMD_MEM_ERASE 0x26 #define HOR3GLL_IFD_CMD_MEM_SELECT 0x27 #define HOR3GLL_IFD_CMD_IO_RD 0x42 #define HOR3GLL_IFD_CMD_IO_WR 0x43 #define HOR3GLL_IFD_CMD_IO_BIT_WR 0x44 #define HOR3GLL_IFD_CMD_LCD_ON 0x2A #define HOR3GLL_IFD_CMD_LCD_OFF 0x29 #define HOR3GLL_IFD_CMD_LCD_CHAR 0x2C #define HOR3GLL_IFD_CMD_LCD_STRING 0x2B #define HOR3GLL_IFD_CMD_LCD_CMD 0x2D #define HOR3GLL_IFD_CMD_KEY_TIMEOUT 0x32 #define HOR3GLL_IFD_CMD_SOUND_BUZZER 0x33 #define HOR3GLL_IFD_CMD_RTC_RD 0x3A #define HOR3GLL_IFD_CMD_RTC_WR 0x3B /*------------------------------------------------------------------------------ Reader special address: ------------------------------------------------------------------------------*/ #define HOR3GLL_IFD_TYP_VERSION 0x05 #define HOR3GLL_IFD_ADD_VERSION 0x3FE0 #define HOR3GLL_IFD_LEN_VERSION 0x10 /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /*------------------------------------------------------------------------------ Prototype section: ------------------------------------------------------------------------------*/ INT16 G_DECL G_Oros3OpenComm ( const INT16 port_no, WORD32 BaudRate); INT16 G_DECL G_ChangeIFDBaudRate(const INT16 port_no, DWORD baud_rate); INT16 G_DECL G_Oros3Exchange (const WORD32 Timeout, const WORD16 CmdLen, const BYTE G_FAR Cmd[], WORD16 G_FAR * RspLen, BYTE G_FAR Rsp[]); INT16 G_DECL G_Oros3CloseComm( // const WORD16 Handle ); INT16 G_DECL G_Oros3SIOConfigure (const WORD32 Timeout, const INT16 Parity, const INT16 ByteSize, const WORD32 BaudRate, WORD16 G_FAR * RspLen, WORD8 G_FAR Rsp[]); // Modif 2001-- INT16 G_DECL G_Oros3SIOConfigureNewBaudRate(const WORD32 BaudRate); // --Modif 2001 INT16 G_DECL G_Oros3IccPowerDown (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IccPowerUp (const WORD32 Timeout, const BYTE ICCVcc, const BYTE PTSMode, const BYTE PTS0, const BYTE PTS1, const BYTE PTS2, const BYTE PTS3, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IsoOutput (const WORD32 Timeout, const WORD8 OrosCmd, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IsoInput (const WORD32 Timeout, const WORD8 OrosCmd, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IsoT1 (const WORD32 Timeout, const WORD8 OrosCmd, const WORD16 ApduLen, const WORD8 G_FAR ApduCommand[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IccIsoOutput (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IccIsoInput (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IccIsoT1 (const WORD32 Timeout, const WORD16 ApduLen, const WORD8 G_FAR ApduCommand[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3IccDefineType (const WORD32 Timeout, const WORD16 Type, const WORD16 Vpp, const WORD16 Presence, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModReset (const WORD32 Timeout, const BYTE ICCVcc, const BYTE PTSMode, const BYTE PTS0, const BYTE PTS1, const BYTE PTS2, const BYTE PTS3, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModDisactivate (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModIsoOutput (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModIsoInput (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModIsoT1 (const WORD32 Timeout, const WORD16 ApduLen, const WORD8 G_FAR ApduCommand[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModDefineType (const WORD32 Timeout, const WORD16 Type, const WORD16 Vpp, const WORD16 Presence, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModSelect (const WORD32 Timeout, const WORD16 Type, const WORD16 ModuleId, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3Dir (const WORD32 Timeout, const WORD16 Type, WORD16 G_FAR * Version, WORD16 G_FAR * Protocol); INT16 G_DECL G_Oros3ActivateDispatcher (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3SynchPowerUp (const WORD32 Timeout, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3SynchPowerDown (const WORD32 Timeout, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3SynchIsoCmd (const WORD32 Timeout, const WORD8 G_FAR Command[4], const WORD32 LIn, const WORD8 G_FAR DataIn[], const WORD32 LOut, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModActivateDispatcher (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModSynchPowerUp (const WORD32 Timeout, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModSynchPowerDown (const WORD32 Timeout, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ModSynchIsoCmd (const WORD32 Timeout, const WORD8 G_FAR Command[4], const WORD32 LIn, const WORD8 G_FAR DataIn[], const WORD32 LOut, const WORD32 CodeLen, const BYTE G_FAR * Code, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3SetMode (const WORD32 Timeout, const WORD16 Option, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ReadMemory (const WORD32 Timeout, const WORD16 MemoryType, const WORD16 Address, const WORD16 Length, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WriteMemory (const WORD32 Timeout, const WORD16 MemoryType, const WORD16 Address, const WORD16 Length, const BYTE G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ReadCPUPort (const WORD32 Timeout, const WORD16 Port, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WriteCPUPort (const WORD32 Timeout, const WORD16 Port, const WORD16 Value, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ClearMemory (const WORD32 Timeout, const WORD16 MemoryType, const WORD16 Address, const WORD16 Data, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3SelectPage (const WORD32 Timeout, const WORD16 Page, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3DisplayOff (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3DisplayOn (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3DisplayPrint (const WORD32 Timeout, const INT16 Pos, const char G_FAR * String, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3DisplayChar (const WORD32 Timeout, const WORD16 Character, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3DisplayCommand (const WORD32 Timeout, const WORD16 Command, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WaitKeyPressed (const WORD32 Timeout, const WORD16 Time, const INT32 Beep, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3Beep (const WORD32 Timeout, const WORD16 Frequency, const WORD16 Time, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ReadRTC (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WriteRTC (const WORD32 Timeout, const WORD16 Year, const WORD16 Month, const WORD16 Day, const WORD16 Hour, const WORD16 Minute, const WORD16 Second, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3ReadIO (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WriteIO (const WORD32 Timeout, const WORD16 Value, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3WriteIOBit (const WORD32 Timeout, const WORD16 BitNb, const INT32 Value, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]); INT16 G_DECL G_Oros3BufferSize (WORD16 G_FAR * Length, WORD8 G_FAR * Buffer); // Handy functions to decode ATR INT16 G_DECL FindTA1(BYTE * Atr, BYTE * TA1); #ifdef __cplusplus } #endif #endif libgcr410-2.4.0.orig/or3icc.c0100644000175000017500000003003707354047734013136 0ustar p2p2/*************************************************************************** or3icc.c - description ------------------- begin : Wed Apr 18 2001 copyright : (C) by 1991 - 2001 Gemplus ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include "gemplus.h" #include "gemgcr.h" #include "gtgbp.h" #include "t0cases.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "or3gll.h" #include "or3icc.h" #include "debug.h" INT16 G_DECL FindTA1(BYTE * Atr, BYTE * TA1) { if (Atr[1] & 0x10) { *TA1 = Atr[2]; return G_OK; } else { return -1; } } WORD16 Fi[] = { 372, 372, 558, 744, 1116, 1488, 1860, 0xFFFF, 0xFFFF, 512, 768, 1024, 1536, 2048, 0xFFFF, 0xFFFF }; WORD16 Di[] = { 0xFFFF, 1, 2, 4, 8, 16, 32, 0xFFFF, 12, 20, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF }; INT16 G_DECL GetAtrParams(BYTE * Atr, PPROTOCOL_OPTIONS Pro) { int i, j, l, k; int offset = 0; int loop = 1; BYTE ta1, ta3, tb3, tc1, tc2, tc3; BYTE F, D; short int InterfaceBytes[5][6]; double etu; double tmp; etu = 372.0 / 3.68; etu = etu / 1000000.0; for (i = 0; i < 5; ++i) for (j = 0; j < 6; ++j) InterfaceBytes[i][j] = -1; l = 1; while (Atr[l] & 0x80) { offset = 0; for (i = 0, k = 0x10; k > 0; k <<= 1, i++) { if (Atr[l] & k) { offset++; InterfaceBytes[loop - 1][i] = Atr[l + offset]; } } l += offset; ++loop; } if (InterfaceBytes[0][0] == -1) { InterfaceBytes[0][0] = 0x11; } ta1 = InterfaceBytes[0][0]; DEBUG_MSG("TA1=0x%x", InterfaceBytes[0][0]); F = (ta1 & 0xf0) >> 4; F &= 0x0f; D = (ta1 & 0x0f); Pro->Current_F = Fi[F]; Pro->Current_D = Di[D]; if (InterfaceBytes[0][2] == -1) // TC1 { InterfaceBytes[0][2] = 0; } tc1 = InterfaceBytes[0][2]; DEBUG_MSG("TC1=0x%x", tc1); tmp = 12 * etu; tmp += tc1 * etu; DEBUG_MSG("ETU = %f", etu); DEBUG_MSG("Guard Time = %f", tmp); Pro->Current_N = tc1; if (Pro->Protocol_Type == 1) { if (InterfaceBytes[1][2] == -1) { InterfaceBytes[1][2] = 10; // Default value for WI } tc2 = InterfaceBytes[1][2]; DEBUG_MSG("TC2=0x%x", tc2); Pro->Current_W = tc2; } if (Pro->Protocol_Type == 1) { if (InterfaceBytes[2][0] == -1) { InterfaceBytes[2][0] = 32; // IFSD Default } ta3 = InterfaceBytes[2][0]; DEBUG_MSG("TA3=0x%x", ta3); Pro->Current_IFSC = ta3; Pro->Current_IFSD = 32; DEBUG_MSG("TA3=0x%x", ta3); if (InterfaceBytes[2][1] == -1) // TB3 { InterfaceBytes[2][1] = 0x4d; } tb3 = InterfaceBytes[2][1]; Pro->Current_BWT = (tb3 & 0xf0) >> 4; Pro->Current_CWT = tb3 & 0x0f; if (InterfaceBytes[2][2] == -1) // TC3 { InterfaceBytes[2][2] = 0; } tc3 = InterfaceBytes[2][2]; Pro->Current_EBC = (tc3 & 0x01); DEBUG_MSG("TB3=0x%x, TC3=0x%x", tb3, tc3); } return G_OK; } INT16 G_DECL G_Oros3IccPowerUp (const WORD32 Timeout, const BYTE ICCVcc, const BYTE PTSMode, const BYTE PTS0, const BYTE PTS1, const BYTE PTS2, const BYTE PTS3, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { // ------------------------------------------------ // Local variables: // - response holds the called function responses. // - i is a counter. // - len holds the length of the command. // - CFG holds the PTS configuration parameter. // - PCK holds the PTS check parameter. // - cmd holds ICC reset command whose format is // <12h> [] [] [] [] [] [] // ------------------------------------------------------ INT16 response = 0; WORD16 i, len = 0; WORD8 CFG = 0, PCK, cmd[7]; WORD16 rlen = HOR3GLL_BUFFER_SIZE; WORD8 rbuff[HOR3GLL_BUFFER_SIZE]; // --------------------------------------------------------- // The command is sent to IFD with the PTS parameters. // <= G_Oros3Exchange status. // ---------------------------------------------------------- cmd[len++] = HOR3GLL_IFD_CMD_ICC_POWER_UP; switch (ICCVcc) { case ICC_VCC_3V: CFG = 0x02; break; case ICC_VCC_5V: CFG = 0x01; break; // 2001 Modif-- case (ICC_VCC_5_3V): CFG = 0x03; break; // --2001 Modif default: CFG = 0x00; break; } // 2001 Modif-- // printf("Switch PTS Mode < %02X> with PPS0 <%02X> PPS1 // <%02X>",PTSMode,PTS0,PTS1) ; // --2001 Modif switch (PTSMode) { case IFD_DEFAULT_MODE: case IFD_WITHOUT_PTS_REQUEST: CFG |= 0x10; cmd[len++] = CFG; response = G_Oros3Exchange(Timeout, len, cmd, RespLen, RespBuff); break; case IFD_NEGOTIATE_PTS_OPTIMAL: CFG |= 0x20; cmd[len++] = CFG; response = G_Oros3Exchange(Timeout, len, cmd, RespLen, RespBuff); break; case IFD_NEGOTIATE_PTS_MANUALLY: // first reset Icc without PTS management // CFG |= 0x10; // cmd[len++] = CFG; // response = G_Oros3Exchange(Timeout,len,cmd,RespLen,RespBuff); // if (response == G_OK) { // then send PTS parameters len = 1; CFG |= 0xF0; cmd[len++] = CFG; cmd[len++] = PTS0; if ((PTS0 & IFD_NEGOTIATE_PTS1) != 0) cmd[len++] = PTS1; if ((PTS0 & IFD_NEGOTIATE_PTS2) != 0) cmd[len++] = PTS2; if ((PTS0 & IFD_NEGOTIATE_PTS3) != 0) cmd[len++] = PTS3; // computes the exclusive-oring of all characters from CFG to // PTS3 PCK = 0xFF; for (i = 2; i < len; i++) { PCK ^= cmd[i]; } cmd[len++] = PCK; response = G_Oros3Exchange(Timeout, len, cmd, &rlen, rbuff); } break; /* * case IFD_DEFAULT_MODE: default: * * if (CFG != 0x00) { cmd[len++] = CFG; } response = * G_Oros3Exchange(Timeout,len,cmd,RespLen,RespBuff); break; */ } return (response); } INT16 G_DECL G_Oros3IccPowerDown (const WORD32 Timeout, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { BYTE cmd[1]; cmd[0] = HOR3GLL_IFD_CMD_ICC_POWER_DOWN; return (G_Oros3Exchange(Timeout, 1, cmd, RespLen, RespBuff)); } INT16 G_DECL G_Oros3IsoInput (const WORD32 Timeout, const WORD8 OrosCmd, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { WORD8 cmd[HOR3GLL_BUFFER_SIZE]; INT16 response; WORD16 resp_len = *RespLen; cmd[0] = OrosCmd; if (Command[COMMAND_LEN] <= (HGTGBP_MAX_DATA - 7)) { _fmemcpy(cmd + 1, Command, 5); _fmemcpy(cmd + 6, Data, Command[COMMAND_LEN]); return (G_Oros3Exchange (Timeout, (WORD16) (6 + Command[COMMAND_LEN]), cmd, RespLen, RespBuff)); } else if (Command[COMMAND_LEN] <= HT0CASES_LIN_SHORT_MAX) { _fmemcpy(cmd + 1, "\xFF\xFF\xFF\xFF", 4); cmd[5] = (WORD8) (Command[COMMAND_LEN] - 248); _fmemcpy(cmd + 6, Data + 248, cmd[5]); response = G_Oros3Exchange (Timeout, (WORD16) (6 + cmd[5]), cmd, &resp_len, RespBuff); if ((response != G_OK) || (RespBuff[0] != 0x00) || (resp_len != 1)) { if ((response == G_OK) && (RespBuff[0] == 0x1B)) { RespBuff[0] = 0x12; } return (response); } _fmemcpy(cmd + 1, Command, 5); _fmemcpy(cmd + 6, Data, 248); return (G_Oros3Exchange (Timeout, (WORD16) (6 + 248), cmd, RespLen, RespBuff)); } else { return (GE_HI_CMD_LEN); } } INT16 G_DECL G_Oros3IccIsoInput (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { return (G_Oros3IsoInput(Timeout, HOR3GLL_IFD_CMD_ICC_ISO_IN, Command, Data, RespLen, RespBuff)); } INT16 G_DECL G_Oros3IsoOutput (const WORD32 Timeout, const WORD8 OrosCmd, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { WORD8 cmd[6]; INT16 response; WORD16 resp_len; BYTE resp_buff[HOR3GLL_BUFFER_SIZE]; cmd[0] = OrosCmd; if ((Command[COMMAND_LEN] <= (HGTGBP_MAX_DATA - 3)) && (Command[COMMAND_LEN] != 0)) { _fmemcpy(cmd + 1, Command, 5); return (G_Oros3Exchange(Timeout, 6, cmd, RespLen, RespBuff)); } else if ((Command[COMMAND_LEN] > (HGTGBP_MAX_DATA - 3)) || (Command[COMMAND_LEN] == 0)) { _fmemcpy(cmd + 1, Command, 5); response = G_Oros3Exchange(Timeout, 6, cmd, RespLen, RespBuff); if ((response != G_OK) || (RespBuff[0] != 0x00)) { return (response); } _fmemcpy(cmd + 1, "\xFF\xFF\xFF\xFF", 4); if (Command[COMMAND_LEN] == 0x00) { cmd[5] = (WORD8) (256 - ((WORD8) (*RespLen - 1))); } else { cmd[5] -= ((WORD8) (*RespLen - 1)); } resp_len = HOR3GLL_BUFFER_SIZE; response = G_Oros3Exchange(Timeout, 6, cmd, &resp_len, resp_buff); if ((response != G_OK) || (resp_buff[0] != 0x00)) { _fmemcpy(RespBuff, resp_buff, resp_len); *RespLen = resp_len; return (response); } _fmemcpy(RespBuff + *RespLen, resp_buff + 1, resp_len - 1); *RespLen += (WORD16) (resp_len - 1); return (response); } else { return (GE_HI_CMD_LEN); } } INT16 G_DECL G_Oros3IccIsoOutput (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { return (G_Oros3IsoOutput(Timeout, HOR3GLL_IFD_CMD_ICC_ISO_OUT, Command, RespLen, RespBuff)); } INT16 G_DECL G_Oros3IsoT1 (const WORD32 Timeout, const WORD8 OrosCmd, const WORD16 ApduLen, const WORD8 G_FAR ApduCommand[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { INT16 response; WORD8 cmd[HOR3GLL_BUFFER_SIZE]; WORD16 length_expected, resp_len; BYTE resp_buff[HOR3GLL_BUFFER_SIZE]; cmd[0] = OrosCmd; if (ApduLen > 5) { if (ApduLen > (WORD16) (5 + ApduCommand[COMMAND_LEN])) { length_expected = ApduCommand[5 + ApduCommand[COMMAND_LEN]]; if (length_expected == 0) { length_expected = 256; } } else { length_expected = 0; } } else if (ApduLen == 5) { length_expected = ApduCommand[COMMAND_LEN]; if (length_expected == 0) { length_expected = 256; } } else if (ApduLen == 4) { length_expected = 0; } else { return (GE_HI_CMD_LEN); } if (length_expected + 3 > *RespLen) { return (GE_HI_CMD_LEN); } if (ApduLen > 261) { return (GE_HI_CMD_LEN); } if (ApduLen <= (HGTGBP_MAX_DATA - 1)) { _fmemcpy(cmd + 1, ApduCommand, ApduLen); response = G_Oros3Exchange(Timeout, (WORD16) (ApduLen + 1), cmd, RespLen, RespBuff); } else { _fmemcpy(cmd + 1, "\xFF\xFF\xFF\xFF", 4); cmd[5] = (WORD8) (ApduLen - (HGTGBP_MAX_DATA - 1)); _fmemcpy(cmd + 6, ApduCommand + (HGTGBP_MAX_DATA - 1), cmd[5]); resp_len = *RespLen; response = G_Oros3Exchange (Timeout, (WORD16) (6 + cmd[5]), cmd, RespLen, RespBuff); if ((response != G_OK) || (RespBuff[0] != 0x00) || (*RespLen != 1)) { return (response); } _fmemcpy(cmd + 1, ApduCommand, (HGTGBP_MAX_DATA - 1)); *RespLen = resp_len; response = G_Oros3Exchange(Timeout, (WORD16) HGTGBP_MAX_DATA, cmd, RespLen, RespBuff); } // 2001 Modif-- // printf("Le %02d RBuff[0] %02d Rlen %02d",length_expected,RespBuff[0] // ,*RespLen) ; // --2001 Modif if ((length_expected > 252) && (RespBuff[0] == 0x1B) && // 2001 Modif-- // (*RespLen == (HGTGBP_MAX_DATA - 1))) (*RespLen > (HGTGBP_MAX_DATA - 1))) // --2001 Modif { _fmemcpy(cmd + 1, "\xFF\xFF\xFF\xFF", 4); cmd[5] = (WORD8) (length_expected - *RespLen + 1); cmd[5] += 2; resp_len = HOR3GLL_BUFFER_SIZE; response = G_Oros3Exchange(Timeout, 6, cmd, &resp_len, resp_buff); if ((response != G_OK) || (resp_buff[0] != 0x00)) { _fmemcpy(RespBuff, resp_buff, resp_len); *RespLen = resp_len; return (response); } _fmemcpy(RespBuff + *RespLen, resp_buff + 1, resp_len - 1); *RespLen += (WORD16) (resp_len - 1); } return (response); } INT16 G_DECL G_Oros3IccIsoT1 (const WORD32 Timeout, const WORD16 ApduLen, const WORD8 G_FAR ApduCommand[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { return (G_Oros3IsoT1(Timeout, HOR3GLL_IFD_CMD_ICC_APDU, ApduLen, ApduCommand, RespLen, RespBuff)); } libgcr410-2.4.0.orig/or3icc.h0100644000175000017500000000007707354047734013144 0ustar p2p2INT16 G_DECL GetAtrParams(BYTE * Atr, PROTOCOL_OPTIONS * Pro); libgcr410-2.4.0.orig/or3utils.c0100644000175000017500000000442507354047734013542 0ustar p2p2/*************************************************************************** or3utils.c - description ------------------- begin : Wed Apr 18 2001 copyright : (C) by 1991 - 2001 Gemplus email : ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include "gemplus.h" #include "gemgcr.h" #include "or3comm.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "or3gll.h" #include "or3utils.h" INT16 G_DECL G_Oros3ReadMemory (const WORD32 Timeout, const WORD16 MemoryType, const WORD16 Address, const WORD16 Length, WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]) { // -------------------------------------------------------------- // Local variables: // - cmd holds the read memory command whose format is // <22h> // -------------------------------------------------------------- WORD8 cmd[5] = { HOR3GLL_IFD_CMD_MEM_RD}; cmd[1] = (WORD8) MemoryType; cmd[2] = HIBYTE(Address); cmd[3] = LOBYTE(Address); cmd[4] = (WORD8) Length; return (G_Oros3Exchange(Timeout, 5, cmd, RespLen, RespBuff)); } INT16 G_DECL G_Oros3String(WORD16 G_FAR * OsLength, char G_FAR * OsString) { return (G_Oros3ReadMemory (HOR3GLL_LOW_TIME, HOR3GLL_IFD_TYP_VERSION, HOR3GLL_IFD_ADD_VERSION, HOR3GLL_IFD_LEN_VERSION, OsLength, (WORD8 G_FAR *) OsString)); } INT16 G_DECL G_Oros3BufferSize(WORD16 G_FAR * Length, WORD8 G_FAR * Buffer) { WORD8 cmd[1] = { 0x0A}; return (G_Oros3Exchange(HOR3GLL_LOW_TIME, 1, cmd, Length, Buffer)); } libgcr410-2.4.0.orig/or3utils.h0100644000175000017500000000011407354047734013536 0ustar p2p2INT16 G_DECL G_Oros3String(WORD16 G_FAR * OsLength, char G_FAR * OsString); libgcr410-2.4.0.orig/Readme0100644000175000017500000000415507355062611012722 0ustar p2p2Gemplus GCR GemCore Reader Driver for PC/SC Linux ================================================= This library provides a PCSC IFD handler implementation for Gemplus GemCore based smart cards readers GemPC410 and maybe some others. This package is needed to communicate with the Gemplus smartcard readers through the PCSC Lite resource manager. Original author: Gemplus Changes : 1.7 Gemplus 2.0 maintener : Gemplus 2.1 maintener : Ludovic Rousseau 2.4 maintener : Gemplus - Improvement of error management. - Support of EMV readers. License: GNU General Public Licence SUPPORTED SMART CARD READERS ============================ Smart Card driver supported: - GemPC 410 with GemCore 1.118 : OK - GemPC 410 with GemCore 1.21 : OK - Gemplus EMV Reader : OK - others : not tested INSTALL ======= IFD Handler ----------- Remark: The IFD Handler has been tested with pcsc-lite-0.9.3 extract library $ tar -xvzf gp-core-2.4.tar.gz compile the library $ make PCSC Lite --------- You need first to install the Resource Manager. Please refer to the install files provided with pcsc-lite. You can get PCSC lite on the MUSCLE (Movement for the Use of Smart Cards in a Linux Environment) web site [1]. PCSC config file ---------------- You need to edit the file /etc/reader.conf created during the installation of PCSC lite. Add the following lines: FRIENDLYNAME "Gemplus GemPC410 Reader" DEVICENAME GEMCORE LIBPATH /libgp_core.so CHANNELID 0x0103F8 You may need to change CHANNELID if your smart card reader is not connected to /dev/ttyS0. Restart PCSC lite ----------------- You need to restart PCSC lite to complete the installation. You may find a starting script under /etc/rc.? Links --------- *Official Gemplus Version [1] http://www.linuxnet.com/middle.html * Other resources [2] http://ludovic.rousseau.free.fr/softwares/gp-core/gp-core.html libgcr410-2.4.0.orig/t0case1.c0100644000175000017500000000551707354047734013221 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : T0Case1.c * * Description : Module which manages transportation of APDUs by T=0 for case 1. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ #define G_NAME "T0Case1" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "gemgcr.h" #include "ifd2gem.h" #include "t0cases.h" INT16 G_DECL G_T0Case1 (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { BYTE cmd[5], resp[3]; WORD16 rlen = 3; INT16 response; _fmemcpy(cmd, ApduComm->Command, COMMAND_LEN); cmd[HT0CASES_P3] = 0; response = IsoIn(Timeout, cmd, NULL, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } if (rlen < 3) { return (GE_HI_LEN); } ApduResp->LengthOut = 0; ApduResp->Status = (WORD16) ((resp[rlen - 2] << 8) + resp[rlen - 1]); return (G_OK); } libgcr410-2.4.0.orig/t0case2.c0100644000175000017500000001066507354047734013222 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : T0Case2.c * * Description : Module which manages transportation of APDUs by T=0 for case 2. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ #define G_NAME "T0Case2" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "gemgcr.h" #include "ifd2gem.h" #include "t0cases.h" INT16 G_DECL G_T0Case2S (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { /*------------------------------------------------------------------------------ Local variables: - cmd is a buffer which is filled with the five command bytes to send to ICC. One more byte could be used for NULL_LEN command transport. - resp is a buffer of 3 bytes which receives the IFD response: - rlen is used to call IsoIn function. It indicates the response buffer size at call and is updated with the real number of read bytes. It is initialized to 3. - response holds called function responses. ------------------------------------------------------------------------------*/ BYTE cmd[6], resp[3]; WORD16 rlen = 3; INT16 response; /*------------------------------------------------------------------------------ The cmd buffer is initialized with the 4 command bytes found in ApduComm. Then Lc character is added according to Annex A of ISO/IEC 7816-4: 1993(E). !! THE CALLER MUST VERIFY THAT ApduComm->LengthIn IS IN [1 .. 255] !! ------------------------------------------------------------------------------*/ _fmemcpy(cmd, ApduComm->Command, COMMAND_LEN); cmd[HT0CASES_P3] = (BYTE) ApduComm->LengthIn; /*------------------------------------------------------------------------------ The communication phase is triggered by calling IsoIn function. <= Test the IsoIn status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). <= Test the response length (>= 3): GE_HI_LEN ------------------------------------------------------------------------------*/ response = IsoIn(Timeout, cmd, ApduComm->DataIn, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } if (rlen < 3) { return (GE_HI_LEN); } /*------------------------------------------------------------------------------ The ApduResp structure is updated (LengthOut and Status) and <= G_OK. ------------------------------------------------------------------------------*/ ApduResp->LengthOut = 0; ApduResp->Status = (WORD16) ((resp[rlen - 2] << 8) + resp[rlen - 1]); return (G_OK); } libgcr410-2.4.0.orig/t0case3.c0100644000175000017500000004266407354047734013227 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : T0Case3.c * * Description : Module which manages transportation of APDUs by T=0 for case 3. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ #define G_NAME "T0Case3" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "gemgcr.h" #include "ifd2gem.h" #include "t0cases.h" INT16 G_DECL G_T0Case3S (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { /*------------------------------------------------------------------------------ Local variables: - cmd is a buffer which is filled with the five command bytes to send to ICC. - resp is a buffer of HT0CASES_MAX_SIZE bytes which receives the IFD response: [Up to 256 bytes] - rlen is used to call IsoIn function. It indicates the response buffer size at call and is updated with the real number of read bytes. It is initialized to HT0CASES_MAX_SIZE (259). - length is used for sending GET_RESPONSE command in loop. - ptr is a huge pointer used to fill ApduResp without wraparound. - response holds called function responses. ------------------------------------------------------------------------------*/ BYTE cmd[5], resp[HT0CASES_MAX_SIZE]; WORD16 rlen = HT0CASES_MAX_SIZE, length; BYTE G_HUGE *ptr; INT16 response; /*------------------------------------------------------------------------------ The cmd buffer is initialized with the 4 command bytes found in ApduComm. Then Le character is added according to Annex A of ISO/IEC 7816-4: 1993(E). !! THE CALLER MUST VERIFY THAT ApduComm->LengthExpected IS IN [1 .. 256] !! ------------------------------------------------------------------------------*/ _fmemcpy(cmd, ApduComm->Command, COMMAND_LEN); cmd[HT0CASES_P3] = (BYTE) ApduComm->LengthExpected; /*------------------------------------------------------------------------------ The communication phase is triggered by calling IsoOut function. <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). <= Test the response length (>= 3): GE_HI_LEN ------------------------------------------------------------------------------*/ response = IsoOut(Timeout, cmd, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } if (rlen < 3) { return (GE_HI_LEN); } /*------------------------------------------------------------------------------ According to the SW1 byte: - CASE_3S_2, Le definitely not accepted. LengthOut field is set to 0. ------------------------------------------------------------------------------*/ switch (resp[rlen - 2]) { case HT0CASES_CASE_3S_2: { ApduResp->LengthOut = 0; break; } /*------------------------------------------------------------------------------ - CASE_3S_3, Le not accepted, La indicated. The command is re-issued with La assigned to P3 parameter. <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). ------------------------------------------------------------------------------*/ case HT0CASES_CASE_3S_3: { cmd[HT0CASES_P3] = resp[rlen - 1]; rlen = HT0CASES_MAX_SIZE; response = IsoOut(Timeout, cmd, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ ApduResp is updated: If only three bytes have been received Then No data are available, LengthOut is set to 0. Else LengthOut is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ if (rlen == 3) { ApduResp->LengthOut = 0; } else { ApduResp->LengthOut = HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, (size_t) ApduResp->LengthOut); } break; } /*------------------------------------------------------------------------------ - CASE_3S_4, Command processed, Lx indicated. The received bytes are stored: If only three bytes have been received Then No data are available, length is set to 0. Else length is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ case HT0CASES_CASE_3S_4: case HT0CASES_CASE_3S_4_SIM: { if (rlen == 3) { length = 0; } else { length = (WORD16) HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, length); } ApduResp->LengthOut = length; /*------------------------------------------------------------------------------ GET RESPONSE command is issued with Lx assigned to P3 parameter: The command is built and parameter P1 is updated for chaining GET RESPONSE. ------------------------------------------------------------------------------*/ if (cmd[HT0CASES_INS] == HT0CASES_GET_RESPONSE) { cmd[HT0CASES_P1] = (BYTE) ((cmd[HT0CASES_P1] + 1) % 2); } else { cmd[HT0CASES_INS] = HT0CASES_GET_RESPONSE; cmd[HT0CASES_P1] = 0x00; } cmd[HT0CASES_P2] = 0x00; /*------------------------------------------------------------------------------ While CASE_3S_4 is detected and bytes are still awaited, P3 byte is updated with last received Lx, The command is sent <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). ApduResp is updated with the received bytes. P1 parameter is updated for the next loop. ------------------------------------------------------------------------------*/ while ( ( (resp[rlen - 2] == HT0CASES_CASE_3S_4) || (resp[rlen - 2] == HT0CASES_CASE_3S_4_SIM)) && (ApduResp->LengthOut < ApduComm->LengthExpected)) { cmd[HT0CASES_P3] = resp[rlen - 1]; rlen = HT0CASES_MAX_SIZE; response = IsoOut(Timeout, cmd, &rlen, resp); if (response == G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } if (rlen == 3) { break; } else { length = (WORD16) HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); ptr = ApduResp->DataOut + ApduResp->LengthOut; _fmemcpy(ptr, resp + 1, length); ApduResp->LengthOut += length; } cmd[HT0CASES_P1] = (BYTE) ((cmd[HT0CASES_P1] + 1) % 2); } break; } /*------------------------------------------------------------------------------ - Other cases must be CASE_3S_1, Le accepted. ApduResp is updated: If only three bytes have been received Then No data are available, LengthOut is set to 0. Else LengthOut is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ default: { if (rlen == 3) { ApduResp->LengthOut = 0; } else { ApduResp->LengthOut = HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, (size_t) ApduResp->LengthOut); } } } /*------------------------------------------------------------------------------ The status part of ApduResp is updated with the two last received bytes. ------------------------------------------------------------------------------*/ ApduResp->Status = (WORD16) ((resp[rlen - 2] << 8) + resp[rlen - 1]); /*------------------------------------------------------------------------------ If LengthExpected == LengthOut Then <= G_OK Else <= GW_APDU_LE ------------------------------------------------------------------------------*/ if (ApduComm->LengthExpected == ApduResp->LengthOut) { return (G_OK); } else { return (GW_APDU_LE); } } INT16 G_DECL G_T0Case3E (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { /*------------------------------------------------------------------------------ Local variables: - cmd is a buffer which is filled with the five command bytes to send to ICC. - resp is a buffer of HT0CASES_MAX_SIZE bytes which receives the IFD response: [Up to 256 bytes] - rlen is used to call IsoIn function. It indicates the response buffer size at call and is updated with the real number of read bytes. It is initialized to HT0CASES_MAX_SIZE (259). - length is used for sending GET_RESPONSE command in loop. - ptr is a huge pointer used to fill ApduResp without wraparound. - response holds called function responses. ------------------------------------------------------------------------------*/ BYTE cmd[5], resp[HT0CASES_MAX_SIZE]; WORD16 rlen = HT0CASES_MAX_SIZE, length; BYTE G_HUGE *ptr; INT16 response; /*------------------------------------------------------------------------------ The cmd buffer is initialized with the 4 command bytes found in ApduComm. Then 0 is added according to Annex A of ISO/IEC 7816-4: 1993(E). !! THE CALLER MUST VERIFY THAT ApduComm->LengthExpected IS IN > 256] !! ------------------------------------------------------------------------------*/ _fmemcpy(cmd, ApduComm->Command, COMMAND_LEN); cmd[HT0CASES_P3] = 0; /*------------------------------------------------------------------------------ The communication phase is triggered by calling IsoOut function. <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). ------------------------------------------------------------------------------*/ response = IsoOut(Timeout, cmd, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ According to the SW1 byte: - CASE_3E_2A, the card rejected the command because of wrong length LengthOut field is set to 0. ------------------------------------------------------------------------------*/ switch (resp[rlen - 2]) { case HT0CASES_CASE_3E_2A: { ApduResp->LengthOut = 0; break; } /*------------------------------------------------------------------------------ - CASE_3E_2B, wrong length but right length is indicated in La The command is re-issued with La assigned to P3 parameter. <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). ------------------------------------------------------------------------------*/ case HT0CASES_CASE_3E_2B: { cmd[HT0CASES_P3] = resp[rlen - 1]; rlen = HT0CASES_MAX_SIZE; response = IsoOut(Timeout, cmd, &rlen, resp); if (response >= G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ ApduResp is updated: If only three bytes have been received Then No data are available, LengthOut is set to 0. Else LengthOut is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ if (rlen == 3) { ApduResp->LengthOut = 0; } else { ApduResp->LengthOut = HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, (size_t) ApduResp->LengthOut); } break; } /*------------------------------------------------------------------------------ - CASE_3E_2D, Lx indicates the extra amount of bytes availables. The received bytes are stored: If only three bytes have been received Then No data are available, length is set to 0. Else length is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ case HT0CASES_CASE_3E_2D: case HT0CASES_CASE_3E_2D_SIM: { if (rlen == 3) { length = 0; } else { length = (WORD16) HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, length); } ApduResp->LengthOut = length; /*------------------------------------------------------------------------------ GET RESPONSE command is issued with Lx assigned to P3 parameter: The command is built and parameter P1 is updated for chaining GET RESPONSE. ------------------------------------------------------------------------------*/ if (cmd[HT0CASES_INS] == HT0CASES_GET_RESPONSE) { cmd[HT0CASES_P1] = (BYTE) ((cmd[HT0CASES_P1] + 1) % 2); } else { cmd[HT0CASES_INS] = HT0CASES_GET_RESPONSE; cmd[HT0CASES_P1] = 0x00; } cmd[HT0CASES_P2] = 0x00; /*------------------------------------------------------------------------------ While CASE_3E_2D is detected and bytes are still awaited, P3 byte is updated with last received Lx, The command is sent <= Test the IsoOut status (>=G_OK) and the IFD status (GE_Translate(Status)>=0). ApduResp is updated with the received bytes. P1 parameter is updated for the next loop. ------------------------------------------------------------------------------*/ while ( ( (resp[rlen - 2] == HT0CASES_CASE_3E_2D) || (resp[rlen - 2] == HT0CASES_CASE_3E_2D_SIM)) && (ApduResp->LengthOut < ApduComm->LengthExpected)) { cmd[HT0CASES_P3] = resp[rlen - 1]; rlen = HT0CASES_MAX_SIZE; response = IsoOut(Timeout, cmd, &rlen, resp); if (response == G_OK) { response = GE_Translate(resp[0]); } if (response < G_OK) { return (response); } if (rlen == 3) { break; } else { length = (WORD16) HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); ptr = ApduResp->DataOut + ApduResp->LengthOut; _fmemcpy(ptr, resp + 1, length); ApduResp->LengthOut += length; } cmd[HT0CASES_P1] = (BYTE) ((cmd[HT0CASES_P1] + 1) % 2); } break; } /*------------------------------------------------------------------------------ - Other cases must be CASE_3E_2C, No more byte to receive. ApduResp is updated: If only three bytes have been received Then No data are available, LengthOut is set to 0. Else LengthOut is set to Min(LengthExpected, P3). DataOut buffer is updated. ------------------------------------------------------------------------------*/ default: { if (rlen == 3) { ApduResp->LengthOut = 0; } else { ApduResp->LengthOut = HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(cmd[HT0CASES_P3])); _fmemcpy(ApduResp->DataOut, resp + 1, (size_t) ApduResp->LengthOut); } } } /*------------------------------------------------------------------------------ The status part of ApduResp is updated with the two last received bytes. ------------------------------------------------------------------------------*/ ApduResp->Status = (WORD16) ((resp[rlen - 2] << 8) + resp[rlen - 1]); /*------------------------------------------------------------------------------ If LengthExpected == LengthOut Then <= G_OK Else <= GW_APDU_LE ------------------------------------------------------------------------------*/ if (ApduComm->LengthExpected == ApduResp->LengthOut) { return (G_OK); } else { return (GW_APDU_LE); } } libgcr410-2.4.0.orig/t0case4.c0100644000175000017500000002303607354047734013220 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : T0Case4.c * * Description : Module which manages transportation of APDUs by T=0 for case 4. * * * Compiler : Microsoft C PDS 6.0 / 7.0 /8.0 * Borland C++ 3.x / 4.0 * Microsoft C++ 1.5 for Windows 16 bits * Microsoft C++ 2.0 for Windows 32 bits * Borland C++ 2.0 pour OS/2 * * Host : IBM PC and compatible machines under MS/DOS 3.1 and upper. * IBM PC and compatible machines under Windows 3.x. * IBM PC and compatible machines under Windows 32 bits (W95 or WNT). * IBM PC and compatible machines under OS/2 Warp. * * Release : 4.31.002 * * Last Modif : 24/08/98: V4.31.002 (GP) * 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : * * Remark : * *******************************************************************************/ #define G_NAME "T0Case4" #define G_RELEASE "4.31.002" #ifdef _MSC_VER #pragma comment(exestr,"Gemplus(c) "G_NAME" Ver "G_RELEASE" "__DATE__) #endif #include #include #include "gemplus.h" #if (defined WIN32) || (defined G_UNIX) || (defined G_OS2) #include "gemansi.h" #endif #include "gemgcr.h" #include "ifd2gem.h" #include "t0cases.h" INT16 G_DECL G_T0Case4S (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]), INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { /*------------------------------------------------------------------------------ Local variables: - apdu_in is used to call GET_RESPONSE Command. - response holds called function responses. ------------------------------------------------------------------------------*/ G4_APDU_COMM apdu_in; INT16 response; /*------------------------------------------------------------------------------ The first part of the command is sent by calling G_T0Case2S. <= Test G_T0Case2S status (>=0). ------------------------------------------------------------------------------*/ response = G_T0Case2S(Timeout, ApduComm, ApduResp, IsoIn); if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ GET_RESPONSE command is buit in apdu_in. ------------------------------------------------------------------------------*/ apdu_in.Command[0] = ApduComm->Command[0]; apdu_in.Command[1] = HT0CASES_GET_RESPONSE; apdu_in.Command[2] = 0; apdu_in.Command[3] = 0; apdu_in.LengthIn = 0; /*------------------------------------------------------------------------------ According to the SW1 byte: - CASE_4S_2, command accepted. GET_RESPONSE is sent with Le in parameter 3 by calling G_T0Case3S command. <= G_T0Case3S status. ------------------------------------------------------------------------------*/ switch (HIBYTE(ApduResp->Status)) { case HT0CASES_CASE_4S_2: { apdu_in.LengthExpected = ApduComm->LengthExpected; return (G_T0Case3S(Timeout, &apdu_in, ApduResp, IsoOut)); } /*------------------------------------------------------------------------------ - CASE_4S_3, command accepted with information added. GET_RESPONSE is sent with minimum of Le and LengthExpected in parameter 3 by calling G_T0Case3S command.. ------------------------------------------------------------------------------*/ case HT0CASES_CASE_4S_3: case HT0CASES_CASE_4S_3_SIM: { apdu_in.LengthExpected = HT0CASES_MIN (ApduComm->LengthExpected, (WORD32) HT0CASES_VAL(LOBYTE(ApduResp->Status))); response = G_T0Case3S(Timeout, &apdu_in, ApduResp, IsoOut); /*------------------------------------------------------------------------------ If the call fails <= G_T0Case3S status. ------------------------------------------------------------------------------*/ if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ Else if we have read the expected number of bytes <= G_OK ------------------------------------------------------------------------------*/ else if (ApduComm->LengthExpected == ApduResp->LengthOut) { return (G_OK); } /*------------------------------------------------------------------------------ Else <= GW_APDU_LE ------------------------------------------------------------------------------*/ else { return (GW_APDU_LE); } } } /*------------------------------------------------------------------------------ All others cases (CASE 4S.1 in particular) return <= GW_APDU_LE ------------------------------------------------------------------------------*/ return (GW_APDU_LE); } INT16 G_DECL G_T0Case4E (const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) (const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[]), INT16(G_DECL * IsoOut) (const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[])) { /*------------------------------------------------------------------------------ Local variables: - apdu_in is used to call GET_RESPONSE Command. - response holds called function responses. ------------------------------------------------------------------------------*/ G4_APDU_COMM apdu_in; INT16 response; /*------------------------------------------------------------------------------ CASE_4E_2 is not supported: If Lc > 255 Then <= a builded WRONG LENGTH Apdu is returned with GW_APDU_LE. ------------------------------------------------------------------------------*/ if (ApduComm->LengthIn > 255) { ApduResp->LengthOut = 0; ApduResp->Status = HT0CASES_WRONG_LENGTH; return (GW_APDU_LE); } /*------------------------------------------------------------------------------ CASE_4E_1 is treated: The first part of the command is sent by calling G_T0Case2S. <= Test G_T0Case2S status (>=0). ------------------------------------------------------------------------------*/ response = G_T0Case2S(Timeout, ApduComm, ApduResp, IsoIn); if (response < G_OK) { return (response); } /*------------------------------------------------------------------------------ GET_RESPONSE command is buit in apdu_in. ------------------------------------------------------------------------------*/ apdu_in.Command[0] = ApduComm->Command[0]; apdu_in.Command[1] = HT0CASES_GET_RESPONSE; apdu_in.Command[2] = 0; apdu_in.Command[3] = 0; apdu_in.LengthIn = 0; /*------------------------------------------------------------------------------ According to the SW1 byte: - CASE_4E_1B, command accepted. GET_RESPONSE is sent with 0 in parameter 3 because LengthExpected is greater than 256 (True case 4E !). This command is sent by G_T0Case3E. <= G_T0Case3E status. ------------------------------------------------------------------------------*/ switch (HIBYTE(ApduResp->Status)) { case HT0CASES_CASE_4E_1B: { apdu_in.LengthExpected = ApduComm->LengthExpected; return (G_T0Case3E(Timeout, &apdu_in, ApduResp, IsoOut)); } /*------------------------------------------------------------------------------ - CASE_4E_1C, command accepted with information added. If the number of available bytes is lower than 256 Then The needed bytes are read by calling G_T0Case3S. If the call fails <= G_T0Case3S status. Else <= GW_APDU_LE (True 4E => LengthExpected > 255 !). ------------------------------------------------------------------------------*/ case HT0CASES_CASE_4E_1C: case HT0CASES_CASE_4E_1C_SIM: { if (HT0CASES_VAL(LOBYTE(ApduResp->Status)) < 256) { apdu_in.LengthExpected = LOBYTE(ApduResp->Status); response = G_T0Case3S(Timeout, &apdu_in, ApduResp, IsoOut); if (response < G_OK) { return (response); } else { return (GW_APDU_LE); } } /*------------------------------------------------------------------------------ Else The needed bytes are read by calling G_T0Case3E. <= G_T0Case3E status. ------------------------------------------------------------------------------*/ else { apdu_in.LengthExpected = ApduComm->LengthExpected; return (G_T0Case3E(Timeout, &apdu_in, ApduResp, IsoOut)); } } } /*------------------------------------------------------------------------------ - others cases (in particular CASE 4E.1A), we have not read the needed bytes so <= GW_APDU_LE (True 4E => LengthExpected > 255 !). ------------------------------------------------------------------------------*/ return (GW_APDU_LE); } libgcr410-2.4.0.orig/t0cases.h0100644000175000017500000001535507354047734013331 0ustar p2p2 /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /******************************************************************************* * Copyright (c) 1991 - 2001 Gemplus * * Name : T0Cases * * Description : Module which gathers individual function for APDU transport in * T=0 protocole. * * Release : 4.31.001 * * Last Modif : 13/10/97: V4.31.001 (GP) * 18/03/97: V4.30.001 (TF) * - Start of development. * ******************************************************************************** * * Warning : The 7616-4 standard indicates that only the transmission system * can initiate GET_RESPONSE and ENVELOPE command. This two * commands cannot be transmitted by this module. * * Remark : The true cases 2E and 4E.2 are not supported because the command * ENVELOPE is not supported by this module. * *******************************************************************************/ /*------------------------------------------------------------------------------ Name definition: _T0CASES_H is used to avoid multiple inclusion. ------------------------------------------------------------------------------*/ #ifndef _T0CASES_H #define _T0CASES_H /*------------------------------------------------------------------------------ Constant section - HT0CASES_MAX_SIZE define the maximum size for a T=0 response command. - HT0CASES_LIN_SHORT_MAX define the maximum Lin value for a short case. - HT0CASES_LEX_SHORT_MAX define the maximum Lexpected value for a short case. ------------------------------------------------------------------------------*/ #define HT0CASES_MAX_SIZE 259 #define HT0CASES_LIN_SHORT_MAX 255 #define HT0CASES_LEX_SHORT_MAX 256 /*------------------------------------------------------------------------------ - Byte position in T=0 commands. ------------------------------------------------------------------------------*/ #define HT0CASES_INS 1 #define HT0CASES_P1 2 #define HT0CASES_P2 3 #define HT0CASES_P3 4 /*------------------------------------------------------------------------------ - ISO command length. ------------------------------------------------------------------------------*/ #define CMD_SIZE 5lu /*------------------------------------------------------------------------------ - Flags for recognized cases. ------------------------------------------------------------------------------*/ #define HT0CASES_CASE_3S_2 0x67 #define HT0CASES_CASE_3S_3 0x6C #define HT0CASES_CASE_3S_4 0x61 #define HT0CASES_CASE_3S_4_SIM 0x9F #define HT0CASES_CASE_4S_2 0x90 #define HT0CASES_CASE_4S_3 0x61 #define HT0CASES_CASE_4S_3_SIM 0x9F #define HT0CASES_CASE_3E_2A 0x67 #define HT0CASES_CASE_3E_2B 0x6C #define HT0CASES_CASE_3E_2D 0x61 #define HT0CASES_CASE_3E_2D_SIM 0x9F #define HT0CASES_CASE_4E_1 0x0100 #define HT0CASES_CASE_4E_1B 0x90 #define HT0CASES_CASE_4E_1C 0x61 #define HT0CASES_CASE_4E_1C_SIM 0x9F #define HT0CASES_WRONG_LENGTH 0x6700 /*------------------------------------------------------------------------------ - Get response INS byte. ------------------------------------------------------------------------------*/ #define HT0CASES_GET_RESPONSE 0xC0 /*------------------------------------------------------------------------------ Macro section - MIN returns the lower of two values. - VAL calculates the real length returned by an IsoOut command. ------------------------------------------------------------------------------*/ #define HT0CASES_MIN(a,b) (((a) < (b)) ? (a) : (b)) #define HT0CASES_VAL(a) (((a) == 0) ? 256 : (a)) /*------------------------------------------------------------------------------ C++ Section: ------------------------------------------------------------------------------*/ #ifdef __cplusplus extern "C" { #endif /* */ /*------------------------------------------------------------------------------ Prototype section ------------------------------------------------------------------------------*/ INT16 G_DECL G_T0Case1 ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); INT16 G_DECL G_T0Case2S ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); INT16 G_DECL G_T0Case3S ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoOut) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); INT16 G_DECL G_T0Case3E ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoOut) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); INT16 G_DECL G_T0Case4S ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ), INT16(G_DECL * IsoOut) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); INT16 G_DECL G_T0Case4E ( const WORD32 Timeout, const G4_APDU_COMM G_FAR * ApduComm, G4_APDU_RESP G_FAR * ApduResp, INT16(G_DECL * IsoIn) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], const WORD8 G_FAR Data[], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ), INT16(G_DECL * IsoOut) ( const WORD32 Timeout, const WORD8 G_FAR Command[5], WORD16 G_FAR * RespLen, BYTE G_FAR RespBuff[] ) ); #ifdef __cplusplus } #endif /* */ #endif /* */