author | weijun |
Fri, 20 May 2016 11:20:49 +0800 | |
changeset 38439 | 8a3871cd7fca |
parent 33653 | c1ee09fe3274 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, 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 |
||
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
195 |
if (size) { |
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); |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
208 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
209 |
|
24630
256eb760e01f
8044342: build failure on Windows noticed with recent smartcardio fix
igerasim
parents:
24627
diff
changeset
|
210 |
result = pcsc_multi2jstring(env, mszReaders); |
2 | 211 |
free(mszReaders); |
212 |
return result; |
|
213 |
} |
|
214 |
||
215 |
JNIEXPORT jlong JNICALL Java_sun_security_smartcardio_PCSC_SCardConnect |
|
216 |
(JNIEnv *env, jclass thisClass, jlong jContext, jstring jReaderName, |
|
217 |
jint jShareMode, jint jPreferredProtocols) |
|
218 |
{ |
|
219 |
SCARDCONTEXT context = (SCARDCONTEXT)jContext; |
|
220 |
LONG rv; |
|
221 |
LPCTSTR readerName; |
|
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
222 |
SCARDHANDLE card = 0; |
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
223 |
DWORD proto = 0; |
2 | 224 |
|
225 |
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
|
226 |
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
|
227 |
return 0; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
228 |
} |
2 | 229 |
rv = CALL_SCardConnect(context, readerName, jShareMode, jPreferredProtocols, &card, &proto); |
230 |
(*env)->ReleaseStringUTFChars(env, jReaderName, readerName); |
|
231 |
dprintf1("-cardhandle: %x\n", card); |
|
232 |
dprintf1("-protocol: %d\n", proto); |
|
233 |
if (handleRV(env, rv)) { |
|
234 |
return 0; |
|
235 |
} |
|
236 |
||
237 |
return (jlong)card; |
|
238 |
} |
|
239 |
||
240 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardTransmit |
|
241 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint protocol, |
|
242 |
jbyteArray jBuf, jint jOfs, jint jLen) |
|
243 |
{ |
|
244 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
245 |
LONG rv; |
|
246 |
SCARD_IO_REQUEST sendPci; |
|
247 |
unsigned char *sbuf; |
|
248 |
unsigned char rbuf[RECEIVE_BUFFER_SIZE]; |
|
249 |
DWORD rlen = RECEIVE_BUFFER_SIZE; |
|
250 |
int ofs = (int)jOfs; |
|
251 |
int len = (int)jLen; |
|
252 |
jbyteArray jOut; |
|
253 |
||
254 |
sendPci.dwProtocol = protocol; |
|
255 |
sendPci.cbPciLength = sizeof(SCARD_IO_REQUEST); |
|
256 |
||
257 |
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
|
258 |
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
|
259 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
260 |
} |
2 | 261 |
rv = CALL_SCardTransmit(card, &sendPci, sbuf + ofs, len, NULL, rbuf, &rlen); |
262 |
(*env)->ReleaseByteArrayElements(env, jBuf, (jbyte *)sbuf, JNI_ABORT); |
|
263 |
||
264 |
if (handleRV(env, rv)) { |
|
265 |
return NULL; |
|
266 |
} |
|
267 |
||
268 |
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
|
269 |
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
|
270 |
(*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
|
271 |
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
|
272 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
273 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
274 |
} |
2 | 275 |
return jOut; |
276 |
} |
|
277 |
||
278 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardStatus |
|
279 |
(JNIEnv *env, jclass thisClass, jlong jCard, jbyteArray jStatus) |
|
280 |
{ |
|
281 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
282 |
LONG rv; |
|
283 |
char readerName[READERNAME_BUFFER_SIZE]; |
|
284 |
DWORD readerLen = READERNAME_BUFFER_SIZE; |
|
285 |
unsigned char atr[ATR_BUFFER_SIZE]; |
|
286 |
DWORD atrLen = ATR_BUFFER_SIZE; |
|
24516
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
287 |
DWORD state = 0; |
9e5ba0f3ce68
8043507: javax.smartcardio.CardTerminals.list() fails on MacOSX
igerasim
parents:
23709
diff
changeset
|
288 |
DWORD protocol = 0; |
2 | 289 |
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
|
290 |
jbyte status[2]; |
2 | 291 |
|
292 |
rv = CALL_SCardStatus(card, readerName, &readerLen, &state, &protocol, atr, &atrLen); |
|
293 |
if (handleRV(env, rv)) { |
|
294 |
return NULL; |
|
295 |
} |
|
296 |
dprintf1("-reader: %s\n", readerName); |
|
297 |
dprintf1("-status: %d\n", state); |
|
298 |
dprintf1("-protocol: %d\n", protocol); |
|
299 |
||
300 |
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
|
301 |
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
|
302 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
303 |
} |
2 | 304 |
(*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
|
305 |
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
|
306 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
307 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
308 |
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
|
309 |
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
|
310 |
(*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
|
311 |
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
|
312 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
313 |
} |
2 | 314 |
return jArray; |
315 |
} |
|
316 |
||
317 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardDisconnect |
|
318 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jDisposition) |
|
319 |
{ |
|
320 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
321 |
LONG rv; |
|
322 |
||
323 |
rv = CALL_SCardDisconnect(card, jDisposition); |
|
324 |
dprintf1("-disconnect: 0x%X\n", rv); |
|
325 |
handleRV(env, rv); |
|
326 |
return; |
|
327 |
} |
|
328 |
||
329 |
JNIEXPORT jintArray JNICALL Java_sun_security_smartcardio_PCSC_SCardGetStatusChange |
|
330 |
(JNIEnv *env, jclass thisClass, jlong jContext, jlong jTimeout, |
|
331 |
jintArray jCurrentState, jobjectArray jReaderNames) |
|
332 |
{ |
|
333 |
SCARDCONTEXT context = (SCARDCONTEXT)jContext; |
|
334 |
LONG rv; |
|
335 |
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
|
336 |
SCARD_READERSTATE *readerState; |
2 | 337 |
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
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
|
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
342 |
readerState = calloc(readers, sizeof(SCARD_READERSTATE)); |
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
346 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
347 |
|
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
348 |
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
|
349 |
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
|
350 |
free(readerState); |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
351 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
352 |
} |
2 | 353 |
|
354 |
for (i = 0; i < readers; i++) { |
|
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
355 |
readerState[i].szReader = NULL; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
356 |
} |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
357 |
|
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
358 |
for (i = 0; i < readers; i++) { |
2 | 359 |
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
|
360 |
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
|
361 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
362 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
363 |
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
|
364 |
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
|
365 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
366 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
367 |
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
|
368 |
(*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
|
369 |
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
|
370 |
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
|
371 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
372 |
} |
2 | 373 |
readerState[i].pvUserData = NULL; |
374 |
readerState[i].dwCurrentState = currentState[i]; |
|
375 |
readerState[i].dwEventState = SCARD_STATE_UNAWARE; |
|
376 |
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
|
377 |
(*env)->DeleteLocalRef(env, jReaderName); |
2 | 378 |
} |
379 |
||
24627
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
380 |
if (readers > 0) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
381 |
rv = CALL_SCardGetStatusChange(context, (DWORD)jTimeout, readerState, readers); |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
382 |
if (handleRV(env, rv)) { |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
383 |
goto cleanup; |
c2e7947c579e
8043720: (smartcardio) Native memory should be handled more accurately
igerasim
parents:
24516
diff
changeset
|
384 |
} |
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
385 |
} |
2 | 386 |
|
387 |
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
|
388 |
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
|
389 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
390 |
} |
2 | 391 |
for (i = 0; i < readers; i++) { |
392 |
jint eventStateTmp; |
|
393 |
dprintf3("-reader status %s: 0x%X, 0x%X\n", readerState[i].szReader, |
|
394 |
readerState[i].dwCurrentState, readerState[i].dwEventState); |
|
395 |
eventStateTmp = (jint)readerState[i].dwEventState; |
|
396 |
(*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
|
397 |
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
|
398 |
jEventState = NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
399 |
goto cleanup; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
400 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
401 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
402 |
cleanup: |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
403 |
(*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
|
404 |
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
|
405 |
free((char *)readerState[i].szReader); |
2 | 406 |
} |
407 |
free(readerState); |
|
408 |
return jEventState; |
|
409 |
} |
|
410 |
||
411 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardBeginTransaction |
|
412 |
(JNIEnv *env, jclass thisClass, jlong jCard) |
|
413 |
{ |
|
414 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
415 |
LONG rv; |
|
416 |
||
417 |
rv = CALL_SCardBeginTransaction(card); |
|
418 |
dprintf1("-beginTransaction: 0x%X\n", rv); |
|
419 |
handleRV(env, rv); |
|
420 |
return; |
|
421 |
} |
|
422 |
||
423 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PCSC_SCardEndTransaction |
|
424 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jDisposition) |
|
425 |
{ |
|
426 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
427 |
LONG rv; |
|
428 |
||
429 |
rv = CALL_SCardEndTransaction(card, jDisposition); |
|
430 |
dprintf1("-endTransaction: 0x%X\n", rv); |
|
431 |
handleRV(env, rv); |
|
432 |
return; |
|
433 |
} |
|
434 |
||
435 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_smartcardio_PCSC_SCardControl |
|
436 |
(JNIEnv *env, jclass thisClass, jlong jCard, jint jControlCode, jbyteArray jSendBuffer) |
|
437 |
{ |
|
438 |
SCARDHANDLE card = (SCARDHANDLE)jCard; |
|
439 |
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
|
440 |
jbyte* sendBuffer; |
2 | 441 |
jint sendBufferLength = (*env)->GetArrayLength(env, jSendBuffer); |
442 |
jbyte receiveBuffer[MAX_STACK_BUFFER_SIZE]; |
|
443 |
jint receiveBufferLength = MAX_STACK_BUFFER_SIZE; |
|
444 |
ULONG returnedLength = 0; |
|
445 |
jbyteArray jReceiveBuffer; |
|
446 |
||
23704
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
447 |
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
|
448 |
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
|
449 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
450 |
} |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
451 |
|
2 | 452 |
#ifdef J2PCSC_DEBUG |
453 |
{ |
|
454 |
int k; |
|
455 |
printf("-control: 0x%X\n", jControlCode); |
|
456 |
printf("-send: "); |
|
457 |
for (k = 0; k < sendBufferLength; k++) { |
|
458 |
printf("%02x ", sendBuffer[k]); |
|
459 |
} |
|
460 |
printf("\n"); |
|
461 |
} |
|
462 |
#endif |
|
463 |
||
464 |
rv = CALL_SCardControl(card, jControlCode, sendBuffer, sendBufferLength, |
|
465 |
receiveBuffer, receiveBufferLength, &returnedLength); |
|
466 |
||
467 |
(*env)->ReleaseByteArrayElements(env, jSendBuffer, sendBuffer, JNI_ABORT); |
|
468 |
if (handleRV(env, rv)) { |
|
469 |
return NULL; |
|
470 |
} |
|
471 |
||
472 |
#ifdef J2PCSC_DEBUG |
|
473 |
{ |
|
474 |
int k; |
|
475 |
printf("-recv: "); |
|
476 |
for (k = 0; k < returnedLength; k++) { |
|
477 |
printf("%02x ", receiveBuffer[k]); |
|
478 |
} |
|
479 |
printf("\n"); |
|
480 |
} |
|
481 |
#endif |
|
482 |
||
483 |
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
|
484 |
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
|
485 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
486 |
} |
2 | 487 |
(*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
|
488 |
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
|
489 |
return NULL; |
c174349fcd4b
8030114: [parfait] warnings from b119 for jdk.src.share.native.sun.security.smartcardio: JNI exception pending
valeriep
parents:
5506
diff
changeset
|
490 |
} |
2 | 491 |
return jReceiveBuffer; |
492 |
} |