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