From 54382009f78b3e2d784d2a802a6d77b61b5a13a6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 01:34:32 +0100 Subject: [PATCH 01/29] Converted documentaion files to Markdown; Updated all content to current version; Added some credit; --- CREDITS | 2 -- CREDITS.md | 11 ++++++ README.md | 100 ++++++++++++++++++++++++++++------------------------ TODO | 15 -------- TODO.md | 17 +++++++++ package.xml | 13 +++---- php_pcsc.h | 2 +- 7 files changed, 89 insertions(+), 71 deletions(-) delete mode 100644 CREDITS create mode 100644 CREDITS.md delete mode 100644 TODO create mode 100644 TODO.md diff --git a/CREDITS b/CREDITS deleted file mode 100644 index 6f9c6d2..0000000 --- a/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -pcsc -Johann Dantant, Johannes Findeisen, Marco Schuster, Calvin Buckley diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..68ab9e7 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,11 @@ +# Contributors + +## In alphabetical order: + + * Johann Dantant (Original author) + * Anatol Belski (Contributor) + * Calvin Buckley (Contributor) + * Remi Collet (Contributor) + * Johannes Findeisen (Maintainer) + * Marco Schuster (Contributor) + diff --git a/README.md b/README.md index 43ab2d3..de9fc05 100644 --- a/README.md +++ b/README.md @@ -1,90 +1,96 @@ -

About

+# PC/SC for PHP -

This is the only extension for using PC/SC based smart cards with PHP. It is a wrapper to the wonderful and free project by Ludovic Rousseau, PCSC-Lite, which is the middleware to access a smart card using SCard API (PC/SC). Since PCSC-Lite is compatible to the winscard API it should be possible to compile this extension using a Windows or macOS operating system.

+## About -

Thanks are going to Johann Dantant! He provides a PC/SC extension for PHP since 2005 and I reused some of his code. He allowed me to relicense these parts under the terms of the PHP license so I could integrate PCSC-Lite natively into PHP.

