92 {
93 unsigned long active_protocol;
94 char reader_buf[2048];
95 size_t num_readers = sizeof(reader_buf);
97 char *reader_ptr;
98
101 }
102
105 if (
state->verbose) {
107 }
108
110 }
111
112 for (reader_ptr = reader_buf; *reader_ptr != '\0';
113 reader_ptr += strlen(reader_ptr) + 1) {
114 if (wanted) {
115 if (!strstr(reader_ptr, wanted)) {
116 if (
state->verbose) {
117 fprintf(stderr, "skipping reader '%s' since it doesn't match '%s'\n",
118 reader_ptr, wanted);
119 }
120 continue;
121 }
122 }
123
124 if (
state->verbose) {
125 fprintf(stderr, "trying to connect to reader '%s'\n", reader_ptr);
126 }
127
129 SCardConnect(
state->
context, reader_ptr, SCARD_SHARE_SHARED,
130 SCARD_PROTOCOL_T1, &
state->card, (LPDWORD) &active_protocol);
131
132 if (
rc != SCARD_S_SUCCESS) {
133 if (
state->verbose) {
134 fprintf(stderr,
"SCardConnect failed, rc=%08lx\n",
rc);
135 }
136 continue;
137 }
138
140 unsigned char data[0xff];
141 unsigned long recv_len = sizeof(data);
142 int sw;
144
148 apdu.
st.lc =
sizeof(
aid);
150
151 if ((res = send_data(
state, &apdu, data, &recv_len, &sw)) !=
153 if (
state->verbose) {
154 fprintf(stderr, "Failed communicating with card: '%s'\n",
156 }
157
158 continue;
161 } else {
162 if (
state->verbose) {
163 fprintf(stderr, "Failed selecting application: %04x\n", sw);
164 }
165 }
166 }
167
168 if (*reader_ptr == '\0') {
169 if (
state->verbose) {
170 fprintf(stderr, "error: no usable reader found\n");
171 }
175 }
176
178}
const char * ykyh_strerror(ykyh_rc err)
unsigned const char aid[]
ykyh_rc ykyh_list_readers(ykyh_state *state, char *readers, size_t *len)