[3181] | 1 | //FIXME Not checked on threadsafety yet; after checking please remove this line
|
---|
[8] | 2 | #include "globals.h"
|
---|
| 3 | #include "reader-common.h"
|
---|
[1389] | 4 | #include "defines.h"
|
---|
| 5 | #include "atr.h"
|
---|
[1926] | 6 | #include "icc_async_exports.h"
|
---|
[1960] | 7 | #include "csctapi/ifd_sc8in1.h"
|
---|
[2905] | 8 | #ifdef HAVE_PCSC
|
---|
| 9 | #include "csctapi/ifd_pcsc.h"
|
---|
| 10 | #endif
|
---|
[2927] | 11 | #ifdef AZBOX
|
---|
| 12 | #include "csctapi/ifd_azbox.h"
|
---|
| 13 | #endif
|
---|
[1951] | 14 |
|
---|
[2172] | 15 | #if defined(TUXBOX) && defined(PPC) //dbox2 only
|
---|
| 16 | #include "csctapi/mc_global.h"
|
---|
[1926] | 17 | static int reader_device_type(struct s_reader * reader)
|
---|
[8] | 18 | {
|
---|
[1926] | 19 | int rc=reader->typ;
|
---|
[8] | 20 | struct stat sb;
|
---|
[1926] | 21 | if (reader->typ == R_MOUSE)
|
---|
[8] | 22 | {
|
---|
[1926] | 23 | if (!stat(reader->device, &sb))
|
---|
[8] | 24 | {
|
---|
| 25 | if (S_ISCHR(sb.st_mode))
|
---|
| 26 | {
|
---|
| 27 | int dev_major, dev_minor;
|
---|
| 28 | dev_major=major(sb.st_rdev);
|
---|
| 29 | dev_minor=minor(sb.st_rdev);
|
---|
[2126] | 30 | if (((dev_major==4) || (dev_major==5)))
|
---|
[8] | 31 | switch(dev_minor & 0x3F)
|
---|
| 32 | {
|
---|
[1208] | 33 | case 0: rc=R_DB2COM1; break;
|
---|
| 34 | case 1: rc=R_DB2COM2; break;
|
---|
[8] | 35 | }
|
---|
| 36 | cs_debug("device is major: %d, minor: %d, typ=%d", dev_major, dev_minor, rc);
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
[1926] | 40 | reader->typ = rc;
|
---|
[8] | 41 | return(rc);
|
---|
| 42 | }
|
---|
[1208] | 43 | #endif
|
---|
[8] | 44 |
|
---|
[1926] | 45 | static void reader_nullcard(struct s_reader * reader)
|
---|
[8] | 46 | {
|
---|
[1926] | 47 | reader->card_system=0;
|
---|
| 48 | memset(reader->hexserial, 0 , sizeof(reader->hexserial));
|
---|
| 49 | memset(reader->prid , 0xFF, sizeof(reader->prid ));
|
---|
| 50 | memset(reader->caid , 0 , sizeof(reader->caid ));
|
---|
| 51 | memset(reader->availkeys, 0 , sizeof(reader->availkeys));
|
---|
| 52 | reader->acs=0;
|
---|
| 53 | reader->nprov=0;
|
---|
[8] | 54 | }
|
---|
| 55 |
|
---|
[3161] | 56 | int reader_cmd2icc(struct s_reader * reader, const uchar *buf, const int l, uchar * cta_res, ushort * p_cta_lr)
|
---|
[8] | 57 | {
|
---|
[1381] | 58 | int rc;
|
---|
| 59 | #ifdef HAVE_PCSC
|
---|
[1953] | 60 | if (reader->typ == R_PCSC) {
|
---|
[1951] | 61 | return (pcsc_reader_do_api(reader, buf, cta_res, p_cta_lr,l));
|
---|
[1381] | 62 | }
|
---|
| 63 |
|
---|
| 64 | #endif
|
---|
| 65 |
|
---|
[1951] | 66 | *p_cta_lr=CTA_RES_LEN-1; //FIXME not sure whether this one is necessary
|
---|
[3153] | 67 | int cs_ptyp_orig=client[cs_idx].cs_ptyp;
|
---|
| 68 | client[cs_idx].cs_ptyp=D_DEVICE;
|
---|
[1926] | 69 | if (reader->typ == R_SC8in1) {
|
---|
| 70 | pthread_mutex_lock(&sc8in1);
|
---|
| 71 | cs_debug("SC8in1: locked for CardWrite of slot %i", reader->slot);
|
---|
[1960] | 72 | Sc8in1_Selectslot(reader, reader->slot);
|
---|
[1926] | 73 | }
|
---|
[2069] | 74 | cs_ddump(buf, l, "write to cardreader %s:",reader->label);
|
---|
[1951] | 75 | rc=ICC_Async_CardWrite(reader, buf, (unsigned short)l, cta_res, p_cta_lr);
|
---|
[2069] | 76 | cs_ddump(cta_res, *p_cta_lr, "answer from cardreader %s:", reader->label);
|
---|
[1926] | 77 | if (reader->typ == R_SC8in1) {
|
---|
| 78 | cs_debug("SC8in1: unlocked for CardWrite of slot %i", reader->slot);
|
---|
| 79 | pthread_mutex_unlock(&sc8in1);
|
---|
| 80 | }
|
---|
[3153] | 81 | client[cs_idx].cs_ptyp=cs_ptyp_orig;
|
---|
[1381] | 82 | return rc;
|
---|
[8] | 83 | }
|
---|
| 84 |
|
---|
[473] | 85 | #define CMD_LEN 5
|
---|
| 86 |
|
---|
[2905] | 87 | int card_write(struct s_reader * reader, const uchar *cmd, const uchar *data, uchar *response, ushort * response_length)
|
---|
[473] | 88 | {
|
---|
[2905] | 89 | uchar buf[260];
|
---|
| 90 | // always copy to be able to be able to use const buffer without changing all code
|
---|
| 91 | memcpy(buf, cmd, CMD_LEN);
|
---|
| 92 |
|
---|
[473] | 93 | if (data) {
|
---|
| 94 | if (cmd[4]) memcpy(buf+CMD_LEN, data, cmd[4]);
|
---|
[1951] | 95 | return(reader_cmd2icc(reader, buf, CMD_LEN+cmd[4], response, response_length));
|
---|
[473] | 96 | }
|
---|
| 97 | else
|
---|
[2905] | 98 | return(reader_cmd2icc(reader, buf, CMD_LEN, response, response_length));
|
---|
[473] | 99 | }
|
---|
| 100 |
|
---|
[2662] | 101 | int check_sct_len(const uchar *data, int off)
|
---|
| 102 | {
|
---|
| 103 | int l = SCT_LEN(data);
|
---|
| 104 | if (l+off > MAX_LEN) {
|
---|
| 105 | cs_debug("check_sct_len(): smartcard section too long %d > %d", l, MAX_LEN-off);
|
---|
| 106 | l = -1;
|
---|
| 107 | }
|
---|
| 108 | return(l);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
[1926] | 112 | static int reader_card_inserted(struct s_reader * reader)
|
---|
[8] | 113 | {
|
---|
[2656] | 114 | #ifndef USE_GPIO
|
---|
[2213] | 115 | if ((reader->detect&0x7f) > 3)
|
---|
[2212] | 116 | return 1;
|
---|
[2656] | 117 | #endif
|
---|
[1389] | 118 | #ifdef HAVE_PCSC
|
---|
[1926] | 119 | if (reader->typ == R_PCSC) {
|
---|
| 120 | return(pcsc_check_card_inserted(reader));
|
---|
[1389] | 121 | }
|
---|
| 122 | #endif
|
---|
| 123 | int card;
|
---|
[3153] | 124 | int cs_ptyp_orig=client[cs_idx].cs_ptyp;
|
---|
| 125 | client[cs_idx].cs_ptyp=D_IFD;
|
---|
[1926] | 126 | if (ICC_Async_GetStatus (reader, &card)) {
|
---|
[1389] | 127 | cs_log("Error getting status of terminal.");
|
---|
| 128 | return 0; //corresponds with no card inside!!
|
---|
| 129 | }
|
---|
[3153] | 130 | client[cs_idx].cs_ptyp=cs_ptyp_orig;
|
---|
[1389] | 131 | return (card);
|
---|
| 132 | }
|
---|
[1928] | 133 |
|
---|
[1926] | 134 | static int reader_activate_card(struct s_reader * reader, ATR * atr, unsigned short deprecated)
|
---|
[1389] | 135 | {
|
---|
| 136 | int i;
|
---|
[776] | 137 | #ifdef HAVE_PCSC
|
---|
[1389] | 138 | unsigned char atrarr[64];
|
---|
| 139 | ushort atr_size = 0;
|
---|
[1926] | 140 | if (reader->typ == R_PCSC) {
|
---|
| 141 | if (pcsc_activate_card(reader, atrarr, &atr_size))
|
---|
[1389] | 142 | return (ATR_InitFromArray (atr, atrarr, atr_size) == ATR_OK);
|
---|
| 143 | else
|
---|
| 144 | return 0;
|
---|
| 145 | }
|
---|
[776] | 146 | #endif
|
---|
[1926] | 147 | if (!reader_card_inserted(reader))
|
---|
[1389] | 148 | return 0;
|
---|
[776] | 149 |
|
---|
[8] | 150 | /* Activate card */
|
---|
[3153] | 151 | int cs_ptyp_orig=client[cs_idx].cs_ptyp;
|
---|
| 152 | client[cs_idx].cs_ptyp=D_DEVICE;
|
---|
[1926] | 153 | if (reader->typ == R_SC8in1) {
|
---|
| 154 | pthread_mutex_lock(&sc8in1);
|
---|
| 155 | cs_debug_mask(D_ATR, "SC8in1: locked for Activation of slot %i", reader->slot);
|
---|
[1960] | 156 | Sc8in1_Selectslot(reader, reader->slot);
|
---|
[1926] | 157 | }
|
---|
[1389] | 158 | for (i=0; i<5; i++) {
|
---|
[1926] | 159 | if (!ICC_Async_Activate(reader, atr, deprecated)) {
|
---|
[1389] | 160 | i = 100;
|
---|
| 161 | break;
|
---|
| 162 | }
|
---|
| 163 | cs_log("Error activating card.");
|
---|
| 164 | cs_sleepms(500);
|
---|
| 165 | }
|
---|
[1926] | 166 | if (reader->typ == R_SC8in1) {
|
---|
| 167 | cs_debug_mask(D_ATR, "SC8in1: unlocked for Activation of slot %i", reader->slot);
|
---|
| 168 | pthread_mutex_unlock(&sc8in1);
|
---|
| 169 | }
|
---|
[3153] | 170 | client[cs_idx].cs_ptyp=cs_ptyp_orig;
|
---|
[8] | 171 | if (i<100) return(0);
|
---|
| 172 |
|
---|
[2105] | 173 | reader->init_history_pos=0;
|
---|
[8] | 174 | #ifdef CS_RDR_INIT_HIST
|
---|
[1926] | 175 | memset(reader->init_history, 0, sizeof(reader->init_history));
|
---|
[8] | 176 | #endif
|
---|
[1389] | 177 | // cs_ri_log("ATR: %s", cs_hexdump(1, atr, atr_size));//FIXME
|
---|
[1584] | 178 | cs_sleepms(1000);
|
---|
[8] | 179 | return(1);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[1926] | 182 | void do_emm_from_file(struct s_reader * reader)
|
---|
[452] | 183 | {
|
---|
| 184 | //now here check whether we have EMM's on file to load and write to card:
|
---|
[1926] | 185 | if (reader->emmfile != NULL) {//readnano has something filled in
|
---|
[452] | 186 |
|
---|
| 187 | //handling emmfile
|
---|
| 188 | char token[256];
|
---|
| 189 | FILE *fp;
|
---|
[460] | 190 | size_t result;
|
---|
[1926] | 191 | if ((reader->emmfile[0] == '/'))
|
---|
| 192 | sprintf (token, "%s", reader->emmfile); //pathname included
|
---|
[452] | 193 | else
|
---|
[1926] | 194 | sprintf (token, "%s%s", cs_confdir, reader->emmfile); //only file specified, look in confdir for this file
|
---|
[452] | 195 |
|
---|
| 196 | if (!(fp = fopen (token, "rb")))
|
---|
| 197 | cs_log ("ERROR: Cannot open EMM file '%s' (errno=%d)\n", token, errno);
|
---|
| 198 | else {
|
---|
| 199 | EMM_PACKET *eptmp;
|
---|
| 200 | eptmp = malloc (sizeof(EMM_PACKET));
|
---|
[460] | 201 | result = fread (eptmp, sizeof(EMM_PACKET), 1, fp);
|
---|
[452] | 202 | fclose (fp);
|
---|
| 203 |
|
---|
[1926] | 204 | uchar old_b_nano = reader->b_nano[eptmp->emm[0]]; //save old b_nano value
|
---|
| 205 | reader->b_nano[eptmp->emm[0]] &= 0xfc; //clear lsb and lsb+1, so no blocking, and no saving for this nano
|
---|
[452] | 206 |
|
---|
| 207 | //if (!reader_do_emm (eptmp))
|
---|
[1926] | 208 | if (!reader_emm (reader, eptmp))
|
---|
[506] | 209 | cs_log ("ERROR: EMM read from file %s NOT processed correctly!", token);
|
---|
[452] | 210 |
|
---|
[1926] | 211 | reader->b_nano[eptmp->emm[0]] = old_b_nano; //restore old block/save settings
|
---|
| 212 | free (reader->emmfile);
|
---|
| 213 | reader->emmfile = NULL; //clear emmfile, so no reading anymore
|
---|
[452] | 214 |
|
---|
| 215 | free(eptmp);
|
---|
| 216 | eptmp = NULL;
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[2837] | 221 | void reader_card_info(struct s_reader * reader)
|
---|
[8] | 222 | {
|
---|
[2851] | 223 | if ((reader->card_status == CARD_NEED_INIT) || (reader->card_status == CARD_INSERTED))
|
---|
[8] | 224 | {
|
---|
| 225 | client[cs_idx].last=time((time_t)0);
|
---|
[1926] | 226 | cs_ri_brk(reader, 0);
|
---|
| 227 | do_emm_from_file(reader);
|
---|
[3168] | 228 |
|
---|
| 229 | if (cardsystem[reader->card_system-1].card_info) {
|
---|
| 230 | cardsystem[reader->card_system-1].card_info(reader);
|
---|
| 231 | }
|
---|
[8] | 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[1926] | 235 | static int reader_get_cardsystem(struct s_reader * reader, ATR atr)
|
---|
[8] | 236 | {
|
---|
[3168] | 237 | int i;
|
---|
| 238 | for (i=0; i<CS_MAX_MOD; i++) {
|
---|
| 239 | if (cardsystem[i].card_init) {
|
---|
| 240 | if (cardsystem[i].card_init(reader, atr)) {
|
---|
| 241 | reader->card_system=i+1;
|
---|
| 242 | cs_log("found cardsystem");
|
---|
| 243 | break;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
[452] | 247 |
|
---|
[3168] | 248 | if (reader->card_system==0)
|
---|
[2073] | 249 | cs_ri_log(reader, "card system not supported");
|
---|
| 250 |
|
---|
| 251 | cs_ri_brk(reader, 1);
|
---|
[3168] | 252 |
|
---|
[2073] | 253 | return(reader->card_system);
|
---|
[8] | 254 | }
|
---|
| 255 |
|
---|
[1926] | 256 | static int reader_reset(struct s_reader * reader)
|
---|
[8] | 257 | {
|
---|
[2927] | 258 | reader_nullcard(reader);
|
---|
| 259 | ATR atr;
|
---|
[2928] | 260 | unsigned short int ret = 0;
|
---|
[2927] | 261 | #ifdef AZBOX
|
---|
| 262 | int i;
|
---|
[2939] | 263 | if (reader->typ == R_INTERNAL) {
|
---|
| 264 | if (reader->mode != -1) {
|
---|
| 265 | Azbox_SetMode(reader->mode);
|
---|
[2928] | 266 | if (!reader_activate_card(reader, &atr, 0)) return(0);
|
---|
| 267 | ret = reader_get_cardsystem(reader, atr);
|
---|
[2939] | 268 | } else {
|
---|
| 269 | for (i = 0; i < AZBOX_MODES; i++) {
|
---|
| 270 | Azbox_SetMode(i);
|
---|
| 271 | if (!reader_activate_card(reader, &atr, 0)) return(0);
|
---|
| 272 | ret = reader_get_cardsystem(reader, atr);
|
---|
| 273 | if (ret)
|
---|
| 274 | break;
|
---|
| 275 | }
|
---|
[2928] | 276 | }
|
---|
[2939] | 277 | } else {
|
---|
| 278 | #endif
|
---|
[2927] | 279 | unsigned short int deprecated;
|
---|
[1926] | 280 | for (deprecated = reader->deprecated; deprecated < 2; deprecated++) {
|
---|
| 281 | if (!reader_activate_card(reader, &atr, deprecated)) return(0);
|
---|
[2927] | 282 | ret = reader_get_cardsystem(reader, atr);
|
---|
[1419] | 283 | if (ret)
|
---|
| 284 | break;
|
---|
| 285 | if (!deprecated)
|
---|
| 286 | cs_log("Normal mode failed, reverting to Deprecated Mode");
|
---|
| 287 | }
|
---|
[2939] | 288 | #ifdef AZBOX
|
---|
| 289 | }
|
---|
[2927] | 290 | #endif
|
---|
[1419] | 291 | return(ret);
|
---|
[8] | 292 | }
|
---|
| 293 |
|
---|
[1926] | 294 | int reader_device_init(struct s_reader * reader)
|
---|
[8] | 295 | {
|
---|
[776] | 296 | #ifdef HAVE_PCSC
|
---|
[1926] | 297 | if (reader->typ == R_PCSC) {
|
---|
| 298 | return (pcsc_reader_init(reader, reader->device));
|
---|
[776] | 299 | }
|
---|
| 300 | #endif
|
---|
| 301 |
|
---|
[2172] | 302 | int rc = -1; //FIXME
|
---|
[3153] | 303 | int cs_ptyp_orig=client[cs_idx].cs_ptyp;
|
---|
| 304 | client[cs_idx].cs_ptyp=D_DEVICE;
|
---|
[2172] | 305 | #if defined(TUXBOX) && defined(PPC)
|
---|
| 306 | struct stat st;
|
---|
| 307 | if (!stat(DEV_MULTICAM, &st))
|
---|
| 308 | reader->typ = reader_device_type(reader);
|
---|
[1394] | 309 | #endif
|
---|
[1926] | 310 | if (ICC_Async_Device_Init(reader))
|
---|
| 311 | cs_log("Cannot open device: %s", reader->device);
|
---|
[1389] | 312 | else
|
---|
| 313 | rc = OK;
|
---|
[1926] | 314 | cs_debug("ct_init on %s: %d", reader->device, rc);
|
---|
[3153] | 315 | client[cs_idx].cs_ptyp=cs_ptyp_orig;
|
---|
[8] | 316 | return((rc!=OK) ? 2 : 0);
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[1926] | 319 | int reader_checkhealth(struct s_reader * reader)
|
---|
[8] | 320 | {
|
---|
[1926] | 321 | if (reader_card_inserted(reader))
|
---|
[8] | 322 | {
|
---|
[1926] | 323 | if (reader->card_status == NO_CARD)
|
---|
[8] | 324 | {
|
---|
| 325 | cs_log("card detected");
|
---|
[2851] | 326 | reader->card_status = CARD_NEED_INIT;
|
---|
[2832] | 327 | if (!reader_reset(reader))
|
---|
[94] | 328 | {
|
---|
[2832] | 329 | reader->card_status = CARD_FAILURE;
|
---|
[8] | 330 | cs_log("card initializing error");
|
---|
[94] | 331 | }
|
---|
[8] | 332 | else
|
---|
| 333 | {
|
---|
[3153] | 334 | client[cs_idx].au = client[cs_idx].ridx;
|
---|
[2837] | 335 | reader_card_info(reader);
|
---|
[2834] | 336 | reader->card_status = CARD_INSERTED;
|
---|
[8] | 337 | }
|
---|
[19] | 338 |
|
---|
| 339 | int i;
|
---|
| 340 | for( i=1; i<CS_MAXPID; i++ ) {
|
---|
[2035] | 341 | if( client[i].pid && client[i].typ=='c' && client[i].usr[0] && ph[client[i].ctyp].type & MOD_CONN_NET) {
|
---|
[3153] | 342 | //kill(client[i].pid, SIGQUIT);
|
---|
[19] | 343 | }
|
---|
| 344 | }
|
---|
[8] | 345 | }
|
---|
| 346 | }
|
---|
| 347 | else
|
---|
| 348 | {
|
---|
[1926] | 349 | if (reader->card_status == CARD_INSERTED)
|
---|
[8] | 350 | {
|
---|
[1926] | 351 | reader_nullcard(reader);
|
---|
[2851] | 352 | client[cs_idx].lastemm = 0;
|
---|
| 353 | client[cs_idx].lastecm = 0;
|
---|
| 354 | client[cs_idx].au = -1;
|
---|
[14] | 355 | extern int io_serial_need_dummy_char;
|
---|
[2851] | 356 | io_serial_need_dummy_char = 0;
|
---|
[1926] | 357 | cs_log("card ejected slot = %i", reader->slot);
|
---|
[8] | 358 | }
|
---|
[2851] | 359 | reader->card_status = NO_CARD;
|
---|
[8] | 360 | }
|
---|
[2851] | 361 | return reader->card_status == CARD_INSERTED;
|
---|
[8] | 362 | }
|
---|
| 363 |
|
---|
[1926] | 364 | void reader_post_process(struct s_reader * reader)
|
---|
[800] | 365 | {
|
---|
| 366 | // some systems eg. nagra2/3 needs post process after receiving cw from card
|
---|
| 367 | // To save ECM/CW time we added this function after writing ecm answer
|
---|
[3168] | 368 |
|
---|
| 369 | if (cardsystem[reader->card_system-1].post_process) {
|
---|
| 370 | cardsystem[reader->card_system-1].post_process(reader);
|
---|
| 371 | }
|
---|
[800] | 372 | }
|
---|
| 373 |
|
---|
[1926] | 374 | int reader_ecm(struct s_reader * reader, ECM_REQUEST *er)
|
---|
[8] | 375 | {
|
---|
[2370] | 376 | int rc=-1;
|
---|
[1926] | 377 | if( (rc=reader_checkhealth(reader)) )
|
---|
[8] | 378 | {
|
---|
[2370] | 379 | if((reader->caid[0] >> 8) == ((er->caid >> 8) & 0xFF))
|
---|
[8] | 380 | {
|
---|
| 381 | client[cs_idx].last_srvid=er->srvid;
|
---|
| 382 | client[cs_idx].last_caid=er->caid;
|
---|
| 383 | client[cs_idx].last=time((time_t)0);
|
---|
[3168] | 384 |
|
---|
| 385 | if (cardsystem[reader->card_system-1].do_ecm)
|
---|
| 386 | rc=cardsystem[reader->card_system-1].do_ecm(reader, er);
|
---|
| 387 | else
|
---|
| 388 | rc=0;
|
---|
| 389 |
|
---|
[8] | 390 | }
|
---|
| 391 | else
|
---|
| 392 | rc=0;
|
---|
| 393 | }
|
---|
| 394 | return(rc);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[1926] | 397 | int reader_get_emm_type(EMM_PACKET *ep, struct s_reader * rdr) //rdr differs from calling reader!
|
---|
[1766] | 398 | {
|
---|
| 399 | cs_debug_mask(D_EMM,"Entered reader_get_emm_type cardsystem %i",rdr->card_system);
|
---|
| 400 | int rc;
|
---|
[3168] | 401 |
|
---|
| 402 | if (rdr->card_system<1)
|
---|
| 403 | return 0;
|
---|
| 404 |
|
---|
| 405 | if (cardsystem[rdr->card_system-1].get_emm_type)
|
---|
| 406 | rc=cardsystem[rdr->card_system-1].get_emm_type(ep, rdr);
|
---|
| 407 | else
|
---|
| 408 | rc=0;
|
---|
| 409 |
|
---|
[1766] | 410 | return rc;
|
---|
| 411 | }
|
---|
| 412 |
|
---|
[1983] | 413 | int get_cardsystem(ushort caid) {
|
---|
[3168] | 414 | int i,j;
|
---|
| 415 | for (i=0; i<CS_MAX_MOD; i++) {
|
---|
| 416 | if (cardsystem[i].caids) {
|
---|
| 417 | for (j=0;j<2;j++) {
|
---|
| 418 | if ((cardsystem[i].caids[j]==caid >> 8)) {
|
---|
| 419 | return i+1;
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 | }
|
---|
[1983] | 423 | }
|
---|
[3168] | 424 | return 0;
|
---|
[1983] | 425 | }
|
---|
| 426 |
|
---|
[2074] | 427 | void get_emm_filter(struct s_reader * rdr, uchar *filter) {
|
---|
| 428 | filter[0]=0xFF;
|
---|
| 429 | filter[1]=0;
|
---|
[1977] | 430 |
|
---|
[3168] | 431 | if (cardsystem[rdr->card_system-1].get_emm_filter) {
|
---|
| 432 | cardsystem[rdr->card_system-1].get_emm_filter(rdr, filter);
|
---|
[1977] | 433 | }
|
---|
| 434 |
|
---|
[2074] | 435 | return;
|
---|
[1977] | 436 | }
|
---|
| 437 |
|
---|
[1926] | 438 | int reader_emm(struct s_reader * reader, EMM_PACKET *ep)
|
---|
[8] | 439 | {
|
---|
| 440 | int rc=-1;
|
---|
[1090] | 441 |
|
---|
[1926] | 442 | rc=reader_checkhealth(reader);
|
---|
[1090] | 443 | if (rc)
|
---|
[8] | 444 | {
|
---|
[1926] | 445 | if (reader->b_nano[ep->emm[0]] & 0x01) //should this nano be blcoked?
|
---|
[452] | 446 | return 3;
|
---|
| 447 |
|
---|
[3168] | 448 | if (cardsystem[reader->card_system-1].do_emm)
|
---|
| 449 | rc=cardsystem[reader->card_system-1].do_emm(reader, ep);
|
---|
| 450 | else
|
---|
| 451 | rc=0;
|
---|
[8] | 452 | }
|
---|
| 453 | return(rc);
|
---|
| 454 | }
|
---|
[2365] | 455 |
|
---|
| 456 | int check_emm_cardsystem(struct s_reader * rdr, EMM_PACKET *ep)
|
---|
| 457 | {
|
---|
[2366] | 458 | return (rdr->fd && (rdr->caid[0] == b2i(2,ep->caid) || rdr->typ == R_CCCAM));
|
---|
[2365] | 459 | }
|
---|
[2803] | 460 |
|
---|
| 461 | void reader_device_close(struct s_reader * reader)
|
---|
| 462 | {
|
---|
| 463 | #ifdef HAVE_PCSC
|
---|
[2805] | 464 | if (reader->typ == R_PCSC)
|
---|
[2803] | 465 | pcsc_close(reader);
|
---|
[2805] | 466 | else
|
---|
[2803] | 467 | #endif
|
---|
[2805] | 468 | ICC_Async_Close(reader);
|
---|
[2803] | 469 | }
|
---|