+This is the only extension for using [PC/SC](http://www.pcscworkgroup.com/) based smart cards with [PHP](http://www.php.net). It is a wrapper to the wonderful and free project by Ludovic Rousseau, [PCSC-Lite](https://pcsclite.apdu.fr/), which is the middleware to access a smart card using SCard API (PC/SC). Since PCSC-Lite is compatible to the winscard API it should be possible to compile this extension using a Windows or macOS operating system. -

Installation

+Thanks are going to Johann Dantant! He provided a PC/SC extension for PHP since 2005 and I reused some of his code. He allowed me to relicense these parts under the terms of the PHP license so I could integrate PCSC-Lite native into PHP. -

I recommend to install the PECL extension the "PHP" way:

+## Installation -
pecl install pcsc-beta
+I recommend to install the PECL extension the "PHP" way: -

You can install the latest code by downloading the sources and compile yourself too.

+``` +pecl install pcsc-beta +``` -
git clone https://github.com/pcsc-for-php/pcsc.git
+You can install the latest code by downloading the sources and compile yourself too.
+
+```
+git clone https://github.com/pcsc-for-php/pcsc.git
 cd pcsc
 phpize
 ./configure
 make
-make install
+make install +``` -

After that you have all needed files in ./modules/

+After that you have all needed files in ./modules/ . -

API

+## API -

The extension currently provides the following API:

+The extension currently provides the following API: -

scard_establish_context();

+### scard_establish_context">scard_establish_context(); -

Returns the application $context to the PC/SC resource manager.

+Returns the application $context to the PC/SC resource manager. -

scard_is_valid_context($context);

+### scard_is_valid_context">scard_is_valid_context($context); -

Returns TRUE if $context is valid or FALSE if $context is not valid.

+Returns TRUE if $context is valid or FALSE if $context is not valid. -

scard_release_context($context);

+### scard_release_context">scard_release_context($context); -

Releases the application $context.

+Releases the application $context. -

scard_list_readers($context);

+### scard_list_readers">scard_list_readers($context); -

Returns an array of available readers or FALSE.

+Returns an array of available readers or FALSE. -
Example:
+#### Example: -
array(3) {
-  [0]=>
+```
+array(3) {
+  [0]=>
   string(26) "OMNIKEY CardMan 5x21 00 00"
-  [1]=>
+  [1]=>
   string(26) "OMNIKEY CardMan 5x21 00 01"
-  [2]=>
+  [2]=>
   string(76) "SCL01x Contactless Reader [SCL01x Contactless Reader] (21161009200722) 00 00"
 }
-
+``` -

scard_connect($context, "OMNIKEY CardMan 5x21 00 00");

+### scard_connect">scard_connect($context, "OMNIKEY CardMan 5x21 00 00"); -

Connects to a card. Returns the $connection to a reader or FALSE.

+Connects to a card. Returns the $connection to a reader or FALSE. -

scard_reconnect($connection);

+### scard_reconnect">scard_reconnect($connection); -

Returns the $connection to a reader or FALSE.

+Returns the $connection to a reader or FALSE. -

scard_disconnect($connection);

+### scard_disconnect">scard_disconnect($connection); -

Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE.

+Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. -

scard_transmit($connection, $apdu);

+### scard_transmit">scard_transmit($connection, $apdu); -

Returns the response $apdu as string or FALSE.

+Returns the response $apdu as string or FALSE. -

scard_status($connection);

+### scard_status">scard_status($connection); -

Returns the status or FALSE.

+Returns the status or FALSE. -

scard_cancel($context);

+### scard_cancel">scard_cancel($context); -

License

+## License -

This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment.

+This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment. - +## Links + + * [PECL Project Page](http://pecl.php.net/package/pcsc) - Page for package download at PHP.net + * [PC/SC Worgroup](http://www.pcscworkgroup.com/) - Homepage and definition file downloads + * [PC/SC](http://en.wikipedia.org/wiki/PC/SC) - PC/SC at Wikipedia + * [PC/SC-Lite](https://pcsclite.apdu.fr/) - The free and open implementation of the PC/SC SCard API for UNIX + * [PCSC sample in PHP5](http://ludovicrousseau.blogspot.de/2015/01/pcsc-sample-in-php5.html) - Ludovic Rousseau about "PC/SC for PHP" - diff --git a/TODO b/TODO deleted file mode 100644 index 644bbb0..0000000 --- a/TODO +++ /dev/null @@ -1,15 +0,0 @@ -Implement important missing PC/SC functions: - - - SCardControl(), - SCardGetStatusChange(), - SCardBeginTransaction(), - SCardEndTransaction() - -Implement less important missing PC/SC functions: - - - SCardGetAttrib(), - SCardSetAttrib(), - SCardListReaderGroups(), - SCardReconnect - -Write complete API documentation diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..2c2cdab --- /dev/null +++ b/TODO.md @@ -0,0 +1,17 @@ +# TODO + +## Implement important missing PC/SC functions and write documentation: + + * SCardControl() + * SCardGetStatusChange() + * SCardBeginTransaction() + * SCardEndTransaction() + * Write complete API documentation + +## Implement less important missing PC/SC functions: + + * SCardGetAttrib() + * SCardSetAttrib() + * SCardListReaderGroups() + * SCardReconnect + diff --git a/package.xml b/package.xml index 0596307..1077076 100644 --- a/package.xml +++ b/package.xml @@ -20,10 +20,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> calvin@cmpct.info yes - 2021-02-20 - + 2021-02-21 + - 0.5.0 + 0.5.1 0.3.1 @@ -31,11 +31,11 @@ http://pear.php.net/dtd/package-2.0.xsd"> stable PHP - Updated for PHP 8 compatibility. + Added and updated content like README.md; No bug or feature updates. - + @@ -43,7 +43,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> - + + diff --git a/php_pcsc.h b/php_pcsc.h index bf607f5..e91ff4e 100644 --- a/php_pcsc.h +++ b/php_pcsc.h @@ -4,7 +4,7 @@ extern zend_module_entry pcsc_module_entry; #define phpext_pcsc_ptr &pcsc_module_entry -#define PHP_PCSC_VERSION "0.5.0" +#define PHP_PCSC_VERSION "0.5.1" #ifdef PHP_WIN32 #define PHP_PCSC_API __declspec(dllexport) From 851e1dded21ae8930a3b999e123db7430edbde4b Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 01:55:04 +0100 Subject: [PATCH 02/29] API documentation fix. --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index de9fc05..c30f2ab 100644 --- a/README.md +++ b/README.md @@ -31,19 +31,19 @@ After that you have all needed files in ./modules/ . The extension currently provides the following API: -### scard_establish_context">scard_establish_context(); +### scard_establish_context(); Returns the application $context to the PC/SC resource manager. -### scard_is_valid_context">scard_is_valid_context($context); +### scard_is_valid_context($context); Returns TRUE if $context is valid or FALSE if $context is not valid. -### scard_release_context">scard_release_context($context); +### scard_release_context($context); Releases the application $context. -### scard_list_readers">scard_list_readers($context); +### scard_list_readers($context); Returns an array of available readers or FALSE. @@ -60,27 +60,27 @@ array(3) { } ``` -### scard_connect">scard_connect($context, "OMNIKEY CardMan 5x21 00 00"); +### scard_connect($context, "OMNIKEY CardMan 5x21 00 00"); Connects to a card. Returns the $connection to a reader or FALSE. -### scard_reconnect">scard_reconnect($connection); +### scard_reconnect($connection); Returns the $connection to a reader or FALSE. -### scard_disconnect">scard_disconnect($connection); +### scard_disconnect($connection); Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. -### scard_transmit">scard_transmit($connection, $apdu); +### scard_transmit($connection, $apdu); Returns the response $apdu as string or FALSE. -### scard_status">scard_status($connection); +### scard_status($connection); Returns the status or FALSE. -### scard_cancel">scard_cancel($context); +### scard_cancel($context); ## License From 5aad57fa26d277d7e3f633276dcb33ac34e117ae Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 03:10:30 +0100 Subject: [PATCH 03/29] CREDITS name order fix --- CREDITS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index 68ab9e7..cd9aa1a 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,11 +1,11 @@ # Contributors -## In alphabetical order: +## In alphabetical order by surname: - * Johann Dantant (Original author) * Anatol Belski (Contributor) * Calvin Buckley (Contributor) * Remi Collet (Contributor) + * Johann Dantant (Original author) * Johannes Findeisen (Maintainer) * Marco Schuster (Contributor) From 2562478bd42e46eba7e4366bc3a369cc100ad52d Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 06:19:50 +0100 Subject: [PATCH 04/29] Fixed and added some more PHP test code; Not stable --- docs/examples/pcsc.class.php | 20 ++++----- docs/examples/simple.php | 86 ++++++++++++++++++++++++++++++++++++ docs/examples/test.php | 9 ++-- 3 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 docs/examples/simple.php diff --git a/docs/examples/pcsc.class.php b/docs/examples/pcsc.class.php index 897edda..2c853a2 100644 --- a/docs/examples/pcsc.class.php +++ b/docs/examples/pcsc.class.php @@ -14,39 +14,39 @@ class PCSC { function __construct() { $this->context = scard_establish_context(); } - - function __destruct() { + + /*function __destruct() { $this->context = scard_release_context($this->context); - } + }*/ function connect($reader) { return $this->connection = scard_connect($this->context, $reader); } - + /*function reconnect() { return $this->connection = scard_reconnect($this->connection); }*/ - + function disconnect() { return scard_disconnect($this->connection); } - + function listreaders() { return $this->readers = scard_list_readers($this->context); } - + function transmit($apdu) { return scard_transmit($this->connection, $apdu); } - + function isvalidcontext() { return scard_is_valid_context($this->context); } - + function releasecontext() { return scard_release_context($this->context); } - + function status() { return scard_status($this->connection); } diff --git a/docs/examples/simple.php b/docs/examples/simple.php new file mode 100644 index 0000000..6e7094c --- /dev/null +++ b/docs/examples/simple.php @@ -0,0 +1,86 @@ +> Create Context\n"; +$context = scard_establish_context(); +var_dump($context); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# Get the reader list +echo ">> Get Readers\n"; +$readers = scard_list_readers($context); +var_dump($readers); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# Use the first reader +echo ">> Select Reader\n"; +$reader = $readers[1]; +echo "Using reader: ", $reader, "\n"; + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# Connect to the card +echo ">> Connect to Card\n"; +$connection = scard_connect($context, $reader); +var_dump($connection); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# Select Applet APDU +echo ">> Select Applet\n"; +$CMD = "00a4040c0cD2760001354B414E4D30310000"; +$res = scard_transmit($connection, $CMD); +var_dump($res); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# test APDU +echo ">> Send APDU\n"; +$CMD = "0084000008"; +$res = scard_transmit($connection, $CMD); +var_dump($res); +#echo pack("H*", $res), "\n"; + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +# Release the PC/SC context +echo ">> Release Context\n"; +scard_release_context($context); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + +?> diff --git a/docs/examples/test.php b/docs/examples/test.php index 61aa86a..f923e37 100644 --- a/docs/examples/test.php +++ b/docs/examples/test.php @@ -13,19 +13,22 @@ $foo = new PCSC(); echo "Create Context:\n"; var_dump($foo->context); +#echo "Last Error String:"; +#var_dump($foo->scard_errstr($foo->scard_last_errno())); + echo "List Readers:\n"; var_dump($foo->listreaders()); echo "Connect Card:\n"; -var_dump($foo->connect("OMNIKEY CardMan 5x21 00 01")); +var_dump($foo->connect("OMNIKEY CardMan (076B:5321) 5321 00 01")); #echo "Reconnect:\n"; #var_dump($foo->reconnect()); echo "Some Transmits:\n"; +// Select applet var_dump($foo->transmit("00a4040c0cD2760001354B414E4D30310000")); -var_dump($foo->transmit("0084000008")); -var_dump($foo->transmit("0084000008")); +// APDU to execute RNG function on card applet var_dump($foo->transmit("0084000008")); echo "Is Valid Context?\n"; From fc687719c6b3dbc0830498b7a7c5a0a615a7aa13 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 06:58:03 +0100 Subject: [PATCH 05/29] Content update --- CREDITS.md | 2 -- TODO.md | 11 +++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index cd9aa1a..f3a7dcd 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,7 +1,5 @@ # Contributors -## In alphabetical order by surname: - * Anatol Belski (Contributor) * Calvin Buckley (Contributor) * Remi Collet (Contributor) diff --git a/TODO.md b/TODO.md index 2c2cdab..ebe81af 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,11 @@ -# TODO +# TODO: -## Implement important missing PC/SC functions and write documentation: +Implement important missing PC/SC functions and write documentation: - * SCardControl() - * SCardGetStatusChange() * SCardBeginTransaction() * SCardEndTransaction() + * SCardControl() + * SCardGetStatusChange() * Write complete API documentation ## Implement less important missing PC/SC functions: @@ -15,3 +15,6 @@ * SCardListReaderGroups() * SCardReconnect +# GOAL: + +Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) From 6a3027b35b060c4aec7c368f09466b243b69e000 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 06:59:18 +0100 Subject: [PATCH 06/29] Content update --- TODO.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index ebe81af..2604a73 100644 --- a/TODO.md +++ b/TODO.md @@ -8,13 +8,13 @@ Implement important missing PC/SC functions and write documentation: * SCardGetStatusChange() * Write complete API documentation -## Implement less important missing PC/SC functions: +# Implement less important missing PC/SC functions: * SCardGetAttrib() * SCardSetAttrib() * SCardListReaderGroups() * SCardReconnect -# GOAL: +## Goal: Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) From 4b7273ae39cb62ffac5b875c9073b4d7ce149c08 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 06:59:46 +0100 Subject: [PATCH 07/29] Content update --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 2604a73..ecda651 100644 --- a/TODO.md +++ b/TODO.md @@ -8,7 +8,7 @@ Implement important missing PC/SC functions and write documentation: * SCardGetStatusChange() * Write complete API documentation -# Implement less important missing PC/SC functions: +Implement less important missing PC/SC functions: * SCardGetAttrib() * SCardSetAttrib() From 83de43d9fef3f17407b8c1040ba90f8c7af80de4 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 07:04:51 +0100 Subject: [PATCH 08/29] Content update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c30f2ab..ff2b4b7 100644 --- a/README.md +++ b/README.md @@ -93,4 +93,5 @@ This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite * [PC/SC](http://en.wikipedia.org/wiki/PC/SC) - PC/SC at Wikipedia * [PC/SC-Lite](https://pcsclite.apdu.fr/) - The free and open implementation of the PC/SC SCard API for UNIX * [PCSC sample in PHP5](http://ludovicrousseau.blogspot.de/2015/01/pcsc-sample-in-php5.html) - Ludovic Rousseau about "PC/SC for PHP" + * [winscard.h header](https://docs.microsoft.com/en-us/windows/win32/api/winscard/) - Microsoft Docs From 6508c449843f114effd6be03392570f0563ad17c Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 07:50:36 +0100 Subject: [PATCH 09/29] Content update --- README.md | 9 ++++++++- docs/examples/simple.php | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff2b4b7..f6375a4 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,17 @@ array(3) { } ``` -### scard_connect($context, "OMNIKEY CardMan 5x21 00 00"); +### scard_connect($context, "OMNIKEY CardMan 5x21 00 00" [, int $protocol]); Connects to a card. Returns the $connection to a reader or FALSE. +Where optional $protocol is: + + * 1 = T=0 + * 2 = T=1 + +Default $protocol is T=1. + ### scard_reconnect($connection); Returns the $connection to a reader or FALSE. diff --git a/docs/examples/simple.php b/docs/examples/simple.php index 6e7094c..87c0c5a 100644 --- a/docs/examples/simple.php +++ b/docs/examples/simple.php @@ -39,7 +39,7 @@ echo "\n"; # Connect to the card echo ">> Connect to Card\n"; -$connection = scard_connect($context, $reader); +$connection = scard_connect($context, $reader, 1); var_dump($connection); $errno = scard_last_errno(); @@ -73,6 +73,17 @@ $errstr = scard_errstr($errno); var_dump($errstr); echo "\n"; +# Show Status +echo ">> Show Status\n"; +$status = scard_status($connection); +var_dump($status); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + # Release the PC/SC context echo ">> Release Context\n"; scard_release_context($context); From d76a0296ec4f4b684e6b74385c6a37e1c573e2ef Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 07:56:18 +0100 Subject: [PATCH 10/29] Content update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index f6375a4..7a9e769 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ Default $protocol is T=1. Returns the $connection to a reader or FALSE. +**NOT IMPLEMENTED!** Should be available. + ### scard_disconnect($connection); Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. @@ -89,6 +91,8 @@ Returns the status or FALSE. ### scard_cancel($context); +**NOT IMPLEMENTED!** Maybe not useful because of this extension is for server side usage designed but since we want the API implemented it should be available. + ## License This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment. From 23bc4ea3e4d929b9b6c07a475acbe523f072afad Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:04:53 +0100 Subject: [PATCH 11/29] Content update --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a9e769..980ddd7 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,28 @@ Returns the response $apdu as string or FALSE. ### scard_status($connection); -Returns the status or FALSE. +Returns the status array or FALSE. + +#### Example: + +``` +array(7) { + ["state"]=> + int(52) + ["SCARD_PRESENT"]=> + int(1) + ["SCARD_POWERED"]=> + int(1) + ["SCARD_NEGOTIABLE"]=> + int(1) + ["SCARD_PROTOCOL_T0"]=> + int(1) + ["PROTOCOL"]=> + string(3) "T=1" + ["ATR"]=> + string(28) "3B8980014A434F5033315632324A" +} +``` ### scard_cancel($context); From 41eafbe76f687971c0b935cafa5244af6a2a08ce Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:17:03 +0100 Subject: [PATCH 12/29] Content update --- README.md | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 980ddd7..4424730 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,30 @@ After that you have all needed files in ./modules/ . The extension currently provides the following API: + +### scard_cancel($context); + +**NOT IMPLEMENTED!** Maybe not useful because of this extension is for server side usage designed but since we want the API implemented it should be available. + +### scard_connect($context, "OMNIKEY CardMan 5x21 00 00" [, int $protocol]); + +Connects to a card. Returns the $connection to a reader or FALSE. + +Where optional $protocol is: + + * 1 = T=0 + * 2 = T=1 + +Default $protocol is T=1. + +### scard_disconnect($connection); + +Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. + +### scard_errstr($errno) + +Returns $errstr for $errno or NULL. + ### scard_establish_context(); Returns the application $context to the PC/SC resource manager. @@ -39,9 +63,9 @@ Returns the application $context to the PC/SC resource manager. Returns TRUE if $context is valid or FALSE if $context is not valid. -### scard_release_context($context); +### scard_last_errno() -Releases the application $context. +Returns the last $errno or nothing? NULL or FALSE? (TODO) ### scard_list_readers($context); @@ -60,30 +84,15 @@ array(3) { } ``` -### scard_connect($context, "OMNIKEY CardMan 5x21 00 00" [, int $protocol]); - -Connects to a card. Returns the $connection to a reader or FALSE. - -Where optional $protocol is: - - * 1 = T=0 - * 2 = T=1 - -Default $protocol is T=1. - ### scard_reconnect($connection); Returns the $connection to a reader or FALSE. **NOT IMPLEMENTED!** Should be available. -### scard_disconnect($connection); +### scard_release_context($context); -Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. - -### scard_transmit($connection, $apdu); - -Returns the response $apdu as string or FALSE. +Releases the application $context. ### scard_status($connection); @@ -110,9 +119,9 @@ array(7) { } ``` -### scard_cancel($context); +### scard_transmit($connection, $apdu); -**NOT IMPLEMENTED!** Maybe not useful because of this extension is for server side usage designed but since we want the API implemented it should be available. +Returns the response $apdu as string or FALSE. ## License @@ -126,4 +135,5 @@ This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite * [PC/SC-Lite](https://pcsclite.apdu.fr/) - The free and open implementation of the PC/SC SCard API for UNIX * [PCSC sample in PHP5](http://ludovicrousseau.blogspot.de/2015/01/pcsc-sample-in-php5.html) - Ludovic Rousseau about "PC/SC for PHP" * [winscard.h header](https://docs.microsoft.com/en-us/windows/win32/api/winscard/) - Microsoft Docs + * [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) From 744c0e765443af6298d32c24245233b4d70d2035 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:18:39 +0100 Subject: [PATCH 13/29] Content update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4424730..becdd62 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Default $protocol is T=1. Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. -### scard_errstr($errno) +### scard_errstr($errno) - Not PC/SC standard. Returns $errstr for $errno or NULL. @@ -63,7 +63,7 @@ Returns the application $context to the PC/SC resource manager. Returns TRUE if $context is valid or FALSE if $context is not valid. -### scard_last_errno() +### scard_last_errno() - Not PC/SC standard. Returns the last $errno or nothing? NULL or FALSE? (TODO) From ac8fa37a533098324e7136a852ae4286c5b44f89 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:19:09 +0100 Subject: [PATCH 14/29] Content update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index becdd62..6bc5ca9 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Default $protocol is T=1. Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. -### scard_errstr($errno) - Not PC/SC standard. +### scard_errstr($errno); - Not PC/SC standard. Returns $errstr for $errno or NULL. @@ -63,7 +63,7 @@ Returns the application $context to the PC/SC resource manager. Returns TRUE if $context is valid or FALSE if $context is not valid. -### scard_last_errno() - Not PC/SC standard. +### scard_last_errno(); - Not PC/SC standard. Returns the last $errno or nothing? NULL or FALSE? (TODO) From 2e58c9192dccbb59ad5937d05f618dc0b039b859 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:38:33 +0100 Subject: [PATCH 15/29] Added more API docs --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6bc5ca9..b847ffd 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,25 @@ After that you have all needed files in ./modules/ . ## API -The extension currently provides the following API: +The extension currently provides the following API (alphabetical order): +### pcsc_stringify_error($errno); + +**NOT IMPLEMENTED!** - Should be available! + +Duplicate of scard_errstr() but this should be the default. + +### scard_begin_transaction($connection); + +**NOT IMPLEMENTED!** - Should be available! + +Establishes a temporary exclusive access mode for doing a serie of commands in a transaction. + +You might want to use this when you are selecting a few files and then writing a large file so you can make sure that another application will not change the current file. If another application has a lock on this reader or this application is in SCARD_SHARE_EXCLUSIVE there will be no action taken. ### scard_cancel($context); -**NOT IMPLEMENTED!** Maybe not useful because of this extension is for server side usage designed but since we want the API implemented it should be available. +**NOT IMPLEMENTED!** - Maybe not useful because of this extension is for server side usage designed but since we want the API implemented it should be available. ### scard_connect($context, "OMNIKEY CardMan 5x21 00 00" [, int $protocol]); @@ -47,10 +60,24 @@ Where optional $protocol is: Default $protocol is T=1. +### scard_control($connection); + +**NOT IMPLEMENTED!** - Should be available! + +Sends a command directly to the IFD Handler (reader driver) to be processed by the reader. + ### scard_disconnect($connection); Disconnects the $connection to a card. Returns the TRUE if disconnecting was succesful or FALSE. +### scard_end_transaction($connection); + +**NOT IMPLEMENTED!** - Should be available! + +Ends a previously begun transaction. + +The calling application must be the owner of the previously begun transaction or an error will occur. + ### scard_errstr($errno); - Not PC/SC standard. Returns $errstr for $errno or NULL. @@ -59,6 +86,18 @@ Returns $errstr for $errno or NULL. Returns the application $context to the PC/SC resource manager. +### scard_get_attrib($connection); + +**NOT IMPLEMENTED!** - Should be available! + +Get an attribute from the IFD Handler (reader driver). + +### scard_get_status_change($context); + +**NOT IMPLEMENTED!** - Should be available! + +Blocks execution until the current availability of the cards in a specific set of readers changes. + ### scard_is_valid_context($context); Returns TRUE if $context is valid or FALSE if $context is not valid. @@ -67,6 +106,12 @@ Returns TRUE if $context is valid or FALSE if $context is not valid. Returns the last $errno or nothing? NULL or FALSE? (TODO) +### scard_list_reader_groups($context); + +**NOT IMPLEMENTED!** - Should be available! + +Returns a list of currently available reader groups on the system. + ### scard_list_readers($context); Returns an array of available readers or FALSE. @@ -86,14 +131,20 @@ array(3) { ### scard_reconnect($connection); -Returns the $connection to a reader or FALSE. +**NOT IMPLEMENTED!** - Should be available! -**NOT IMPLEMENTED!** Should be available. +Returns the $connection to a reader or FALSE. ### scard_release_context($context); Releases the application $context. +### scard_set_attrib($connection); + +**NOT IMPLEMENTED!** - Should be available! + +Set an attribute of the IFD Handler. + ### scard_status($connection); Returns the status array or FALSE. @@ -110,7 +161,7 @@ array(7) { int(1) ["SCARD_NEGOTIABLE"]=> int(1) - ["SCARD_PROTOCOL_T0"]=> + ["SCARD_PROTOCOL_T1"]=> int(1) ["PROTOCOL"]=> string(3) "T=1" From 87c612789b5615521e775f27d7ee3406d64114cb Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 21 Feb 2021 08:41:11 +0100 Subject: [PATCH 16/29] Added more API docs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b847ffd..0274d49 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ The extension currently provides the following API (alphabetical order): ### pcsc_stringify_error($errno); +Returns $errstr for $errno or NULL. + **NOT IMPLEMENTED!** - Should be available! Duplicate of scard_errstr() but this should be the default. From aac77822103befd8d1e0f25f781443d361841dae Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 02:09:10 +0100 Subject: [PATCH 17/29] Moved content from CREDITS and TODO to README and deleted files --- CREDITS.md | 9 --------- README.md | 38 ++++++++++++++++++++++++++++++++++++-- TODO.md | 20 -------------------- package.xml | 2 -- 4 files changed, 36 insertions(+), 33 deletions(-) delete mode 100644 CREDITS.md delete mode 100644 TODO.md diff --git a/CREDITS.md b/CREDITS.md deleted file mode 100644 index f3a7dcd..0000000 --- a/CREDITS.md +++ /dev/null @@ -1,9 +0,0 @@ -# Contributors - - * Anatol Belski (Contributor) - * Calvin Buckley (Contributor) - * Remi Collet (Contributor) - * Johann Dantant (Original author) - * Johannes Findeisen (Maintainer) - * Marco Schuster (Contributor) - diff --git a/README.md b/README.md index 0274d49..78421d1 100644 --- a/README.md +++ b/README.md @@ -176,17 +176,51 @@ array(7) { Returns the response $apdu as string or FALSE. +# To do: + +There is some stuff to do. Some things are important but some are not. + +## Implement important missing PC/SC functions and write documentation: + + * SCardBeginTransaction() + * SCardEndTransaction() + * SCardControl() + * SCardGetStatusChange() + * Write complete API documentation + +## Implement less important missing PC/SC functions: + + * SCardGetAttrib() + * SCardSetAttrib() + * SCardListReaderGroups() + * SCardReconnect() + +## Goal: + +Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) + ## License This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment. +# Credits + +This extension was originally written in 2005 by Johann Dantant. In 2011 Johannes Findeisen took his code and updated it to work with the current PHP version. Johannes maintains the code to this day, but there have been some contributions from other people in the past. All people who have worked on extending or porting the "pcsc" extension are listed below in alphabetical order by their last name. Thanks to all! + + * Anatol Belski (Contributor) + * Calvin Buckley (Contributor) + * Remi Collet (Contributor) + * Johann Dantant (Original author) + * Johannes Findeisen (Maintainer) + * Marco Schuster (Contributor) + ## Links * [PECL Project Page](http://pecl.php.net/package/pcsc) - Page for package download at PHP.net * [PC/SC Worgroup](http://www.pcscworkgroup.com/) - Homepage and definition file downloads * [PC/SC](http://en.wikipedia.org/wiki/PC/SC) - PC/SC at Wikipedia * [PC/SC-Lite](https://pcsclite.apdu.fr/) - The free and open implementation of the PC/SC SCard API for UNIX + * [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) - Documentation of the PCSC-Lite API * [PCSC sample in PHP5](http://ludovicrousseau.blogspot.de/2015/01/pcsc-sample-in-php5.html) - Ludovic Rousseau about "PC/SC for PHP" - * [winscard.h header](https://docs.microsoft.com/en-us/windows/win32/api/winscard/) - Microsoft Docs - * [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) + * [winscard.h header](https://docs.microsoft.com/en-us/windows/win32/api/winscard/) - Microsoft Documentation diff --git a/TODO.md b/TODO.md deleted file mode 100644 index ecda651..0000000 --- a/TODO.md +++ /dev/null @@ -1,20 +0,0 @@ -# TODO: - -Implement important missing PC/SC functions and write documentation: - - * SCardBeginTransaction() - * SCardEndTransaction() - * SCardControl() - * SCardGetStatusChange() - * Write complete API documentation - -Implement less important missing PC/SC functions: - - * SCardGetAttrib() - * SCardSetAttrib() - * SCardListReaderGroups() - * SCardReconnect - -## Goal: - -Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) diff --git a/package.xml b/package.xml index 1077076..26b7da0 100644 --- a/package.xml +++ b/package.xml @@ -35,7 +35,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -44,7 +43,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - From 1226d9ace8d6fd95ac2b63e9f8b1629e6f90f9e6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 02:46:54 +0100 Subject: [PATCH 18/29] Replaced tabs with 2 whitespaces in pcsc.c --- pcsc.c | 263 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 131 insertions(+), 132 deletions(-) diff --git a/pcsc.c b/pcsc.c index a0cbb9c..23ec66d 100644 --- a/pcsc.c +++ b/pcsc.c @@ -28,7 +28,7 @@ ZEND_DECLARE_MODULE_GLOBALS(pcsc); /* Compatibility shims */ #ifndef ZEND_FETCH_RESOURCE #define ZEND_FETCH_RESOURCE(res, stmt_type, stmt, stmt_id, resource_type_name, le_stmt) \ - res = (stmt_type)zend_fetch_resource(Z_RES_P(*stmt),resource_type_name,le_stmt); + res = (stmt_type)zend_fetch_resource(Z_RES_P(*stmt),resource_type_name,le_stmt); #endif #ifndef FALSE @@ -71,44 +71,44 @@ ZEND_GET_MODULE(pcsc) /* resource container: context */ static int le_pcsc_ctx_res; static void php_pcsc_ctx_res_dtor(zend_resource *rsrc) { - SCARDCONTEXT context; - LONG rc=0; - - context=(SCARDCONTEXT)rsrc->ptr; - rc = SCardIsValidContext(context); - if (rc != SCARD_S_SUCCESS) { - php_error_docref(NULL, E_WARNING, "PC/SC context dtor: SCardIsValidContext returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); - return; - } + SCARDCONTEXT context; + LONG rc=0; - rc = SCardReleaseContext(context); - if (rc != SCARD_S_SUCCESS) { - php_error_docref(NULL, E_WARNING, "PC/SC context dtor: SCardReleaseContext returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); - return; - } - return; + context=(SCARDCONTEXT)rsrc->ptr; + rc = SCardIsValidContext(context); + if (rc != SCARD_S_SUCCESS) { + php_error_docref(NULL, E_WARNING, "PC/SC context dtor: SCardIsValidContext returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); + return; + } + + rc = SCardReleaseContext(context); + if (rc != SCARD_S_SUCCESS) { + php_error_docref(NULL, E_WARNING, "PC/SC context dtor: SCardReleaseContext returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); + return; + } + return; } /* resource container: connection */ static int le_pcsc_conn_res; static void php_pcsc_conn_res_dtor(zend_resource *rsrc) { - SCARDHANDLE hCard; - LONG rc; + SCARDHANDLE hCard; + LONG rc; - //TODO: actually use this - return; - php_printf("conn dtor\n"); - hCard=(SCARDHANDLE)rsrc->ptr; - - rc = SCardDisconnect(hCard, SCARD_LEAVE_CARD); - if (rc != SCARD_S_SUCCESS) { - php_error_docref(NULL, E_WARNING, "PC/SC connection dtor: SCardDisconnect returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); - } + //TODO: actually use this + return; + php_printf("conn dtor\n"); + hCard=(SCARDHANDLE)rsrc->ptr; + + rc = SCardDisconnect(hCard, SCARD_LEAVE_CARD); + if (rc != SCARD_S_SUCCESS) { + php_error_docref(NULL, E_WARNING, "PC/SC connection dtor: SCardDisconnect returned %s (0x%lx)", php_pcsc_error_to_string(rc), rc); + } } /* TLS */ static void php_pcsc_globals_ctor(zend_pcsc_globals* pcsc_globals) { - pcsc_globals->last_errno=SCARD_S_SUCCESS; + pcsc_globals->last_errno=SCARD_S_SUCCESS; } /* {{{ PHP_MINIT_FUNCTION @@ -194,18 +194,18 @@ PHP_MINIT_FUNCTION(pcsc) #ifdef SCARD_E_WRITE_TOO_MANY REGISTER_PCSC_CONSTANT(SCARD_E_WRITE_TOO_MANY); #endif - + REGISTER_PCSC_CONSTANT(SCARD_F_COMM_ERROR); REGISTER_PCSC_CONSTANT(SCARD_F_INTERNAL_ERROR); REGISTER_PCSC_CONSTANT(SCARD_F_UNKNOWN_ERROR); REGISTER_PCSC_CONSTANT(SCARD_F_WAITED_TOO_LONG); - + #ifdef SCARD_P_SHUTDOWN REGISTER_PCSC_CONSTANT(SCARD_P_SHUTDOWN); #endif - + REGISTER_PCSC_CONSTANT(SCARD_S_SUCCESS); - + #ifdef SCARD_W_CANCELLED_BY_USER REGISTER_PCSC_CONSTANT(SCARD_W_CANCELLED_BY_USER); #endif @@ -284,82 +284,82 @@ PHP_MINFO_FUNCTION(pcsc) /* map error codes to string */ static char* php_pcsc_error_to_string(DWORD dwRC) { - switch(dwRC) { + switch(dwRC) { #ifdef SCARD_E_BAD_SEEK - case SCARD_E_BAD_SEEK: return "SCARD_E_BAD_SEEK"; + case SCARD_E_BAD_SEEK: return "SCARD_E_BAD_SEEK"; #endif - case SCARD_E_CANCELLED: return "SCARD_E_CANCELLED"; - case SCARD_E_CANT_DISPOSE: return "SCARD_E_CANT_DISPOSE"; - case SCARD_E_CARD_UNSUPPORTED: return "SCARD_E_CARD_UNSUPPORTED"; + case SCARD_E_CANCELLED: return "SCARD_E_CANCELLED"; + case SCARD_E_CANT_DISPOSE: return "SCARD_E_CANT_DISPOSE"; + case SCARD_E_CARD_UNSUPPORTED: return "SCARD_E_CARD_UNSUPPORTED"; #ifdef SCARD_E_CERTIFICATE_UNAVAILABLE - case SCARD_E_CERTIFICATE_UNAVAILABLE: return "SCARD_E_CERTIFICATE_UNAVAILABLE"; + case SCARD_E_CERTIFICATE_UNAVAILABLE: return "SCARD_E_CERTIFICATE_UNAVAILABLE"; #endif #ifdef SCARD_E_COMM_DATA_LOST - case SCARD_E_COMM_DATA_LOST: return "SCARD_E_COMM_DATA_LOST"; + case SCARD_E_COMM_DATA_LOST: return "SCARD_E_COMM_DATA_LOST"; #endif #ifdef SCARD_E_DIR_NOT_FOUND - case SCARD_E_DIR_NOT_FOUND: return "SCARD_E_DIR_NOT_FOUND"; + case SCARD_E_DIR_NOT_FOUND: return "SCARD_E_DIR_NOT_FOUND"; #endif - case SCARD_E_DUPLICATE_READER: return "SCARD_E_DUPLICATE_READER"; + case SCARD_E_DUPLICATE_READER: return "SCARD_E_DUPLICATE_READER"; #ifdef SCARD_E_FILE_NOT_FOUND - case SCARD_E_FILE_NOT_FOUND: return "SCARD_E_FILE_NOT_FOUND"; + case SCARD_E_FILE_NOT_FOUND: return "SCARD_E_FILE_NOT_FOUND"; #endif #ifdef SCARD_E_ICC_CREATEORDER - case SCARD_E_ICC_CREATEORDER: return "SCARD_E_ICC_CREATEORDER"; + case SCARD_E_ICC_CREATEORDER: return "SCARD_E_ICC_CREATEORDER"; #endif #ifdef SCARD_E_ICC_INSTALLATION - case SCARD_E_ICC_INSTALLATION: return "SCARD_E_ICC_INSTALLATION"; + case SCARD_E_ICC_INSTALLATION: return "SCARD_E_ICC_INSTALLATION"; #endif - case SCARD_E_INSUFFICIENT_BUFFER: return "SCARD_E_INSUFFICIENT_BUFFER"; - case SCARD_E_INVALID_ATR: return "SCARD_E_INVALID_ATR"; + case SCARD_E_INSUFFICIENT_BUFFER: return "SCARD_E_INSUFFICIENT_BUFFER"; + case SCARD_E_INVALID_ATR: return "SCARD_E_INVALID_ATR"; #ifdef SCARD_E_INVALID_CHV - case SCARD_E_INVALID_CHV: return "SCARD_E_INVALID_CHV"; + case SCARD_E_INVALID_CHV: return "SCARD_E_INVALID_CHV"; #endif - case SCARD_E_INVALID_HANDLE: return "SCARD_E_INVALID_HANDLE"; - case SCARD_E_INVALID_PARAMETER: return "SCARD_E_INVALID_PARAMETER"; - case SCARD_E_INVALID_TARGET: return "SCARD_E_INVALID_TARGET"; - case SCARD_E_INVALID_VALUE: return "SCARD_E_INVALID_VALUE"; + case SCARD_E_INVALID_HANDLE: return "SCARD_E_INVALID_HANDLE"; + case SCARD_E_INVALID_PARAMETER: return "SCARD_E_INVALID_PARAMETER"; + case SCARD_E_INVALID_TARGET: return "SCARD_E_INVALID_TARGET"; + case SCARD_E_INVALID_VALUE: return "SCARD_E_INVALID_VALUE"; #ifdef SCARD_E_NO_ACCESS - case SCARD_E_NO_ACCESS: return "SCARD_E_NO_ACCESS"; + case SCARD_E_NO_ACCESS: return "SCARD_E_NO_ACCESS"; #endif #ifdef SCARD_E_NO_DIR - case SCARD_E_NO_DIR: return "SCARD_E_NO_DIR"; + case SCARD_E_NO_DIR: return "SCARD_E_NO_DIR"; #endif #ifdef SCARD_E_NO_FILE - case SCARD_E_NO_FILE: return "SCARD_E_NO_FILE"; + case SCARD_E_NO_FILE: return "SCARD_E_NO_FILE"; #endif #ifdef SCARD_E_NO_KEY_CONTAINER - case SCARD_E_NO_KEY_CONTAINER: return "SCARD_E_NO_KEY_CONTAINER"; + case SCARD_E_NO_KEY_CONTAINER: return "SCARD_E_NO_KEY_CONTAINER"; #endif - case SCARD_E_NO_MEMORY: return "SCARD_E_NO_MEMORY"; - case SCARD_E_NO_READERS_AVAILABLE: return "SCARD_E_NO_READERS_AVAILABLE"; - case SCARD_E_NO_SERVICE: return "SCARD_E_NO_SERVICE"; - case SCARD_E_NO_SMARTCARD: return "SCARD_E_NO_SMARTCARD"; + case SCARD_E_NO_MEMORY: return "SCARD_E_NO_MEMORY"; + case SCARD_E_NO_READERS_AVAILABLE: return "SCARD_E_NO_READERS_AVAILABLE"; + case SCARD_E_NO_SERVICE: return "SCARD_E_NO_SERVICE"; + case SCARD_E_NO_SMARTCARD: return "SCARD_E_NO_SMARTCARD"; #ifdef SCARD_E_NO_ACCESS - case SCARD_E_NO_SUCH_CERTIFICATE: return "SCARD_E_NO_SUCH_CERTIFICATE"; + case SCARD_E_NO_SUCH_CERTIFICATE: return "SCARD_E_NO_SUCH_CERTIFICATE"; #endif - case SCARD_E_NOT_READY: return "SCARD_E_NOT_READY"; - case SCARD_E_NOT_TRANSACTED: return "SCARD_E_NOT_TRANSACTED"; - case SCARD_E_PCI_TOO_SMALL: return "SCARD_E_PCI_TOO_SMALL"; - case SCARD_E_PROTO_MISMATCH: return "SCARD_E_PROTO_MISMATCH"; - case SCARD_E_READER_UNAVAILABLE: return "SCARD_E_READER_UNAVAILABLE"; - case SCARD_E_READER_UNSUPPORTED: return "SCARD_E_READER_UNSUPPORTED"; + case SCARD_E_NOT_READY: return "SCARD_E_NOT_READY"; + case SCARD_E_NOT_TRANSACTED: return "SCARD_E_NOT_TRANSACTED"; + case SCARD_E_PCI_TOO_SMALL: return "SCARD_E_PCI_TOO_SMALL"; + case SCARD_E_PROTO_MISMATCH: return "SCARD_E_PROTO_MISMATCH"; + case SCARD_E_READER_UNAVAILABLE: return "SCARD_E_READER_UNAVAILABLE"; + case SCARD_E_READER_UNSUPPORTED: return "SCARD_E_READER_UNSUPPORTED"; #ifdef SCARD_E_SERVER_TOO_BUSY - case SCARD_E_SERVER_TOO_BUSY: return "SCARD_E_SERVER_TOO_BUSY"; + case SCARD_E_SERVER_TOO_BUSY: return "SCARD_E_SERVER_TOO_BUSY"; #endif - case SCARD_E_SERVICE_STOPPED: return "SCARD_E_SERVICE_STOPPED"; - case SCARD_E_SHARING_VIOLATION: return "SCARD_E_SHARING_VIOLATION"; - case SCARD_E_SYSTEM_CANCELLED: return "SCARD_E_SYSTEM_CANCELLED"; - case SCARD_E_TIMEOUT: return "SCARD_E_TIMEOUT"; + case SCARD_E_SERVICE_STOPPED: return "SCARD_E_SERVICE_STOPPED"; + case SCARD_E_SHARING_VIOLATION: return "SCARD_E_SHARING_VIOLATION"; + case SCARD_E_SYSTEM_CANCELLED: return "SCARD_E_SYSTEM_CANCELLED"; + case SCARD_E_TIMEOUT: return "SCARD_E_TIMEOUT"; #ifdef SCARD_E_UNEXPECTED - case SCARD_E_UNEXPECTED: return "SCARD_E_UNEXPECTED"; + case SCARD_E_UNEXPECTED: return "SCARD_E_UNEXPECTED"; #endif - case SCARD_E_UNKNOWN_CARD: return "SCARD_E_UNKNOWN_CARD"; - case SCARD_E_UNKNOWN_READER: return "SCARD_E_UNKNOWN_READER"; + case SCARD_E_UNKNOWN_CARD: return "SCARD_E_UNKNOWN_CARD"; + case SCARD_E_UNKNOWN_READER: return "SCARD_E_UNKNOWN_READER"; #ifdef SCARD_E_UNKNOWN_RES_MNG - case SCARD_E_UNKNOWN_RES_MNG: return "SCARD_E_UNKNOWN_RES_MNG"; + case SCARD_E_UNKNOWN_RES_MNG: return "SCARD_E_UNKNOWN_RES_MNG"; #endif -/* apparently E_UNEXPECTED and E_UNSUPPORTED are defined +/* apparently E_UNEXPECTED and E_UNSUPPORTED are defined by a buggy header file on Linux, causing a "double used constant" error. Just leave this out on Linux, then. */ @@ -367,50 +367,50 @@ static char* php_pcsc_error_to_string(DWORD dwRC) { case SCARD_E_UNSUPPORTED_FEATURE: return "SCARD_E_UNSUPPORTED_FEATURE"; #endif #ifdef SCARD_E_WRITE_TOO_MANY - case SCARD_E_WRITE_TOO_MANY: return "SCARD_E_WRITE_TOO_MANY"; + case SCARD_E_WRITE_TOO_MANY: return "SCARD_E_WRITE_TOO_MANY"; #endif - case SCARD_F_COMM_ERROR: return "SCARD_E_WRITE_TOO_MANY"; - case SCARD_F_INTERNAL_ERROR: return "SCARD_F_INTERNAL_ERROR"; - case SCARD_F_UNKNOWN_ERROR: return "SCARD_F_UNKNOWN_ERROR"; - case SCARD_F_WAITED_TOO_LONG: return "SCARD_F_WAITED_TOO_LONG"; + case SCARD_F_COMM_ERROR: return "SCARD_E_WRITE_TOO_MANY"; + case SCARD_F_INTERNAL_ERROR: return "SCARD_F_INTERNAL_ERROR"; + case SCARD_F_UNKNOWN_ERROR: return "SCARD_F_UNKNOWN_ERROR"; + case SCARD_F_WAITED_TOO_LONG: return "SCARD_F_WAITED_TOO_LONG"; #ifdef SCARD_P_SHUTDOWN - case SCARD_P_SHUTDOWN: return "SCARD_P_SHUTDOWN"; + case SCARD_P_SHUTDOWN: return "SCARD_P_SHUTDOWN"; #endif - case SCARD_S_SUCCESS: return "SCARD_S_SUCCESS"; + case SCARD_S_SUCCESS: return "SCARD_S_SUCCESS"; #ifdef SCARD_W_CANCELLED_BY_USER - case SCARD_W_CANCELLED_BY_USER: return "SCARD_W_CANCELLED_BY_USER"; + case SCARD_W_CANCELLED_BY_USER: return "SCARD_W_CANCELLED_BY_USER"; #endif #ifdef SCARD_W_CACHE_ITEM_NOT_FOUND - case SCARD_W_CACHE_ITEM_NOT_FOUND: return "SCARD_W_CACHE_ITEM_NOT_FOUND"; + case SCARD_W_CACHE_ITEM_NOT_FOUND: return "SCARD_W_CACHE_ITEM_NOT_FOUND"; #endif #ifdef SCARD_W_CACHE_ITEM_STALE - case SCARD_W_CACHE_ITEM_STALE: return "SCARD_W_CACHE_ITEM_STALE"; + case SCARD_W_CACHE_ITEM_STALE: return "SCARD_W_CACHE_ITEM_STALE"; #endif #ifdef SCARD_W_CACHE_ITEM_TOO_BIG - case SCARD_W_CACHE_ITEM_TOO_BIG: return "SCARD_W_CACHE_ITEM_TOO_BIG"; + case SCARD_W_CACHE_ITEM_TOO_BIG: return "SCARD_W_CACHE_ITEM_TOO_BIG"; #endif #ifdef SCARD_W_CARD_NOT_AUTHENTICATED - case SCARD_W_CARD_NOT_AUTHENTICATED: return "SCARD_W_CARD_NOT_AUTHENTICATED"; + case SCARD_W_CARD_NOT_AUTHENTICATED: return "SCARD_W_CARD_NOT_AUTHENTICATED"; #endif #ifdef SCARD_W_CHV_BLOCKED - case SCARD_W_CHV_BLOCKED: return "SCARD_W_CHV_BLOCKED"; + case SCARD_W_CHV_BLOCKED: return "SCARD_W_CHV_BLOCKED"; #endif #ifdef SCARD_W_EOF - case SCARD_W_EOF: return "SCARD_W_EOF"; + case SCARD_W_EOF: return "SCARD_W_EOF"; #endif - case SCARD_W_REMOVED_CARD: return "SCARD_W_REMOVED_CARD"; - case SCARD_W_RESET_CARD: return "SCARD_W_RESET_CARD"; + case SCARD_W_REMOVED_CARD: return "SCARD_W_REMOVED_CARD"; + case SCARD_W_RESET_CARD: return "SCARD_W_RESET_CARD"; #ifdef SCARD_W_SECURITY_VIOLATION - case SCARD_W_SECURITY_VIOLATION: return "SCARD_W_SECURITY_VIOLATION"; + case SCARD_W_SECURITY_VIOLATION: return "SCARD_W_SECURITY_VIOLATION"; #endif - case SCARD_W_UNPOWERED_CARD: return "SCARD_W_UNPOWERED_CARD"; - case SCARD_W_UNRESPONSIVE_CARD: return "SCARD_W_UNRESPONSIVE_CARD"; - case SCARD_W_UNSUPPORTED_CARD: return "SCARD_W_UNSUPPORTED_CARD"; + case SCARD_W_UNPOWERED_CARD: return "SCARD_W_UNPOWERED_CARD"; + case SCARD_W_UNRESPONSIVE_CARD: return "SCARD_W_UNRESPONSIVE_CARD"; + case SCARD_W_UNSUPPORTED_CARD: return "SCARD_W_UNSUPPORTED_CARD"; #ifdef SCARD_W_WRONG_CHV - case SCARD_W_WRONG_CHV: return "SCARD_W_WRONG_CHV"; + case SCARD_W_WRONG_CHV: return "SCARD_W_WRONG_CHV"; #endif - default: return "Unknown"; - } + default: return "Unknown"; + } } static char *e_bytes_to_hex(BYTE *buffer, DWORD length) @@ -453,15 +453,15 @@ static BYTE *e_hex_to_bytes(char *str, DWORD *length) DWORD i, l; BYTE *buf; - if (str == NULL) { + if (str == NULL) { return NULL; } - + l = strlen(str) / 2; if (length != NULL) { *length = l; } - + buf = emalloc(l); for (i = 0; i < l; i++) { @@ -484,10 +484,10 @@ PHP_FUNCTION(scard_establish_context) rc = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &scard_context); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } - + RETURN_RES(zend_register_resource((void*)scard_context,le_pcsc_ctx_res)); } /* }}} */ @@ -499,15 +499,15 @@ PHP_FUNCTION(scard_is_valid_context) LONG rc = 0; zval* ctx_res; SCARDCONTEXT context; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &ctx_res) == FAILURE) { RETURN_NULL(); } ZEND_FETCH_RESOURCE(context, SCARDCONTEXT, &ctx_res, -1, PHP_PCSC_CTX_RES_NAME, le_pcsc_ctx_res); - + rc = SCardIsValidContext(context); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } RETURN_TRUE; @@ -520,7 +520,7 @@ PHP_FUNCTION(scard_release_context) { zval* ctx_res; SCARDCONTEXT context; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &ctx_res) == FAILURE) { RETURN_NULL(); } @@ -542,22 +542,22 @@ PHP_FUNCTION(scard_list_readers) LONG rc = 0; zval* ctx_res; SCARDCONTEXT context; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &ctx_res) == FAILURE) { RETURN_NULL(); } ZEND_FETCH_RESOURCE(context, SCARDCONTEXT, &ctx_res, -1, PHP_PCSC_CTX_RES_NAME, le_pcsc_ctx_res); - + rc = SCardListReaders(context, NULL, (char *) &strReaders, &dwLen); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } - + if (strReaders == NULL) { RETURN_FALSE; } - + array_init(return_value); ptrReader = strReaders; @@ -566,7 +566,7 @@ PHP_FUNCTION(scard_list_readers) ptrReader+= strlen(ptrReader); ptrReader++; } while (*ptrReader != '\0'); - + SCardFreeMemory(context, strReaders); } /* }}} */ @@ -575,7 +575,7 @@ PHP_FUNCTION(scard_list_readers) Return a handle to the card */ PHP_FUNCTION(scard_connect) { - DWORD dwPreferredProtocol = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1; + DWORD dwPreferredProtocol = SCARD_PROTOCOL_RAW | SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1; DWORD dwCurrentProtocol; SCARDHANDLE hCard = 0; LONG rc = 0; @@ -585,7 +585,7 @@ PHP_FUNCTION(scard_connect) char *strReaderName; size_t strReaderNameLen; zend_long preferred_protocol; - + current_protocol = NULL; ctx_res = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lz", &ctx_res, &strReaderName, &strReaderNameLen, &preferred_protocol, ¤t_protocol) == FAILURE) { @@ -602,13 +602,13 @@ PHP_FUNCTION(scard_connect) rc = SCardConnect(context, strReaderName, SCARD_SHARE_SHARED, dwPreferredProtocol, &hCard, &dwCurrentProtocol); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } if (current_protocol != NULL) { ZVAL_LONG(current_protocol, dwCurrentProtocol); } - + RETURN_RES(zend_register_resource((void*)hCard, le_pcsc_conn_res)); } /* }}} */ @@ -621,15 +621,15 @@ PHP_FUNCTION(scard_disconnect) LONG rc; zval* conn_res; SCARDHANDLE hCard; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &conn_res, &dwDisposition) == FAILURE) { return; } ZEND_FETCH_RESOURCE(hCard, SCARDHANDLE, &conn_res, -1, PHP_PCSC_CONN_RES_NAME, le_pcsc_conn_res); - + rc = SCardDisconnect(hCard, (DWORD)dwDisposition); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } RETURN_TRUE; @@ -652,7 +652,7 @@ PHP_FUNCTION(scard_transmit) LONG rc; char *apdu; size_t apduLen; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &conn_res, &apdu, &apduLen) == FAILURE) { return; } @@ -661,15 +661,15 @@ PHP_FUNCTION(scard_transmit) /* Are we in T=0 or T=1 ? Is the card powered? */ rc = SCardStatus(hCard, NULL, NULL, &dwState, &dwProtocol, NULL, NULL); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } - + if (!(dwState & SCARD_POWERED)) { - PCSC_G(last_errno) = SCARD_W_UNPOWERED_CARD; + PCSC_G(last_errno) = SCARD_W_UNPOWERED_CARD; RETURN_FALSE; } - + switch (dwProtocol) { case SCARD_PROTOCOL_RAW : sendPci = SCARD_PCI_RAW; break; case SCARD_PROTOCOL_T0 : sendPci = SCARD_PCI_T0; break; @@ -690,7 +690,7 @@ PHP_FUNCTION(scard_transmit) rc = SCardTransmit(hCard, sendPci, sendBuffer, sendLen, recvPci, recvBuffer, &recvLen); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; efree(recvPci); efree(recvBuffer); efree(sendBuffer); @@ -717,16 +717,16 @@ PHP_FUNCTION(scard_status) BYTE atrBuffer[32]; DWORD atrLen; LONG rc; - + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &conn_res) == FAILURE) { return; } ZEND_FETCH_RESOURCE(hCard, SCARDHANDLE, &conn_res, -1, PHP_PCSC_CONN_RES_NAME, le_pcsc_conn_res); - + atrLen = sizeof(atrBuffer); rc = SCardStatus(hCard, NULL, NULL, &dwState, &dwProtocol, atrBuffer, &atrLen); if (rc != SCARD_S_SUCCESS) { - PCSC_G(last_errno) = rc; + PCSC_G(last_errno) = rc; RETURN_FALSE; } @@ -751,7 +751,6 @@ PHP_FUNCTION(scard_status) add_assoc_long(return_value, "SCARD_SPECIFIC", 1); switch (dwProtocol) { - /* Maybe change to bool type here instead of add_assoc_long...? */ case SCARD_PROTOCOL_RAW : add_assoc_long(return_value, "SCARD_PROTOCOL_RAW", 1); add_assoc_string(return_value, "PROTOCOL", "RAW"); break; @@ -780,7 +779,7 @@ PHP_FUNCTION(scard_last_errno) if (zend_parse_parameters_none() == FAILURE) { return; } - RETURN_LONG(PCSC_G(last_errno)); + RETURN_LONG(PCSC_G(last_errno)); } /* }}} */ From 576a3c6ca0c8676bd7109e43c06aa7930a49287e Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 04:16:16 +0100 Subject: [PATCH 19/29] .gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0cbbd11..b127146 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ config.cache config.guess config.h config.h.in +config.h.in~ config.log config.nice config.status From 9023e2a831e575d71424dfed2309dd0da799a954 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 04:17:32 +0100 Subject: [PATCH 20/29] README update --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 78421d1..d15ee5c 100644 --- a/README.md +++ b/README.md @@ -207,11 +207,11 @@ This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite This extension was originally written in 2005 by Johann Dantant. In 2011 Johannes Findeisen took his code and updated it to work with the current PHP version. Johannes maintains the code to this day, but there have been some contributions from other people in the past. All people who have worked on extending or porting the "pcsc" extension are listed below in alphabetical order by their last name. Thanks to all! - * Anatol Belski (Contributor) - * Calvin Buckley (Contributor) - * Remi Collet (Contributor) + * [Anatol Belski](https://github.com/weltling) (Contributor) + * [Calvin Buckley](https://github.com/NattyNarwhal) (Contributor) + * [Remi Collet](https://github.com/remicollet) (Contributor) * Johann Dantant (Original author) - * Johannes Findeisen (Maintainer) + * [Johannes Findeisen](https://github.com/hanez) (Maintainer) * Marco Schuster (Contributor) ## Links From 62b8e1e6d80ae657f72559801bab4eacf7193fde Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 04:21:28 +0100 Subject: [PATCH 21/29] Added scard_begin_transaction and scard_end_transaction; SEGFAULTS when using it --- docs/examples/simple.php | 22 ++++++++++++++ package.xml | 2 +- pcsc.c | 42 +++++++++++++++++++++++++++ pcsc.stub.php | 12 ++++++++ pcsc_arginfo.h | 62 +++++++++++++++++++++++----------------- pcsc_legacy_arginfo.h | 60 ++++++++++++++++++++++---------------- php_pcsc.h | 4 ++- 7 files changed, 151 insertions(+), 53 deletions(-) diff --git a/docs/examples/simple.php b/docs/examples/simple.php index 87c0c5a..04504e3 100644 --- a/docs/examples/simple.php +++ b/docs/examples/simple.php @@ -48,6 +48,17 @@ $errstr = scard_errstr($errno); var_dump($errstr); echo "\n"; +# Begin Transaction +echo ">> Begin Transaction\n"; +$begin= scard_begin_transaction($connection); +var_dump($begin); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + # Select Applet APDU echo ">> Select Applet\n"; $CMD = "00a4040c0cD2760001354B414E4D30310000"; @@ -73,6 +84,17 @@ $errstr = scard_errstr($errno); var_dump($errstr); echo "\n"; +# End Transaction +echo ">> End Transaction\n"; +$begin= scard_end_transaction($connection); +var_dump($connection); + +$errno = scard_last_errno(); +var_dump($errno); +$errstr = scard_errstr($errno); +var_dump($errstr); +echo "\n"; + # Show Status echo ">> Show Status\n"; $status = scard_status($connection); diff --git a/package.xml b/package.xml index 26b7da0..5b762eb 100644 --- a/package.xml +++ b/package.xml @@ -23,7 +23,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> 2021-02-21 - 0.5.1 + 0.6.0 0.3.1 diff --git a/pcsc.c b/pcsc.c index 23ec66d..c833121 100644 --- a/pcsc.c +++ b/pcsc.c @@ -636,6 +636,48 @@ PHP_FUNCTION(scard_disconnect) } /* }}} */ +/* {{{ proto boolean scard_begin_transaction(resource card_handle) + Begin transaction on a card connection obtained with scard_connect */ +PHP_FUNCTION(scard_begin_transaction) +{ + LONG rc; + zval* conn_res; + SCARDHANDLE hCard; + + ZEND_FETCH_RESOURCE(hCard, SCARDHANDLE, &conn_res, -1, PHP_PCSC_CONN_RES_NAME, le_pcsc_conn_res); + + rc = SCardBeginTransaction(hCard); + if (rc != SCARD_S_SUCCESS) { + PCSC_G(last_errno) = rc; + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto boolean scard_end_transaction(resource card_handle, [long disposition = SCARD_LEAVE_CARD]) + End a previously begun transaction invoked by scard_begin_transaction on a card connection obtained with scard_connect; If no transaction began, do nothing. */ +PHP_FUNCTION(scard_end_transaction) +{ + zend_long dwDisposition = SCARD_LEAVE_CARD; + LONG rc; + zval* conn_res; + SCARDHANDLE hCard; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &conn_res, &dwDisposition) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(hCard, SCARDHANDLE, &conn_res, -1, PHP_PCSC_CONN_RES_NAME, le_pcsc_conn_res); + + rc = SCardEndTransaction(hCard, (DWORD)dwDisposition); + if (rc != SCARD_S_SUCCESS) { + PCSC_G(last_errno) = rc; + RETURN_FALSE; + } + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto string scard_transmit(resource card_handle, string send_command) Transmit (and receive) data to (and from) the card */ PHP_FUNCTION(scard_transmit) diff --git a/pcsc.stub.php b/pcsc.stub.php index 1a973c3..c295f40 100644 --- a/pcsc.stub.php +++ b/pcsc.stub.php @@ -37,6 +37,18 @@ function scard_connect($context, string $reader_name, int $preferred_protocol=SC */ function scard_disconnect($card, int $disposition=SCARD_EJECT_CARD): bool {} +/** + * @param resource $card + * @return resource|false + */ +function scard_begin_transaction($card): bool {} + +/** + * @param resource $card + * @return resource|false + */ +function scard_end_transaction($card, int $disposition=SCARD_LEAVE_CARD): bool {} + /** * @param resource $card * @return resource|false diff --git a/pcsc_arginfo.h b/pcsc_arginfo.h index 80b4481..6ecb3e8 100644 --- a/pcsc_arginfo.h +++ b/pcsc_arginfo.h @@ -1,45 +1,51 @@ -/* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3e1df1d509b6416c1eb997f61295c26d9ad0fd03 */ - ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_establish_context, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_release_context, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() #define arginfo_scard_is_valid_context arginfo_scard_release_context ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_list_readers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_connect, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, context) - ZEND_ARG_TYPE_INFO(0, reader_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preferred_protocol, IS_LONG, 0, "SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(1, current_protocol, IS_LONG, 0, "NULL") + ZEND_ARG_INFO(0, context) + ZEND_ARG_TYPE_INFO(0, reader_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preferred_protocol, IS_LONG, 0, "SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(1, current_protocol, IS_LONG, 0, "NULL") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_disconnect, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, card) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_EJECT_CARD") + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_EJECT_CARD") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_begin_transaction, 0, 1, _IS_BOOL, 0) + ZEND_ARG_INFO(0, card) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_end_transaction, 0, 1, _IS_BOOL, 0) + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_LEAVE_CARD") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_transmit, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, card) - ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_status, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, card) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_last_errno, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_errstr, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, errno, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, errno, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -49,6 +55,8 @@ ZEND_FUNCTION(scard_is_valid_context); ZEND_FUNCTION(scard_list_readers); ZEND_FUNCTION(scard_connect); ZEND_FUNCTION(scard_disconnect); +ZEND_FUNCTION(scard_begin_transaction); +ZEND_FUNCTION(scard_end_transaction); ZEND_FUNCTION(scard_transmit); ZEND_FUNCTION(scard_status); ZEND_FUNCTION(scard_last_errno); @@ -56,15 +64,17 @@ ZEND_FUNCTION(scard_errstr); static const zend_function_entry ext_functions[] = { - ZEND_FE(scard_establish_context, arginfo_scard_establish_context) - ZEND_FE(scard_release_context, arginfo_scard_release_context) - ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) - ZEND_FE(scard_list_readers, arginfo_scard_list_readers) - ZEND_FE(scard_connect, arginfo_scard_connect) - ZEND_FE(scard_disconnect, arginfo_scard_disconnect) - ZEND_FE(scard_transmit, arginfo_scard_transmit) - ZEND_FE(scard_status, arginfo_scard_status) - ZEND_FE(scard_last_errno, arginfo_scard_last_errno) - ZEND_FE(scard_errstr, arginfo_scard_errstr) - ZEND_FE_END + ZEND_FE(scard_establish_context, arginfo_scard_establish_context) + ZEND_FE(scard_release_context, arginfo_scard_release_context) + ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) + ZEND_FE(scard_list_readers, arginfo_scard_list_readers) + ZEND_FE(scard_connect, arginfo_scard_connect) + ZEND_FE(scard_disconnect, arginfo_scard_disconnect) + ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) + ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) + ZEND_FE(scard_transmit, arginfo_scard_transmit) + ZEND_FE(scard_status, arginfo_scard_status) + ZEND_FE(scard_last_errno, arginfo_scard_last_errno) + ZEND_FE(scard_errstr, arginfo_scard_errstr) + ZEND_FE_END }; diff --git a/pcsc_legacy_arginfo.h b/pcsc_legacy_arginfo.h index c56c076..17975db 100644 --- a/pcsc_legacy_arginfo.h +++ b/pcsc_legacy_arginfo.h @@ -1,11 +1,8 @@ -/* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3e1df1d509b6416c1eb997f61295c26d9ad0fd03 */ - ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_establish_context, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_release_context, 0, 0, 1) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() #define arginfo_scard_is_valid_context arginfo_scard_release_context @@ -13,30 +10,39 @@ ZEND_END_ARG_INFO() #define arginfo_scard_list_readers arginfo_scard_release_context ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_connect, 0, 0, 2) - ZEND_ARG_INFO(0, context) - ZEND_ARG_INFO(0, reader_name) - ZEND_ARG_INFO(0, preferred_protocol) - ZEND_ARG_INFO(1, current_protocol) + ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, reader_name) + ZEND_ARG_INFO(0, preferred_protocol) + ZEND_ARG_INFO(1, current_protocol) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_disconnect, 0, 0, 1) - ZEND_ARG_INFO(0, card) - ZEND_ARG_INFO(0, disposition) + ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, disposition) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_begin_transaction, 0, 0, 1) + ZEND_ARG_INFO(0, card) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_end_transaction, 0, 0, 1) + ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, disposition) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_transmit, 0, 0, 2) - ZEND_ARG_INFO(0, card) - ZEND_ARG_INFO(0, command) + ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, command) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_status, 0, 0, 1) - ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, card) ZEND_END_ARG_INFO() #define arginfo_scard_last_errno arginfo_scard_establish_context ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_errstr, 0, 0, 1) - ZEND_ARG_INFO(0, errno) + ZEND_ARG_INFO(0, errno) ZEND_END_ARG_INFO() @@ -46,6 +52,8 @@ ZEND_FUNCTION(scard_is_valid_context); ZEND_FUNCTION(scard_list_readers); ZEND_FUNCTION(scard_connect); ZEND_FUNCTION(scard_disconnect); +ZEND_FUNCTION(scard_begin_transaction); +ZEND_FUNCTION(scard_end_transaction); ZEND_FUNCTION(scard_transmit); ZEND_FUNCTION(scard_status); ZEND_FUNCTION(scard_last_errno); @@ -53,15 +61,17 @@ ZEND_FUNCTION(scard_errstr); static const zend_function_entry ext_functions[] = { - ZEND_FE(scard_establish_context, arginfo_scard_establish_context) - ZEND_FE(scard_release_context, arginfo_scard_release_context) - ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) - ZEND_FE(scard_list_readers, arginfo_scard_list_readers) - ZEND_FE(scard_connect, arginfo_scard_connect) - ZEND_FE(scard_disconnect, arginfo_scard_disconnect) - ZEND_FE(scard_transmit, arginfo_scard_transmit) - ZEND_FE(scard_status, arginfo_scard_status) - ZEND_FE(scard_last_errno, arginfo_scard_last_errno) - ZEND_FE(scard_errstr, arginfo_scard_errstr) - ZEND_FE_END + ZEND_FE(scard_establish_context, arginfo_scard_establish_context) + ZEND_FE(scard_release_context, arginfo_scard_release_context) + ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) + ZEND_FE(scard_list_readers, arginfo_scard_list_readers) + ZEND_FE(scard_connect, arginfo_scard_connect) + ZEND_FE(scard_disconnect, arginfo_scard_disconnect) + ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) + ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) + ZEND_FE(scard_transmit, arginfo_scard_transmit) + ZEND_FE(scard_status, arginfo_scard_status) + ZEND_FE(scard_last_errno, arginfo_scard_last_errno) + ZEND_FE(scard_errstr, arginfo_scard_errstr) + ZEND_FE_END }; diff --git a/php_pcsc.h b/php_pcsc.h index e91ff4e..e4f3811 100644 --- a/php_pcsc.h +++ b/php_pcsc.h @@ -4,7 +4,7 @@ extern zend_module_entry pcsc_module_entry; #define phpext_pcsc_ptr &pcsc_module_entry -#define PHP_PCSC_VERSION "0.5.1" +#define PHP_PCSC_VERSION "0.6.0" #ifdef PHP_WIN32 #define PHP_PCSC_API __declspec(dllexport) @@ -32,6 +32,8 @@ PHP_FUNCTION(scard_list_readers); PHP_FUNCTION(scard_connect); //PHP_FUNCTION(scard_reconnect); PHP_FUNCTION(scard_disconnect); +PHP_FUNCTION(scard_begin_transaction); +PHP_FUNCTION(scard_end_transaction); PHP_FUNCTION(scard_status); //PHP_FUNCTION(scard_get_status_change); PHP_FUNCTION(scard_transmit); From 4b2df9bae88df9269bafee810d07204e996329a2 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 22 Feb 2021 04:32:30 +0100 Subject: [PATCH 22/29] Copy/Paste fix --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d15ee5c..9794824 100644 --- a/README.md +++ b/README.md @@ -176,11 +176,11 @@ array(7) { Returns the response $apdu as string or FALSE. -# To do: +## To do: There is some stuff to do. Some things are important but some are not. -## Implement important missing PC/SC functions and write documentation: +### Implement important missing PC/SC functions and write documentation: * SCardBeginTransaction() * SCardEndTransaction() @@ -188,14 +188,14 @@ There is some stuff to do. Some things are important but some are not. * SCardGetStatusChange() * Write complete API documentation -## Implement less important missing PC/SC functions: +### Implement less important missing PC/SC functions: * SCardGetAttrib() * SCardSetAttrib() * SCardListReaderGroups() * SCardReconnect() -## Goal: +### Goal: Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) @@ -203,7 +203,7 @@ Completely implement the full API from [PC/SC API from PCSC-Lite](https://pcscli This code is licensed under the terms of the PHP License version 3.01. PCSC-Lite is licensed in a way where it is possible to integrate it native in the PHP environment. -# Credits +## Credits This extension was originally written in 2005 by Johann Dantant. In 2011 Johannes Findeisen took his code and updated it to work with the current PHP version. Johannes maintains the code to this day, but there have been some contributions from other people in the past. All people who have worked on extending or porting the "pcsc" extension are listed below in alphabetical order by their last name. Thanks to all! From aab796c98209de2665e5d57a2c6d169ad77ab741 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 23 Feb 2021 20:37:54 +0100 Subject: [PATCH 23/29] .gitignore update --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b127146..7d924cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.dep + # Object files *.o *.lo @@ -34,6 +36,7 @@ config.nice config.status config.sub configure +configure.ac configure.in conftest conftest.c From 1503e63658cc86fe4ff26bfba02ac326388541b6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 23 Feb 2021 22:45:15 +0100 Subject: [PATCH 24/29] Fixed compile error be generating arginfo headers --- pcsc_arginfo.h | 63 ++++++++++++++++++++++--------------------- pcsc_legacy_arginfo.h | 60 ++++++++++++++++++++--------------------- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/pcsc_arginfo.h b/pcsc_arginfo.h index 6ecb3e8..704a4ae 100644 --- a/pcsc_arginfo.h +++ b/pcsc_arginfo.h @@ -1,51 +1,54 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 676b86ff0a1ee4d762d86126e8068f4cb6805272 */ + ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_establish_context, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_release_context, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() #define arginfo_scard_is_valid_context arginfo_scard_release_context ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_list_readers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_connect, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, context) - ZEND_ARG_TYPE_INFO(0, reader_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preferred_protocol, IS_LONG, 0, "SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(1, current_protocol, IS_LONG, 0, "NULL") + ZEND_ARG_INFO(0, context) + ZEND_ARG_TYPE_INFO(0, reader_name, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, preferred_protocol, IS_LONG, 0, "SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(1, current_protocol, IS_LONG, 0, "NULL") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_disconnect, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, card) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_EJECT_CARD") + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_EJECT_CARD") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_begin_transaction, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, card) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_begin_transaction, 0, 1, _IS_BOOL, 0) + ZEND_ARG_INFO(0, card) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_end_transaction, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, card) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_LEAVE_CARD") +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_end_transaction, 0, 1, _IS_BOOL, 0) + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, disposition, IS_LONG, 0, "SCARD_LEAVE_CARD") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_transmit, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, card) - ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) + ZEND_ARG_INFO(0, card) + ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_scard_status, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, card) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_last_errno, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_scard_errstr, 0, 1, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, errno, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, errno, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -64,17 +67,17 @@ ZEND_FUNCTION(scard_errstr); static const zend_function_entry ext_functions[] = { - ZEND_FE(scard_establish_context, arginfo_scard_establish_context) - ZEND_FE(scard_release_context, arginfo_scard_release_context) - ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) - ZEND_FE(scard_list_readers, arginfo_scard_list_readers) - ZEND_FE(scard_connect, arginfo_scard_connect) - ZEND_FE(scard_disconnect, arginfo_scard_disconnect) - ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) - ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) - ZEND_FE(scard_transmit, arginfo_scard_transmit) - ZEND_FE(scard_status, arginfo_scard_status) - ZEND_FE(scard_last_errno, arginfo_scard_last_errno) - ZEND_FE(scard_errstr, arginfo_scard_errstr) - ZEND_FE_END + ZEND_FE(scard_establish_context, arginfo_scard_establish_context) + ZEND_FE(scard_release_context, arginfo_scard_release_context) + ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) + ZEND_FE(scard_list_readers, arginfo_scard_list_readers) + ZEND_FE(scard_connect, arginfo_scard_connect) + ZEND_FE(scard_disconnect, arginfo_scard_disconnect) + ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) + ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) + ZEND_FE(scard_transmit, arginfo_scard_transmit) + ZEND_FE(scard_status, arginfo_scard_status) + ZEND_FE(scard_last_errno, arginfo_scard_last_errno) + ZEND_FE(scard_errstr, arginfo_scard_errstr) + ZEND_FE_END }; diff --git a/pcsc_legacy_arginfo.h b/pcsc_legacy_arginfo.h index 17975db..132f188 100644 --- a/pcsc_legacy_arginfo.h +++ b/pcsc_legacy_arginfo.h @@ -1,8 +1,11 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 676b86ff0a1ee4d762d86126e8068f4cb6805272 */ + ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_establish_context, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_release_context, 0, 0, 1) - ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, context) ZEND_END_ARG_INFO() #define arginfo_scard_is_valid_context arginfo_scard_release_context @@ -10,39 +13,34 @@ ZEND_END_ARG_INFO() #define arginfo_scard_list_readers arginfo_scard_release_context ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_connect, 0, 0, 2) - ZEND_ARG_INFO(0, context) - ZEND_ARG_INFO(0, reader_name) - ZEND_ARG_INFO(0, preferred_protocol) - ZEND_ARG_INFO(1, current_protocol) + ZEND_ARG_INFO(0, context) + ZEND_ARG_INFO(0, reader_name) + ZEND_ARG_INFO(0, preferred_protocol) + ZEND_ARG_INFO(1, current_protocol) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_disconnect, 0, 0, 1) - ZEND_ARG_INFO(0, card) - ZEND_ARG_INFO(0, disposition) + ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, disposition) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_begin_transaction, 0, 0, 1) - ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, card) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_end_transaction, 0, 0, 1) - ZEND_ARG_INFO(0, card) - ZEND_ARG_INFO(0, disposition) -ZEND_END_ARG_INFO() +#define arginfo_scard_end_transaction arginfo_scard_disconnect ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_transmit, 0, 0, 2) - ZEND_ARG_INFO(0, card) - ZEND_ARG_INFO(0, command) + ZEND_ARG_INFO(0, card) + ZEND_ARG_INFO(0, command) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_status, 0, 0, 1) - ZEND_ARG_INFO(0, card) -ZEND_END_ARG_INFO() +#define arginfo_scard_status arginfo_scard_begin_transaction #define arginfo_scard_last_errno arginfo_scard_establish_context ZEND_BEGIN_ARG_INFO_EX(arginfo_scard_errstr, 0, 0, 1) - ZEND_ARG_INFO(0, errno) + ZEND_ARG_INFO(0, errno) ZEND_END_ARG_INFO() @@ -61,17 +59,17 @@ ZEND_FUNCTION(scard_errstr); static const zend_function_entry ext_functions[] = { - ZEND_FE(scard_establish_context, arginfo_scard_establish_context) - ZEND_FE(scard_release_context, arginfo_scard_release_context) - ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) - ZEND_FE(scard_list_readers, arginfo_scard_list_readers) - ZEND_FE(scard_connect, arginfo_scard_connect) - ZEND_FE(scard_disconnect, arginfo_scard_disconnect) - ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) - ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) - ZEND_FE(scard_transmit, arginfo_scard_transmit) - ZEND_FE(scard_status, arginfo_scard_status) - ZEND_FE(scard_last_errno, arginfo_scard_last_errno) - ZEND_FE(scard_errstr, arginfo_scard_errstr) - ZEND_FE_END + ZEND_FE(scard_establish_context, arginfo_scard_establish_context) + ZEND_FE(scard_release_context, arginfo_scard_release_context) + ZEND_FE(scard_is_valid_context, arginfo_scard_is_valid_context) + ZEND_FE(scard_list_readers, arginfo_scard_list_readers) + ZEND_FE(scard_connect, arginfo_scard_connect) + ZEND_FE(scard_disconnect, arginfo_scard_disconnect) + ZEND_FE(scard_begin_transaction, arginfo_scard_begin_transaction) + ZEND_FE(scard_end_transaction, arginfo_scard_end_transaction) + ZEND_FE(scard_transmit, arginfo_scard_transmit) + ZEND_FE(scard_status, arginfo_scard_status) + ZEND_FE(scard_last_errno, arginfo_scard_last_errno) + ZEND_FE(scard_errstr, arginfo_scard_errstr) + ZEND_FE_END }; From a722128295534d2243085c78a31fe1c2dedfe55d Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 23 Feb 2021 22:52:12 +0100 Subject: [PATCH 25/29] Added Jan Erhardt to list of contributors --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9794824..d38098c 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,7 @@ This extension was originally written in 2005 by Johann Dantant. In 2011 Johanne * [Calvin Buckley](https://github.com/NattyNarwhal) (Contributor) * [Remi Collet](https://github.com/remicollet) (Contributor) * Johann Dantant (Original author) + * [Jan Ehrhardt](https://github.com/Jan-E) (Contributor) * [Johannes Findeisen](https://github.com/hanez) (Maintainer) * Marco Schuster (Contributor) From 1c14647729ae860e0121ae90042ac121631a00a6 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 23 Feb 2021 22:57:46 +0100 Subject: [PATCH 26/29] .gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7d924cc..af84c8f 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ config.nice config.status config.sub configure +configure~ configure.ac configure.in conftest From 9ab1ae883ac06da9e4af7a64373653184becbd65 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 23 Feb 2021 23:30:10 +0100 Subject: [PATCH 27/29] Testscript simple.php cleaned up --- docs/examples/simple.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/examples/simple.php b/docs/examples/simple.php index 04504e3..a120c10 100644 --- a/docs/examples/simple.php +++ b/docs/examples/simple.php @@ -39,8 +39,8 @@ echo "\n"; # Connect to the card echo ">> Connect to Card\n"; -$connection = scard_connect($context, $reader, 1); -var_dump($connection); + $card = scard_connect($context, $reader, 2); +var_dump( $card ); $errno = scard_last_errno(); var_dump($errno); @@ -50,7 +50,7 @@ echo "\n"; # Begin Transaction echo ">> Begin Transaction\n"; -$begin= scard_begin_transaction($connection); +$begin= scard_begin_transaction($card); var_dump($begin); $errno = scard_last_errno(); @@ -61,8 +61,8 @@ echo "\n"; # Select Applet APDU echo ">> Select Applet\n"; -$CMD = "00a4040c0cD2760001354B414E4D30310000"; -$res = scard_transmit($connection, $CMD); +$apdu = "00a4040c0cD2760001354B414E4D30310000"; +$res = scard_transmit($card , $apdu); var_dump($res); $errno = scard_last_errno(); @@ -73,8 +73,8 @@ echo "\n"; # test APDU echo ">> Send APDU\n"; -$CMD = "0084000008"; -$res = scard_transmit($connection, $CMD); +$apdu = "0084000008"; +$res = scard_transmit($card, $apdu); var_dump($res); #echo pack("H*", $res), "\n"; @@ -86,8 +86,8 @@ echo "\n"; # End Transaction echo ">> End Transaction\n"; -$begin= scard_end_transaction($connection); -var_dump($connection); +$begin= scard_end_transaction($card); +var_dump( $card ); $errno = scard_last_errno(); var_dump($errno); @@ -97,7 +97,7 @@ echo "\n"; # Show Status echo ">> Show Status\n"; -$status = scard_status($connection); +$status = scard_status($card); var_dump($status); $errno = scard_last_errno(); From 37ecbc4eb015ec335dce40fcb527014f1596ed09 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 5 May 2022 03:17:27 +0200 Subject: [PATCH 28/29] .gitignore update --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index af84c8f..34ab023 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +nbproject/ + *.dep # Object files From 0b0fab487ff892b35e97be017cded3c7fafeef93 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 12 May 2024 00:46:29 +0200 Subject: [PATCH 29/29] Link in README update. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d38098c..73e8a4d 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,6 @@ This extension was originally written in 2005 by Johann Dantant. In 2011 Johanne * [PC/SC](http://en.wikipedia.org/wiki/PC/SC) - PC/SC at Wikipedia * [PC/SC-Lite](https://pcsclite.apdu.fr/) - The free and open implementation of the PC/SC SCard API for UNIX * [PC/SC API from PCSC-Lite](https://pcsclite.apdu.fr/api/group__API.html) - Documentation of the PCSC-Lite API - * [PCSC sample in PHP5](http://ludovicrousseau.blogspot.de/2015/01/pcsc-sample-in-php5.html) - Ludovic Rousseau about "PC/SC for PHP" + * [PCSC sample in PHP5](https://blog.apdu.fr/posts/2015/01/pcsc-sample-in-php5/) - Ludovic Rousseau about "PC/SC for PHP" * [winscard.h header](https://docs.microsoft.com/en-us/windows/win32/api/winscard/) - Microsoft Documentation