author | dl |
Wed, 28 Nov 2018 15:25:14 -0800 | |
changeset 52730 | 345266000aba |
parent 51120 | dccdf51b10dd |
child 53930 | df3d253aaf81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
51120 | 2 |
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* disable asserts in product mode */ |
|
27 |
#ifndef DEBUG |
|
28 |
#ifndef NDEBUG |
|
29 |
#define NDEBUG |
|
30 |
#endif |
|
31 |
#endif |
|
32 |
||
33 |
#include <stdio.h> |
|
34 |
#include <stdlib.h> |
|
35 |
#include <string.h> |
|
36 |
#include <assert.h> |
|
37 |
||
38 |
#include <winscard.h> |
|
39 |
||
40 |
// #define J2PCSC_DEBUG |
|
41 |
||
42 |
#ifdef J2PCSC_DEBUG |
|
43 |
#define dprintf(s) printf(s) |
|
44 |
#define dprintf1(s, p1) printf(s, p1) |
|
45 |
#define dprintf2(s, p1, p2) printf(s, p1, p2) |
|
46 |
#define dprintf3(s, p1, p2, p3) printf(s, p1, p2, p3) |
|
47 |
#else |
|
48 |
#define dprintf(s) |
|
49 |
#define dprintf1(s, p1) |
|
50 |
#define dprintf2(s, p1, p2) |
|
51 |
#define dprintf3(s, p1, p2, p3) |
|
52 |
#endif |
|
53 |
||
54 |
#include "sun_security_smartcardio_PCSC.h" |
|
55 |
||
56 |
#include "pcsc_md.h" |
|
57 |
||
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
58 |
#include "jni_util.h" |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
59 |
|
2 | 60 |
#define MAX_STACK_BUFFER_SIZE 8192 |
61 |
||
62 |
// make the buffers larger than what should be necessary, just in case |
|
63 |
#define ATR_BUFFER_SIZE 128 |
|
64 |
#define READERNAME_BUFFER_SIZE 128 |
|
65 |
#define RECEIVE_BUFFER_SIZE MAX_STACK_BUFFER_SIZE |
|
66 |
||
67 |
#define J2PCSC_EXCEPTION_NAME "sun/security/smartcardio/PCSCException" |
|
68 |
||
23709
9f7652fb03b2
8039118: Windows build failure (j2pcsc.dll : fatal error unresolved external symbol throwByName)
chegar
parents:
23704
diff
changeset
|
69 |
void throwOutOfMemoryError(JNIEnv *env, const char *msg) { |
9f7652fb03b2
8039118: Windows build failure (j2pcsc.dll : fatal error unresolved external symbol throwByName)
chegar
parents:
23704
diff
changeset
|
70 |
jclass cls = (*env)->FindClass(env, "java/lang/OutOfMemoryError"); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
71 |
|
23709
9f7652fb03b2
8039118: Windows build failure (j2pcsc.dll : fatal error unresolved external symbol throwByName)
chegar
parents:
23704
diff
changeset
|
72 |
if (cls != NULL) /* Otherwise an exception has already been thrown */ |
9f7652fb03b2
8039118: Windows build failure (j2pcsc.dll : fatal error unresolved external symbol throwByName)
chegar
parents:
23704
diff
changeset
|
73 |
(*env)->ThrowNew(env, cls, msg); |
9f7652fb03b2
8039118: Windows build failure (j2pcsc.dll : fatal error unresolved external symbol throwByName)
chegar
parents:
23704
diff
changeset
|
74 |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
75 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
76 |
|
2 | 77 |
void throwPCSCException(JNIEnv* env, LONG code) { |
78 |
jclass pcscClass; |
|
79 |
jmethodID constructor; |
|
80 |
jthrowable pcscException; |
|
81 |
||
82 |
pcscClass = (*env)->FindClass(env, J2PCSC_EXCEPTION_NAME); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
83 |
if (pcscClass == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
84 |
return; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
85 |
} |
2 | 86 |
constructor = (*env)->GetMethodID(env, pcscClass, "<init>", "(I)V"); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
87 |
if (constructor == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
88 |
return; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
89 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
90 |
pcscException = (jthrowable) (*env)->NewObject(env, pcscClass, |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
91 |
constructor, (jint)code); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
92 |
if (pcscException != NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
93 |
(*env)->Throw(env, pcscException); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
94 |
} |
2 | 95 |
} |
96 |
||
97 |
jboolean handleRV(JNIEnv* env, LONG code) { |
|
98 |
if (code == SCARD_S_SUCCESS) { |
|
99 |
return JNI_FALSE; |
|
100 |
} else { |
|
101 |
throwPCSCException(env, code); |
|
102 |
return JNI_TRUE; |
|
103 |
} |
|
104 |
} |
|
105 |
||
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
106 |
JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *vm, void *reserved) { |
2 | 107 |
return JNI_VERSION_1_4; |
108 |
} |
|
109 |
||
110 |
JNIEXPORT jlong JNICALL Java_sun_security_smartcardio_PCSC_SCardEstablishContext |
|
111 |
(JNIEnv *env, jclass thisClass, jint dwScope) |
|
112 |
{ |
|
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
113 |
SCARDCONTEXT context = 0; |
2 | 114 |
LONG rv; |
115 |
dprintf("-establishContext\n"); |
|
116 |
rv = CALL_SCardEstablishContext(dwScope, NULL, NULL, &context); |
|
117 |
if (handleRV(env, rv)) { |
|
118 |
return 0; |
|
119 |
} |
|
120 |
// note: SCARDCONTEXT is typedef'd as long, so this works |
|
121 |
return (jlong)context; |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Convert a multi string to a java string array, |
|
126 |
*/ |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
127 |
jobjectArray pcsc_multi2jstring(JNIEnv *env, char *spec) { |
2 | 128 |
jobjectArray result; |
129 |
jclass stringClass; |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
130 |
char *cp, **tab = NULL; |
2 | 131 |
jstring js; |
132 |
int cnt = 0; |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
133 |
|
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
134 |
cp = spec; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
135 |
while (*cp != 0) { |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
136 |
cp += (strlen(cp) + 1); |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
137 |
++cnt; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
138 |
} |
2 | 139 |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
140 |
tab = (char **)malloc(cnt * sizeof(char *)); |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
141 |
if (tab == NULL) { |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
142 |
throwOutOfMemoryError(env, NULL); |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
143 |
return NULL; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
144 |
} |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
145 |
|
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
146 |
cnt = 0; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
147 |
cp = spec; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
148 |
while (*cp != 0) { |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
149 |
tab[cnt++] = cp; |
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
150 |
cp += (strlen(cp) + 1); |
2 | 151 |
} |
152 |
||
153 |
stringClass = (*env)->FindClass(env, "java/lang/String"); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
154 |
if (stringClass == NULL) { |
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
155 |
free(tab); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
156 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
157 |
} |
2 | 158 |
|
159 |
result = (*env)->NewObjectArray(env, cnt, stringClass, NULL); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
160 |
if (result != NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
161 |
while (cnt-- > 0) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
162 |
js = (*env)->NewStringUTF(env, tab[cnt]); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
163 |
if ((*env)->ExceptionCheck(env)) { |
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
164 |
free(tab); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
165 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
166 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
167 |
(*env)->SetObjectArrayElement(env, result, cnt, js); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
168 |
if ((*env)->ExceptionCheck(env)) { |
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
169 |
free(tab); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
170 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
171 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
172 |
(*env)->DeleteLocalRef(env, js); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
173 |
} |
2 | 174 |
} |
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
175 |
free(tab); |
2 | 176 |
return result; |
177 |
} |
|
178 |
||
179 |
JNIEXPORT jobjectArray JNICALL Java_sun_security_smartcardio_PCSC_SCardListReaders |
|
180 |
(JNIEnv *env, jclass thisClass, jlong jContext) |
|
181 |
{ |
|
182 |
SCARDCONTEXT context = (SCARDCONTEXT)jContext; |
|
183 |
LONG rv; |
|
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
184 |
LPTSTR mszReaders = NULL; |
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
185 |
DWORD size = 0; |
2 | 186 |
jobjectArray result; |
187 |
||
188 |
dprintf1("-context: %x\n", context); |
|
189 |
rv = CALL_SCardListReaders(context, NULL, NULL, &size); |
|
190 |
if (handleRV(env, rv)) { |
|
191 |
return NULL; |
|
192 |
} |
|
193 |
dprintf1("-size: %d\n", size); |
|
194 |
||
51120 | 195 |
if (size != 0) { |
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
196 |
mszReaders = malloc(size); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
197 |
if (mszReaders == NULL) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
198 |
throwOutOfMemoryError(env, NULL); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
199 |
return NULL; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
200 |
} |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
201 |
|
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
202 |
rv = CALL_SCardListReaders(context, NULL, mszReaders, &size); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
203 |
if (handleRV(env, rv)) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
204 |
free(mszReaders); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
205 |
return NULL; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
206 |
} |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
207 |
dprintf1("-String: %s\n", mszReaders); |
51120 | 208 |
} else { |
209 |
return NULL; |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
210 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
211 |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
212 |
result = pcsc_multi2jstring(env, mszReaders); |
2 | 213 |
free(mszReaders); |
214 |
return result; |
|
215 |
} |
|
216 |
||
217 |
JNIEXPORT jlong JNICALL Java_sun_security_smartcardio_PCSC_SCardConnect |
|
218 |
(JNIEnv *env, jclass thisClass, jlong jContext, jstring jReaderName, |
|
219 |
jint jShareMode, jint jPreferredProtocols) |
|
220 |
{ |
|
221 |
SCARDCONTEXT context = (SCARDCONTEXT)jContext; |
|
222 |
LONG rv; |
|
223 |
LPCTSTR readerName; |
|
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
224 |
SCARDHANDLE card = 0; |
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
225 |
DWORD proto = 0; |
2 | 226 |
|
227 |
readerName = (*env)->GetStringUTFChars(env, jReaderName, NULL); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
228 |
if (readerName == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
229 |
return 0; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
230 |
} |
2 | 231 |
rv = CALL_SCardConnect(context, readerName, jShareMode, jPreferredProtocols, &card, &proto); |
232 |
(*env)->ReleaseStringUTFChars(env, jReaderName, readerName); |
|
233 |
dprintf1("-cardhandle: %x\n", card); |
|
234 |
dprintf1("-protocol: %d\n", proto); |
|
235 |
if (handleRV(env, rv)) { |
|
236 |
return 0; |
|
237 |
} |
|
238 |
||
239 |
return (jlong)card; |
|
240 |
} |
|
241 |
||
242 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardTransmit |
|
243 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint protocol, |
|
244 |
jbyteArray jBuf, jint jOfs, jint jLen) |
|
245 |
{ |
|
246 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
247 |
LONG rv; |
|
248 |
SCARD_IO_REQUEST sendPci; |
|
249 |
unsigned char *sbuf; |
|
250 |
unsigned char rbuf[RECEIVE_BUFFER_SIZE]; |
|
251 |
DWORD rlen = RECEIVE_BUFFER_SIZE; |
|
252 |
int ofs = (int)jOfs; |
|
253 |
int len = (int)jLen; |
|
254 |
jbyteArray jOut; |
|
255 |
||
256 |
sendPci.dwProtocol = protocol; |
|
257 |
sendPci.cbPciLength = sizeof(SCARD_IO_REQUEST); |
|
258 |
||
259 |
sbuf = (unsigned char *) ((*env)->GetByteArrayElements(env, jBuf, NULL)); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
260 |
if (sbuf == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
261 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
262 |
} |
2 | 263 |
rv = CALL_SCardTransmit(card, &sendPci, sbuf + ofs, len, NULL, rbuf, &rlen); |
264 |
(*env)->ReleaseByteArrayElements(env, jBuf, (jbyte *)sbuf, JNI_ABORT); |
|
265 |
||
266 |
if (handleRV(env, rv)) { |
|
267 |
return NULL; |
|
268 |
} |
|
269 |
||
270 |
jOut = (*env)->NewByteArray(env, rlen); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
271 |
if (jOut != NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
272 |
(*env)->SetByteArrayRegion(env, jOut, 0, rlen, (jbyte *)rbuf); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
273 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
274 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
275 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
276 |
} |
2 | 277 |
return jOut; |
278 |
} |
|
279 |
||
280 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardStatus |
|
281 |
(JNIEnv *env, jclass thisClass, jlong jCard, jbyteArray jStatus) |
|
282 |
{ |
|
283 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
284 |
LONG rv; |
|
285 |
char readerName[READERNAME_BUFFER_SIZE]; |
|
286 |
DWORD readerLen = READERNAME_BUFFER_SIZE; |
|
287 |
unsigned char atr[ATR_BUFFER_SIZE]; |
|
288 |
DWORD atrLen = ATR_BUFFER_SIZE; |
|
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
289 |
DWORD state = 0; |
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
290 |
DWORD protocol = 0; |
2 | 291 |
jbyteArray jArray; |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
292 |
jbyte status[2]; |
2 | 293 |
|
294 |
rv = CALL_SCardStatus(card, readerName, &readerLen, &state, &protocol, atr, &atrLen); |
|
295 |
if (handleRV(env, rv)) { |
|
296 |
return NULL; |
|
297 |
} |
|
298 |
dprintf1("-reader: %s\n", readerName); |
|
299 |
dprintf1("-status: %d\n", state); |
|
300 |
dprintf1("-protocol: %d\n", protocol); |
|
301 |
||
302 |
jArray = (*env)->NewByteArray(env, atrLen); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
303 |
if (jArray == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
304 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
305 |
} |
2 | 306 |
(*env)->SetByteArrayRegion(env, jArray, 0, atrLen, (jbyte *)atr); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
307 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
308 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
309 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
310 |
status[0] = (jbyte) state; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
311 |
status[1] = (jbyte) protocol; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
312 |
(*env)->SetByteArrayRegion(env, jStatus, 0, 2, status); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
313 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
314 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
315 |
} |
2 | 316 |
return jArray; |
317 |
} |
|
318 |
||
319 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardDisconnect |
|
320 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jDisposition) |
|
321 |
{ |
|
322 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
323 |
LONG rv; |
|
324 |
||
325 |
rv = CALL_SCardDisconnect(card, jDisposition); |
|
326 |
dprintf1("-disconnect: 0x%X\n", rv); |
|
327 |
handleRV(env, rv); |
|
328 |
return; |
|
329 |
} |
|
330 |
||
331 |
JNIEXPORT jintArray JNICALL Java_sun_security_smartcardio_PCSC_SCardGetStatusChange |
|
332 |
(JNIEnv *env, jclass thisClass, jlong jContext, jlong jTimeout, |
|
333 |
jintArray jCurrentState, jobjectArray jReaderNames) |
|
334 |
{ |
|
335 |
SCARDCONTEXT context = (SCARDCONTEXT)jContext; |
|
336 |
LONG rv; |
|
337 |
int readers = (*env)->GetArrayLength(env, jReaderNames); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
338 |
SCARD_READERSTATE *readerState; |
2 | 339 |
int i; |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
340 |
jintArray jEventState = NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
341 |
int *currentState = NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
342 |
const char *readerName; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
343 |
|
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
344 |
readerState = calloc(readers, sizeof(SCARD_READERSTATE)); |
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
345 |
if (readerState == NULL && readers > 0) { |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
346 |
throwOutOfMemoryError(env, NULL); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
347 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
348 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
349 |
|
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
350 |
currentState = (*env)->GetIntArrayElements(env, jCurrentState, NULL); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
351 |
if (currentState == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
352 |
free(readerState); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
353 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
354 |
} |
2 | 355 |
|
356 |
for (i = 0; i < readers; i++) { |
|
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
357 |
readerState[i].szReader = NULL; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
358 |
} |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
359 |
|
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
360 |
for (i = 0; i < readers; i++) { |
2 | 361 |
jobject jReaderName = (*env)->GetObjectArrayElement(env, jReaderNames, i); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
362 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
363 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
364 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
365 |
readerName = (*env)->GetStringUTFChars(env, jReaderName, NULL); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
366 |
if (readerName == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
367 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
368 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
369 |
readerState[i].szReader = strdup(readerName); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
370 |
(*env)->ReleaseStringUTFChars(env, jReaderName, readerName); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
371 |
if (readerState[i].szReader == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
372 |
throwOutOfMemoryError(env, NULL); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
373 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
374 |
} |
2 | 375 |
readerState[i].pvUserData = NULL; |
376 |
readerState[i].dwCurrentState = currentState[i]; |
|
377 |
readerState[i].dwEventState = SCARD_STATE_UNAWARE; |
|
378 |
readerState[i].cbAtr = 0; |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
379 |
(*env)->DeleteLocalRef(env, jReaderName); |
2 | 380 |
} |
381 |
||
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
382 |
if (readers > 0) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
383 |
rv = CALL_SCardGetStatusChange(context, (DWORD)jTimeout, readerState, readers); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
384 |
if (handleRV(env, rv)) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
385 |
goto cleanup; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
386 |
} |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
387 |
} |
2 | 388 |
|
389 |
jEventState = (*env)->NewIntArray(env, readers); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
390 |
if (jEventState == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
391 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
392 |
} |
2 | 393 |
for (i = 0; i < readers; i++) { |
394 |
jint eventStateTmp; |
|
395 |
dprintf3("-reader status %s: 0x%X, 0x%X\n", readerState[i].szReader, |
|
396 |
readerState[i].dwCurrentState, readerState[i].dwEventState); |
|
397 |
eventStateTmp = (jint)readerState[i].dwEventState; |
|
398 |
(*env)->SetIntArrayRegion(env, jEventState, i, 1, &eventStateTmp); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
399 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
400 |
jEventState = NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
401 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
402 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
403 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
404 |
cleanup: |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
405 |
(*env)->ReleaseIntArrayElements(env, jCurrentState, currentState, JNI_ABORT); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
406 |
for (i = 0; i < readers; i++) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
407 |
free((char *)readerState[i].szReader); |
2 | 408 |
} |
409 |
free(readerState); |
|
410 |
return jEventState; |
|
411 |
} |
|
412 |
||
413 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardBeginTransaction |
|
414 |
(JNIEnv *env, jclass thisClass, jlong jCard) |
|
415 |
{ |
|
416 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
417 |
LONG rv; |
|
418 |
||
419 |
rv = CALL_SCardBeginTransaction(card); |
|
420 |
dprintf1("-beginTransaction: 0x%X\n", rv); |
|
421 |
handleRV(env, rv); |
|
422 |
return; |
|
423 |
} |
|
424 |
||
425 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardEndTransaction |
|
426 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jDisposition) |
|
427 |
{ |
|
428 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
429 |
LONG rv; |
|
430 |
||
431 |
rv = CALL_SCardEndTransaction(card, jDisposition); |
|
432 |
dprintf1("-endTransaction: 0x%X\n", rv); |
|
433 |
handleRV(env, rv); |
|
434 |
return; |
|
435 |
} |
|
436 |
||
437 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardControl |
|
438 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jControlCode, jbyteArray jSendBuffer) |
|
439 |
{ |
|
440 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
441 |
LONG rv; |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
442 |
jbyte* sendBuffer; |
2 | 443 |
jint sendBufferLength = (*env)->GetArrayLength(env, jSendBuffer); |
444 |
jbyte receiveBuffer[MAX_STACK_BUFFER_SIZE]; |
|
445 |
jint receiveBufferLength = MAX_STACK_BUFFER_SIZE; |
|
446 |
ULONG returnedLength = 0; |
|
447 |
jbyteArray jReceiveBuffer; |
|
448 |
||
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
449 |
sendBuffer = (*env)->GetByteArrayElements(env, jSendBuffer, NULL); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
450 |
if (sendBuffer == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
451 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
452 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
453 |
|
2 | 454 |
#ifdef J2PCSC_DEBUG |
455 |
{ |
|
456 |
int k; |
|
457 |
printf("-control: 0x%X\n", jControlCode); |
|
458 |
printf("-send: "); |
|
459 |
for (k = 0; k < sendBufferLength; k++) { |
|
460 |
printf("%02x ", sendBuffer[k]); |
|
461 |
} |
|
462 |
printf("\n"); |
|
463 |
} |
|
464 |
#endif |
|
465 |
||
466 |
rv = CALL_SCardControl(card, jControlCode, sendBuffer, sendBufferLength, |
|
467 |
receiveBuffer, receiveBufferLength, &returnedLength); |
|
468 |
||
469 |
(*env)->ReleaseByteArrayElements(env, jSendBuffer, sendBuffer, JNI_ABORT); |
|
470 |
if (handleRV(env, rv)) { |
|
471 |
return NULL; |
|
472 |
} |
|
473 |
||
474 |
#ifdef J2PCSC_DEBUG |
|
475 |
{ |
|
476 |
int k; |
|
477 |
printf("-recv: "); |
|
478 |
for (k = 0; k < returnedLength; k++) { |
|
479 |
printf("%02x ", receiveBuffer[k]); |
|
480 |
} |
|
481 |
printf("\n"); |
|
482 |
} |
|
483 |
#endif |
|
484 |
||
485 |
jReceiveBuffer = (*env)->NewByteArray(env, returnedLength); |
|
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
486 |
if (jReceiveBuffer == NULL) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
487 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
488 |
} |
2 | 489 |
(*env)->SetByteArrayRegion(env, jReceiveBuffer, 0, returnedLength, receiveBuffer); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
490 |
if ((*env)->ExceptionCheck(env)) { |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
491 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
492 |
} |
2 | 493 |
return jReceiveBuffer; |
494 |
} |