mirror of
https://github.com/pcsc-for-php/pcsc.git
synced 2026-08-08 21:09:26 +02:00
Fixed and added some more PHP test code; Not stable
This commit is contained in:
parent
5aad57fa26
commit
2562478bd4
3 changed files with 102 additions and 13 deletions
|
|
@ -14,39 +14,39 @@ class PCSC {
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->context = scard_establish_context();
|
$this->context = scard_establish_context();
|
||||||
}
|
}
|
||||||
|
|
||||||
function __destruct() {
|
/*function __destruct() {
|
||||||
$this->context = scard_release_context($this->context);
|
$this->context = scard_release_context($this->context);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
function connect($reader) {
|
function connect($reader) {
|
||||||
return $this->connection = scard_connect($this->context, $reader);
|
return $this->connection = scard_connect($this->context, $reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function reconnect() {
|
/*function reconnect() {
|
||||||
return $this->connection = scard_reconnect($this->connection);
|
return $this->connection = scard_reconnect($this->connection);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
function disconnect() {
|
function disconnect() {
|
||||||
return scard_disconnect($this->connection);
|
return scard_disconnect($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
function listreaders() {
|
function listreaders() {
|
||||||
return $this->readers = scard_list_readers($this->context);
|
return $this->readers = scard_list_readers($this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transmit($apdu) {
|
function transmit($apdu) {
|
||||||
return scard_transmit($this->connection, $apdu);
|
return scard_transmit($this->connection, $apdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isvalidcontext() {
|
function isvalidcontext() {
|
||||||
return scard_is_valid_context($this->context);
|
return scard_is_valid_context($this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
function releasecontext() {
|
function releasecontext() {
|
||||||
return scard_release_context($this->context);
|
return scard_release_context($this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
function status() {
|
function status() {
|
||||||
return scard_status($this->connection);
|
return scard_status($this->connection);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
86
docs/examples/simple.php
Normal file
86
docs/examples/simple.php
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if (!extension_loaded('pcsc')) {
|
||||||
|
dl('pcsc.so');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get a PC/SC context
|
||||||
|
echo ">> 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";
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -13,19 +13,22 @@ $foo = new PCSC();
|
||||||
echo "Create Context:\n";
|
echo "Create Context:\n";
|
||||||
var_dump($foo->context);
|
var_dump($foo->context);
|
||||||
|
|
||||||
|
#echo "Last Error String:";
|
||||||
|
#var_dump($foo->scard_errstr($foo->scard_last_errno()));
|
||||||
|
|
||||||
echo "List Readers:\n";
|
echo "List Readers:\n";
|
||||||
var_dump($foo->listreaders());
|
var_dump($foo->listreaders());
|
||||||
|
|
||||||
echo "Connect Card:\n";
|
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";
|
#echo "Reconnect:\n";
|
||||||
#var_dump($foo->reconnect());
|
#var_dump($foo->reconnect());
|
||||||
|
|
||||||
echo "Some Transmits:\n";
|
echo "Some Transmits:\n";
|
||||||
|
// Select applet
|
||||||
var_dump($foo->transmit("00a4040c0cD2760001354B414E4D30310000"));
|
var_dump($foo->transmit("00a4040c0cD2760001354B414E4D30310000"));
|
||||||
var_dump($foo->transmit("0084000008"));
|
// APDU to execute RNG function on card applet
|
||||||
var_dump($foo->transmit("0084000008"));
|
|
||||||
var_dump($foo->transmit("0084000008"));
|
var_dump($foo->transmit("0084000008"));
|
||||||
|
|
||||||
echo "Is Valid Context?\n";
|
echo "Is Valid Context?\n";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue