Changeset 3011
- Timestamp:
- 09/08/10 19:44:06 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/reader-irdeto.c
r2955 r3011 175 175 static int irdeto_do_cmd(struct s_reader * reader, uchar *buf, ushort good, uchar * cta_res, ushort * p_cta_lr) 176 176 { 177 178 if( (rc=reader_cmd2icc(reader, buf, buf[4]+5, cta_res, p_cta_lr)) )179 180 if (*p_cta_lr<2)181 182 return(good!=b2i(2, cta_res+*p_cta_lr-2));177 int rc; 178 if( (rc = reader_cmd2icc(reader, buf, buf[4] + 5, cta_res, p_cta_lr)) ) 179 return(rc); // result may be 0 (success) or negative 180 if (*p_cta_lr < 2) 181 return(0x7F7F); // this should never happen 182 return(good != b2i(2, cta_res+*p_cta_lr-2)); 183 183 } 184 184 … … 190 190 static int irdeto_card_init_provider(struct s_reader * reader) 191 191 { 192 193 194 uchar buf[256]={0};195 196 197 198 199 200 for (buf[0]=i=p=0; i<reader->nprov; i++)201 202 sc_GetProvider[3]=i;203 204 205 if ((cta_lr==26) && ((!(i&1)) || (cta_res[0]!=0xf)))206 207 reader->prid[i][4]=p++;208 209 210 211 212 213 214 215 216 217 218 219 reader->prid[i][0]=0xf;220 221 222 cs_ri_log(reader, "active providers: %d (%s)", p, buf+1);223 224 192 def_resp; 193 int i, p; 194 uchar buf[256] = {0}; 195 196 /* 197 * Provider 198 */ 199 memset(reader->prid, 0xff, sizeof(reader->prid)); 200 for (buf[0] = i = p = 0; i<reader->nprov; i++) 201 { 202 sc_GetProvider[3] = i; 203 reader_chk_cmd(sc_GetProvider, 0); 204 //if ((cta_lr==26) && (cta_res[0]!=0xf)) 205 if ((cta_lr == 26) && ((!(i&1)) || (cta_res[0] != 0xf))) 206 { 207 reader->prid[i][4] = p++; 208 209 // maps the provider id for Betacrypt from FFFFFF to 000000, 210 // fixes problems with cascading CCcam and OSCam 211 if ((reader->caid[0] >= 0x1700) && (reader->caid[0] <= 0x1799)) 212 memset(&reader->prid[i][0], 0, 4); 213 else 214 memcpy(&reader->prid[i][0], cta_res, 4); 215 216 sprintf((char *) buf+strlen((char *)buf), ",%06lx", b2i(3, &reader->prid[i][1])); 217 } 218 else 219 reader->prid[i][0] = 0xf; 220 } 221 if (p) 222 cs_ri_log(reader, "active providers: %d (%s)", p, buf + 1); 223 224 return OK; 225 225 } 226 226 227 227 int irdeto_card_init(struct s_reader * reader, ATR newatr) 228 228 { 229 230 231 int camkey=0;232 uchar buf[256]={0};233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 reader->acs=(cta_res[0]<<8)|cta_res[1];253 reader->caid[0]=(cta_res[5]<<8)|cta_res[6];254 memcpy(reader->country_code,cta_res+13,3);255 256 257 258 259 260 261 262 263 buf[10]=0;264 265 memcpy(reader->hexserial, cta_res+12, 8); 266 reader->nprov=cta_res[10];267 268 269 270 271 272 273 for (sc_GetCardFile[2]=2;sc_GetCardFile[2]<4;sc_GetCardFile[2]++)274 275 276 277 278 279 if ((atr[14]==0x03) && (atr[15]==0x84) && (atr[16]==0x55))280 281 282 283 case 0x1702: camkey=1; break;284 case 0x1722: camkey=2; break;285 case 0x1762: camkey=3; break;286 default : camkey=4; break;287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 229 def_resp; 230 get_atr; 231 int camkey = 0; 232 uchar buf[256] = {0}; 233 234 if (memcmp(atr+4, "IRDETO", 6)) 235 return ERROR; 236 cs_ri_log(reader, "detect irdeto card"); 237 238 if(reader->has_rsa && !reader->force_irdeto) // we use rsa from config as camkey 239 { 240 cs_debug("[irdeto-reader] using camkey data from config"); 241 memcpy(&sc_GetCamKey383C[5], reader->rsa_mod, 0x40); 242 memcpy(sc_CamKey, reader->nagra_boxkey, 8); 243 cs_debug("[irdeto-reader] camkey: %s", cs_hexdump (0, sc_CamKey, 8)); 244 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[5], 32)); 245 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[37], 32)); 246 } 247 248 /* 249 * ContryCode 250 */ 251 reader_chk_cmd(sc_GetCountryCode, 18); 252 reader->acs = (cta_res[0] << 8) | cta_res[1]; 253 reader->caid[0] = (cta_res[5] << 8) | cta_res[6]; 254 memcpy(reader->country_code,cta_res + 13, 3); 255 cs_ri_log(reader, "caid: %04X, acs: %x.%02x, country code: %c%c%c", 256 reader->caid[0], cta_res[0], cta_res[1], cta_res[13], cta_res[14], cta_res[15]); 257 258 /* 259 * Ascii/Hex-Serial 260 */ 261 reader_chk_cmd(sc_GetASCIISerial, 22); 262 memcpy(buf, cta_res, 10); 263 buf[10] = 0; 264 reader_chk_cmd(sc_GetHEXSerial, 18); 265 memcpy(reader->hexserial, cta_res+12, 8); 266 reader->nprov = cta_res[10]; 267 cs_ri_log(reader, "providers: %d, ascii serial: %s, hex serial: %02X%02X%02X, hex base: %02X", 268 reader->nprov, buf, cta_res[12], cta_res[13], cta_res[14], cta_res[15]); 269 270 /* 271 * CardFile 272 */ 273 for (sc_GetCardFile[2] = 2; sc_GetCardFile[2] < 4; sc_GetCardFile[2]++) 274 reader_chk_cmd(sc_GetCardFile, 0); 275 276 /* 277 * CamKey 278 */ 279 if ((atr[14] == 0x03) && (atr[15] == 0x84) && (atr[16] == 0x55)) 280 { 281 switch (reader->caid[0]) 282 { 283 case 0x1702: camkey = 1; break; 284 case 0x1722: camkey = 2; break; 285 case 0x1762: camkey = 3; break; 286 default : camkey = 4; break; 287 } 288 } 289 290 cs_debug("[irdeto-reader] set camkey for type=%d", camkey); 291 292 switch (camkey) 293 { 294 case 1: 295 reader_chk_cmd(sc_GetCamKey384CZ, 10); 296 break; 297 case 2: 298 reader_chk_cmd(sc_GetCamKey384DZ, 10); 299 break; 300 case 3: 301 reader_chk_cmd(sc_GetCamKey384FZ, 10); 302 break; 303 default: 304 reader_chk_cmd(sc_GetCamKey383C, 0); 305 break; 306 } 307 307 if (reader->cardmhz != 600) 308 308 cs_log("WARNING: For Irdeto cards you will have to set 'cardmhz = 600' in oscam.server"); 309 309 310 310 return irdeto_card_init_provider(reader); 311 311 } 312 312 313 313 int irdeto_do_ecm(struct s_reader * reader, ECM_REQUEST *er) 314 314 { 315 def_resp; cta_lr=0; //suppress compiler error 316 static const uchar sc_EcmCmd[] = { 0x05, 0x00, 0x00, 0x02, 0x00 }; 317 uchar cta_cmd[272]; 318 319 memcpy(cta_cmd, sc_EcmCmd, sizeof(sc_EcmCmd)); 320 cta_cmd[4]=(er->ecm[2])-3; 321 memcpy(cta_cmd+sizeof(sc_EcmCmd), &er->ecm[6], cta_cmd[4]); 322 if (irdeto_do_cmd(reader, cta_cmd, 0x9D00, cta_res, &cta_lr)) { if(cta_lr>=2) snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d] %02x %02x",cta_lr, cta_res[cta_lr-2], cta_res[cta_lr-1] ); else snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d]<2",cta_lr); return ERROR; } 323 if (cta_lr<24) { snprintf( er->msglog, MSGLOGSIZE, "cta_lr (%d) < 24",cta_lr ); return ERROR; } 324 ReverseSessionKeyCrypt(sc_CamKey, cta_res+6); 325 ReverseSessionKeyCrypt(sc_CamKey, cta_res+14); 326 memcpy(er->cw, cta_res+6, 16); 327 return OK; 315 def_resp; cta_lr = 0; //suppress compiler error 316 static const uchar sc_EcmCmd[] = { 0x05, 0x00, 0x00, 0x02, 0x00 }; 317 uchar cta_cmd[272]; 318 319 memcpy(cta_cmd, sc_EcmCmd, sizeof(sc_EcmCmd)); 320 cta_cmd[4] = (er->ecm[2]) - 3; 321 memcpy(cta_cmd + sizeof(sc_EcmCmd), &er->ecm[6], cta_cmd[4]); 322 323 if (irdeto_do_cmd(reader, cta_cmd, 0x9D00, cta_res, &cta_lr)) { 324 if(cta_lr >= 2) 325 snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d] %02x %02x", cta_lr, cta_res[cta_lr - 2], cta_res[cta_lr - 1] ); 326 else 327 snprintf( er->msglog, MSGLOGSIZE, "irdeto_do_cmd [%d]<2", cta_lr); 328 329 return ERROR; 330 } 331 332 if (cta_lr < 24) { 333 snprintf( er->msglog, MSGLOGSIZE, "cta_lr (%d) < 24",cta_lr ); 334 return ERROR; 335 } 336 337 ReverseSessionKeyCrypt(sc_CamKey, cta_res+6); 338 ReverseSessionKeyCrypt(sc_CamKey, cta_res+14); 339 memcpy(er->cw, cta_res + 6, 16); 340 return OK; 328 341 } 329 342 … … 351 364 strcpy(dumprdrserial, cs_hexdump(1, rdr->hexserial, l)); 352 365 cs_debug_mask(D_EMM, "IRDETO EMM: SHARED l = %d ep = %s rdr = %s base = %02x", l, 353 366 cs_hexdump(1, ep->hexserial, l), dumprdrserial, base); 354 367 355 368 if (base & 0x10) { … … 365 378 cs_debug_mask(D_EMM, "IRDETO EMM: neither hex nor provider addressed or unknown provider id"); 366 379 return FALSE; 367 380 368 381 case 3: 369 382 // unique emm, 3 bytes addressed … … 373 386 strcpy(dumprdrserial, cs_hexdump(1, rdr->hexserial, l)); 374 387 cs_debug_mask(D_EMM, "IRDETO EMM: UNIQUE l = %d ep = %s rdr = %s", l, 375 388 cs_hexdump(1, ep->hexserial, l), dumprdrserial); 376 389 377 390 return (base == rdr->hexserial[3] && !memcmp(ep->emm + 4, rdr->hexserial, l)); … … 426 439 int irdeto_do_emm(struct s_reader * reader, EMM_PACKET *ep) 427 440 { 428 429 430 431 432 int i, l=(ep->emm[3]&0x07), ok=0;433 int mode=(ep->emm[3]>>3);434 435 uchar *emm=ep->emm;436 if (mode&0x10) // Hex addressed437 438 ok=(mode==reader->hexserial[3] &&439 440 441 442 443 for(i=0; i<reader->nprov; i++)444 445 ok=(mode==reader->prid[i][0] &&446 447 448 449 450 451 452 453 454 if (l<=ADDRLEN)455 456 const int dataLen=SCT_LEN(emm)-5-l; // sizeof of emm bytes (nanos)457 uchar *ptr=cta_cmd;458 memcpy(ptr, sc_EmmCmd, sizeof(sc_EmmCmd));// copy card command459 ptr[4]=dataLen+ADDRLEN;// set card command emm size460 ptr+=sizeof(sc_EmmCmd); emm+=3;461 memset(ptr, 0, ADDRLEN);// clear addr range462 memcpy(ptr, emm, l);// copy addr bytes463 ptr+=ADDRLEN; emm+=l;464 memcpy(ptr, &emm[2], dataLen);// copy emm bytes465 466 467 468 469 470 441 def_resp; 442 static const uchar sc_EmmCmd[] = { 0x01,0x00,0x00,0x00,0x00 }; 443 uchar cta_cmd[272]; 444 445 int i, l = (ep->emm[3] & 0x07), ok = 0; 446 int mode = (ep->emm[3] >> 3); 447 448 uchar *emm = ep->emm; 449 if (mode & 0x10) // Hex addressed 450 { 451 ok=(mode == reader->hexserial[3] && 452 (!l || !memcmp(&emm[4], reader->hexserial, l))); 453 } 454 else // Provider addressed 455 { 456 for(i = 0; i < reader->nprov; i++) 457 { 458 ok=(mode == reader->prid[i][0] && 459 (!l || !memcmp(&emm[4], &reader->prid[i][1], l))); 460 if (ok) break; 461 } 462 } 463 464 if (ok) 465 { 466 l++; 467 if (l <= ADDRLEN) 468 { 469 const int dataLen = SCT_LEN(emm) - 5 - l; // sizeof of emm bytes (nanos) 470 uchar *ptr = cta_cmd; 471 memcpy(ptr, sc_EmmCmd, sizeof(sc_EmmCmd)); // copy card command 472 ptr[4] = dataLen + ADDRLEN; // set card command emm size 473 ptr += sizeof(sc_EmmCmd); emm += 3; 474 memset(ptr, 0, ADDRLEN); // clear addr range 475 memcpy(ptr, emm, l); // copy addr bytes 476 ptr += ADDRLEN; emm += l; 477 memcpy(ptr, &emm[2], dataLen); // copy emm bytes 478 return(irdeto_do_cmd(reader, cta_cmd, 0, cta_res, &cta_lr) ? 0 : 1); 479 } 480 else 481 cs_debug("[irdeto-reader] addrlen %d > %d", l, ADDRLEN); 482 } 483 return ERROR; 471 484 } 472 485
Note:
See TracChangeset
for help on using the changeset viewer.