Lines Matching defs:ccid
82 static void push_apdu(smartcard_ccid_t *ccid, void *data, int len)
92 pthread_mutex_lock(&ccid->apdu_lock);
93 for (p = &ccid->apdu_list; *p; p = &(*p)->next)
97 pthread_mutex_unlock(&ccid->apdu_lock);
100 static apdu_t * pop_apdu(smartcard_ccid_t *ccid)
103 pthread_mutex_lock(&ccid->apdu_lock);
104 p = ccid->apdu_list;
105 if (ccid->apdu_list)
106 ccid->apdu_list = p->next;
107 pthread_mutex_unlock(&ccid->apdu_lock);
117 static void send_reply(smartcard_ccid_t *ccid, uint32_t code)
122 reply[1] = htonl(ccid->lun); // reader id
126 if (write(ccid->fd, (char *) reply, sizeof(reply)) != sizeof(reply)) {
127 fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
128 IFDHCloseChannel(ccid->lun);
132 static int send_tx_buffer(smartcard_ccid_t *ccid, void *data, int len)
141 *p++ = htonl(ccid->lun); // reader id
145 if (write(ccid->fd, (char *) reply, write_len) != write_len) {
146 fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
147 IFDHCloseChannel(ccid->lun);
155 static void process_reader_add(smartcard_ccid_t *ccid, VSCMsgHeader *h, char *data)
157 if (ccid->state & STATE_READER_ADDED) {
158 send_reply(ccid, VSC_GENERAL_ERROR);
162 ccid->state |= STATE_READER_ADDED;
163 ccid->state &= ~STATE_READER_REMOVED;
165 pthread_mutex_init(&ccid->apdu_lock, NULL);
166 ccid->apdu_list = NULL;
168 send_reply(ccid, VSC_SUCCESS);
171 static void process_reader_remove(smartcard_ccid_t *ccid, VSCMsgHeader *h)
175 if (ccid->state & STATE_READER_REMOVED) {
176 send_reply(ccid, VSC_GENERAL_ERROR);
180 ccid->state |= STATE_READER_REMOVED;
181 ccid->state &= ~STATE_READER_ADDED;
183 while (p = pop_apdu(ccid))
186 pthread_mutex_destroy(&ccid->apdu_lock);
188 send_reply(ccid, VSC_SUCCESS);
191 static void process_atr(smartcard_ccid_t *ccid, VSCMsgHeader *h, char *data)
193 ccid->atr_len = h->length;
194 if (h->length > sizeof(ccid->atr)) {
196 h->length, sizeof(ccid->atr));
197 send_reply(ccid, VSC_GENERAL_ERROR);
201 memset(ccid->atr, 0, sizeof(ccid->atr));
202 memcpy(ccid->atr, data, ccid->atr_len);
204 send_reply(ccid, VSC_SUCCESS);
207 static void process_apdu(smartcard_ccid_t *ccid, VSCMsgHeader *h, char *data)
209 if (ccid->state & STATE_READER_ADDED)
210 push_apdu(ccid, data, h->length);
215 static void process_card_remove(smartcard_ccid_t *ccid, VSCMsgHeader *h)
217 ccid->atr_len = 0;
218 memset(ccid->atr, 0, sizeof(ccid->atr));
219 send_reply(ccid, VSC_SUCCESS);
222 static int process_message(smartcard_ccid_t *ccid, char *buf, int len)
236 process_reader_add(ccid, &h, h.length > 0 ? buf + sizeof(h) : NULL);
240 process_reader_remove(ccid, &h);
244 process_atr(ccid, &h, h.length > 0 ? buf + sizeof(h) : NULL);
248 process_card_remove(ccid, &h);
252 process_apdu(ccid, &h, h.length > 0 ? buf + sizeof(h) : NULL);
267 smartcard_ccid_t *ccid = (smartcard_ccid_t *) arg;
271 rc = read(ccid->fd, buf + pos, sizeof(buf) - pos);
284 rc = process_message(ccid, buf, pos);
292 fprintf(stderr, "LUN %d thread exiting: %s\n", ccid->lun,
294 close(ccid->fd);
295 ccid->fd = -1;
296 ccid->lun = 0;
297 ccid->atr_len = 0;
298 ccid->state &= ~STATE_OPEN;
304 static void send_init(smartcard_ccid_t *ccid)
309 msg[1] = htonl(ccid->lun); // reader id
315 if (write(ccid->fd, (char *) msg, sizeof(msg)) != sizeof(msg)) {
316 fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
317 IFDHCloseChannel(ccid->lun);