CK_RV card_detect_all(void) { unsigned int i; sc_log(context, "Detect all cards"); /* Detect cards in all initialized readers */ for (i=0; i< sc_ctx_get_reader_count(context); i++) { sc_reader_t *reader = sc_ctx_get_reader(context, i); if (reader->flags & SC_READER_REMOVED) { struct sc_pkcs11_slot *slot; card_removed(reader); while ((slot = reader_get_slot(reader))) { empty_slot(slot); } _sc_delete_reader(context, reader); i--; } else { if (!reader_get_slot(reader)) initialize_reader(reader); else card_detect(sc_ctx_get_reader(context, i)); } } sc_log(context, "All cards detected"); return CKR_OK; }
static inline int t1_setleds(struct t1 *wc, int leds, int inisr) { unsigned long flags; int hit; int ret = 0; leds = ~leds & 0x0E; /* invert the LED bits (3 downto 1)*/ do { if (!inisr) { spin_lock_irqsave(&wc->reglock, flags); } hit = empty_slot(wc); if (hit > -1) { wc->cmdq.cmds[hit].flags |= __CMD_LEDS; wc->cmdq.cmds[hit].address = leds; } if (inisr) { break; } else { spin_unlock_irqrestore(&wc->reglock, flags); } if (hit < 0) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit < 0); return (hit > -1) ? 0 : -1; }
static inline int t1_setreg_full(struct t1 *wc, int addr, int val, int inisr, int vpm_num) { unsigned long flags; int hit; int ret; do { if (!inisr) spin_lock_irqsave(&wc->reglock, flags); hit = empty_slot(wc); if (hit > -1) { wc->cmdq.cmds[hit].address = addr; wc->cmdq.cmds[hit].data = val; wc->cmdq.cmds[hit].flags |= __CMD_WR; if(vpm_num >= 0) { wc->cmdq.cmds[hit].flags |= __CMD_VPM; wc->cmdq.cmds[hit].vpm_num = vpm_num; } } if (inisr) break; spin_unlock_irqrestore(&wc->reglock, flags); if (hit < 0) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit < 0); return (hit > -1) ? 0 : -1; }
static inline int t1_getreg_full(struct t1 *wc, int addr, int inisr, int vpm_num) { unsigned long flags; int hit; int ret = 0; do { if (!inisr) { spin_lock_irqsave(&wc->reglock, flags); } hit = empty_slot(wc); if (hit > -1) { wc->cmdq.cmds[hit].address = addr; wc->cmdq.cmds[hit].data = 0x00; wc->cmdq.cmds[hit].flags |= __CMD_RD; if(vpm_num >= 0) { wc->cmdq.cmds[hit].flags |= __CMD_VPM; wc->cmdq.cmds[hit].vpm_num = vpm_num; } if (inisr) wc->cmdq.cmds[hit].flags |= __CMD_ISR; } if (inisr) /* must be requested in t1_getreg_isr() */ return (hit > -1) ? 0 : -1; else { spin_unlock_irqrestore(&wc->reglock, flags); } if (hit < 0) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit < 0); do { spin_lock_irqsave(&wc->reglock, flags); if (wc->cmdq.cmds[hit].flags & __CMD_FIN) { ret = wc->cmdq.cmds[hit].data; memset(&wc->cmdq.cmds[hit], 0, sizeof(wc->cmdq.cmds[hit])); hit = -1; } spin_unlock_irqrestore(&wc->reglock, flags); if (hit > -1) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit > -1); return ret; }
static inline int t1_getpins(struct t1 *wc, int inisr) { unsigned long flags; int hit; int ret = 0; do { spin_lock_irqsave(&wc->reglock, flags); hit = empty_slot(wc); if (hit > -1) { wc->cmdq.cmds[hit].address = 0x00; wc->cmdq.cmds[hit].data = 0x00; wc->cmdq.cmds[hit].flags |= __CMD_PINS; } spin_unlock_irqrestore(&wc->reglock, flags); if (inisr) return (hit > -1) ? 0 : -1; if (hit < 0) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit < 0); do { spin_lock_irqsave(&wc->reglock, flags); if (wc->cmdq.cmds[hit].flags & __CMD_FIN) { ret = wc->cmdq.cmds[hit].data; memset(&wc->cmdq.cmds[hit], 0, sizeof(wc->cmdq.cmds[hit])); hit = -1; } spin_unlock_irqrestore(&wc->reglock, flags); if (hit > -1) { if ((ret = schluffen(&wc->regq))) return ret; } } while (hit > -1); return ret; }