Changeset 1507
- Timestamp:
- 02/11/10 12:33:39 (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/protocol_t1.c
r1399 r1507 39 39 */ 40 40 41 static int 42 Protocol_T1_SendBlock (T1_Block * block); 43 44 static int 45 Protocol_T1_ReceiveBlock (T1_Block ** block); 46 47 static int 48 Protocol_T1_UpdateBWT (unsigned short BWT); 41 static int Protocol_T1_SendBlock (T1_Block * block); 42 43 static int Protocol_T1_ReceiveBlock (T1_Block ** block); 49 44 50 45 /* … … 52 47 */ 53 48 54 int 55 Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) 49 int Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp) 56 50 { 57 51 T1_Block *block; … … 71 65 ret = Protocol_T1_SendBlock (block); 72 66 73 /* Delete block */74 T1_Block_Delete (block);75 76 67 /* Receive a block */ 77 68 ret = Protocol_T1_ReceiveBlock (&block); 78 69 79 if (ret == PROTOCOL_T1_OK)70 if (ret == OK) 80 71 { 81 72 rsp_type = T1_Block_GetType (block); … … 110 101 ret = Protocol_T1_SendBlock (block); 111 102 112 /* Delete I-block */ 113 T1_Block_Delete (block); 114 115 while ((ret == PROTOCOL_T1_OK) && more) 103 while ((ret == OK) && more) 116 104 { 117 105 /* Receive a block */ 118 106 ret = Protocol_T1_ReceiveBlock (&block); 119 107 120 if (ret == PROTOCOL_T1_OK)108 if (ret == OK) 121 109 { 122 110 rsp_type = T1_Block_GetType (block); … … 147 135 /* Send a block */ 148 136 ret = Protocol_T1_SendBlock (block); 149 150 /* Delete I-block */151 T1_Block_Delete (block);152 137 } 153 138 … … 157 142 T1_Block_Delete (block); 158 143 159 ret = PROTOCOL_T1_NOT_IMPLEMENTED;144 ret = ERROR; //not implemented 160 145 } 161 146 } … … 163 148 else 164 149 { 165 ret = PROTOCOL_T1_NOT_IMPLEMENTED;150 ret = ERROR;//not implemented 166 151 } 167 152 } … … 173 158 wtx = 0; 174 159 175 while ((ret == PROTOCOL_T1_OK) && more)160 while ((ret == OK) && more) 176 161 { 177 162 if (wtx > 1) 178 Protocol_T1_UpdateBWT(wtx * BWT);163 ICC_Async_SetTimings (wtx * BWT); 179 164 180 165 /* Receive a block */ … … 183 168 if (wtx > 1) 184 169 { 185 Protocol_T1_UpdateBWT(BWT);170 ICC_Async_SetTimings (BWT); 186 171 wtx = 0; 187 172 } 188 173 189 if (ret == PROTOCOL_T1_OK)174 if (ret == OK) 190 175 { 191 176 rsp_type = T1_Block_GetType (block); … … 218 203 /* Send R-Block */ 219 204 ret = Protocol_T1_SendBlock (block); 220 221 /* Delete I-block */222 T1_Block_Delete (block);223 205 } 224 206 } … … 240 222 /* Send WTX response */ 241 223 ret = Protocol_T1_SendBlock (block); 242 243 /* Delete block */244 T1_Block_Delete (block);245 224 } 246 225 247 226 else 248 227 { 249 ret = PROTOCOL_T1_NOT_IMPLEMENTED;228 ret = ERROR;//not implemented 250 229 } 251 230 } 252 231 } 253 232 254 if (ret == PROTOCOL_T1_OK)233 if (ret == OK) 255 234 (*rsp) = APDU_Rsp_New (buffer, counter); 256 235 … … 265 244 */ 266 245 267 static int 268 Protocol_T1_SendBlock (T1_Block * block) 246 static int Protocol_T1_SendBlock (T1_Block * block) 269 247 { 270 BYTE *buffer; 271 int length, ret; 272 273 { 274 /* Send T=1 block */ 275 buffer = T1_Block_Raw (block); 276 length = T1_Block_RawLen (block); 277 278 if (ICC_Async_Transmit (length, buffer)) 279 { 280 ret = PROTOCOL_T1_ICC_ERROR; 281 } 282 283 else 284 ret = PROTOCOL_T1_OK; 285 } 286 248 int ret; 249 ret = ICC_Async_Transmit (T1_Block_RawLen(block), T1_Block_Raw(block)); 250 T1_Block_Delete(block); 287 251 return ret; 288 252 } 289 253 290 static int 291 Protocol_T1_ReceiveBlock (T1_Block ** block) 254 static int Protocol_T1_ReceiveBlock (T1_Block ** block) 292 255 { 293 256 BYTE buffer[T1_BLOCK_MAX_SIZE]; … … 296 259 /* Receive four mandatory bytes */ 297 260 if (ICC_Async_Receive (4, buffer)) 298 { 299 ret = PROTOCOL_T1_ICC_ERROR; 300 (*block) = NULL; 301 } 302 261 ret = ERROR; 303 262 else 304 { 305 if (buffer[2] != 0x00) 306 { 263 if (buffer[2] != 0x00) { 307 264 /* Set timings to read the remaining block */ 308 Protocol_T1_UpdateBWT(CWT);265 ICC_Async_SetTimings (CWT); 309 266 310 267 /* Receive remaining bytes */ 311 268 if (ICC_Async_Receive (buffer[2], buffer + 4)) 312 { 313 (*block) = NULL; 314 ret = PROTOCOL_T1_ICC_ERROR; 315 } 316 317 else 318 { 269 ret = ERROR; 270 else { 319 271 (*block) = T1_Block_New (buffer, buffer[2] + 4); 320 ret = PROTOCOL_T1_OK; 321 } 322 272 ret = OK; 273 } 323 274 /* Restore timings */ 324 Protocol_T1_UpdateBWT (BWT); 325 } 326 else 327 { 328 ret = PROTOCOL_T1_OK; 275 ICC_Async_SetTimings (BWT); 276 } 277 else { 278 ret = OK; 329 279 (*block) = T1_Block_New (buffer, 4); 330 280 } 331 } 332 281 282 if (ret == ERROR) 283 (*block) = NULL; 333 284 return ret; 334 285 } 335 336 static int337 Protocol_T1_UpdateBWT (unsigned short bwt)338 {339 if (ICC_Async_SetTimings (bwt))340 return PROTOCOL_T1_ICC_ERROR;341 342 return PROTOCOL_T1_OK;343 } -
trunk/csctapi/protocol_t1.h
r1389 r1507 30 30 31 31 /* 32 * Exported constants definition33 */34 35 /* Return codes */36 #define PROTOCOL_T1_OK 0 /* Command OK */37 #define PROTOCOL_T1_ICC_ERROR 2 /* ICC comunication error */38 #define PROTOCOL_T1_ERROR 4 /* T=1 Protocol Error */39 #define PROTOCOL_T1_NOT_IMPLEMENTED 7 /* Feture not implemented */40 41 /*42 32 * Exported datatypes definition 43 33 */ -
trunk/reader-irdeto.c
r1399 r1507 154 154 if (l && (cta_lr!=l)) return ERROR; } 155 155 156 int irdeto_card_init(ATR newatr) 157 { 158 get_atr; 159 int i, camkey=0; 160 uchar buf[256]={0}; 161 162 if (memcmp(atr+4, "IRDETO", 6)) 163 return ERROR; 164 cs_ri_log("detect Irdeto card"); 165 166 if(reader[ridx].has_rsa) // we use rsa from config as camkey 167 { 168 cs_debug("[irdeto-reader] using camkey data from config"); 169 memcpy(&sc_GetCamKey383C[5], reader[ridx].rsa_mod, 0x40); 170 memcpy(sc_CamKey, reader[ridx].nagra_boxkey, 8); 171 cs_debug("[irdeto-reader] camkey: %s", cs_hexdump (0, sc_CamKey, 8)); 172 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[5], 32)); 173 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[37], 32)); 174 } 175 176 /* 177 * ContryCode 178 */ 179 reader_chk_cmd(sc_GetCountryCode, 18); 180 reader[ridx].acs=(cta_res[0]<<8)|cta_res[1]; 181 reader[ridx].caid[0]=(cta_res[5]<<8)|cta_res[6]; 182 cs_ri_log("caid: %04X, acs: %x.%02x%s", 183 reader[ridx].caid[0], cta_res[0], cta_res[1], buf); 184 185 /* 186 * Ascii/Hex-Serial 187 */ 188 reader_chk_cmd(sc_GetASCIISerial, 22); 189 memcpy(buf, cta_res, 10); 190 buf[10]=0; 191 reader_chk_cmd(sc_GetHEXSerial, 18); 192 memcpy(reader[ridx].hexserial, cta_res+12, 8); 193 reader[ridx].nprov=cta_res[10]; 194 cs_ri_log("ascii serial: %s, hex serial: %02X%02X%02X, hex base: %02X", 195 buf, cta_res[12], cta_res[13], cta_res[14], cta_res[15]); 196 197 /* 198 * CardFile 199 */ 200 for (sc_GetCardFile[2]=2;sc_GetCardFile[2]<4;sc_GetCardFile[2]++) 201 reader_chk_cmd(sc_GetCardFile, 0); 202 203 /* 204 * CamKey 205 */ 206 if ((atr[14]==0x03) && (atr[15]==0x84) && (atr[16]==0x55)) 207 { 208 switch (reader[ridx].caid[0]) 209 { 210 case 0x1702: camkey=1; break; 211 case 0x1722: camkey=2; break; 212 case 0x1762: camkey=3; break; 213 default : camkey=4; break; 214 } 215 } 216 217 if ((reader[ridx].caid[0] >= 0x1700) && (reader[ridx].caid[0] <= 0x1799)) // Betacrypt 218 { 219 memset(reader[ridx].prid, 0xff, sizeof(reader[ridx].prid)); 220 for (i=0; i<reader[ridx].nprov; i++) 221 { 222 //values are needed for AU to work for Nagravision/Aladin/Betacrypt 223 reader[ridx].prid[i][0]=0; 224 reader[ridx].prid[i][1]=0; 225 reader[ridx].prid[i][2]=0; 226 reader[ridx].prid[i][3]=i; 227 //reader[ridx].prid[i][4]=0; //not sure what to do with this one 228 229 //since shared address is not filled, we fill it here 230 reader[ridx].sa[i][0]=0x00; 231 reader[ridx].sa[i][1]=0xFF; 232 reader[ridx].sa[i][2]=0xFF; 233 reader[ridx].sa[i][3]=0xFF; 234 } 235 } 236 237 cs_debug("[irdeto-reader] set camkey for type=%d", camkey); 238 239 switch (camkey) 240 { 241 case 1: 242 reader_chk_cmd(sc_GetCamKey384CZ, 10); 243 break; 244 case 2: 245 reader_chk_cmd(sc_GetCamKey384DZ, 10); 246 break; 247 case 3: 248 reader_chk_cmd(sc_GetCamKey384FZ, 10); 249 break; 250 default: 251 reader_chk_cmd(sc_GetCamKey383C, 0); 252 break; 253 } 254 if (reader[ridx].cardmhz != 600) 255 cs_log("WARNING: For Irdeto cards you will have to set 'cardmhz = 600' in oscam.server"); 256 return OK; 257 } 258 259 int irdeto_do_ecm(ECM_REQUEST *er) 260 { 261 static const uchar sc_EcmCmd[] = { 0x05, 0x00, 0x00, 0x02, 0x00 }; 262 uchar cta_cmd[272]; 263 264 memcpy(cta_cmd, sc_EcmCmd, sizeof(sc_EcmCmd)); 265 cta_cmd[4]=(er->ecm[2])-3; 266 memcpy(cta_cmd+sizeof(sc_EcmCmd), &er->ecm[6], cta_cmd[4]); 267 if (irdeto_do_cmd(cta_cmd, 0x9D00)) return ERROR; 268 if (cta_lr<24) return ERROR; 269 ReverseSessionKeyCrypt(sc_CamKey, cta_res+6); 270 ReverseSessionKeyCrypt(sc_CamKey, cta_res+14); 271 memcpy(er->cw, cta_res+6, 16); 272 return OK; 273 } 274 275 int irdeto_do_emm(EMM_PACKET *ep) 276 { 277 static const uchar sc_EmmCmd[] = { 0x01,0x00,0x00,0x00,0x00 }; 278 uchar cta_cmd[272]; 279 280 int i, l=(ep->emm[3]&0x07), ok=0; 281 int mode=(ep->emm[3]>>3); 282 283 uchar *emm=ep->emm; 284 ep->type=emm[3]; 285 if (mode&0x10) // Hex addressed 286 { 287 ok=(mode==reader[ridx].hexserial[3] && 288 (!l || !memcmp(&emm[4], reader[ridx].hexserial, l))); 289 } 290 else // Provider addressed 291 { 292 for(i=0; i<reader[ridx].nprov; i++) 293 { 294 ok=(mode==reader[ridx].prid[i][0] && 295 (!l || !memcmp(&emm[4], &reader[ridx].prid[i][1], l))); 296 if (ok) break; 297 } 298 } 299 300 if (ok) 301 { 302 l++; 303 if (l<=ADDRLEN) 304 { 305 const int dataLen=SCT_LEN(emm)-5-l; // sizeof of emm bytes (nanos) 306 uchar *ptr=cta_cmd; 307 memcpy(ptr, sc_EmmCmd, sizeof(sc_EmmCmd)); // copy card command 308 ptr[4]=dataLen+ADDRLEN; // set card command emm size 309 ptr+=sizeof(sc_EmmCmd); emm+=3; 310 memset(ptr, 0, ADDRLEN); // clear addr range 311 memcpy(ptr, emm, l); // copy addr bytes 312 ptr+=ADDRLEN; emm+=l; 313 memcpy(ptr, &emm[2], dataLen); // copy emm bytes 314 return(irdeto_do_cmd(cta_cmd, 0) ? 0 : 1); 315 } 316 else 317 cs_debug("[irdeto-reader] addrlen %d > %d", l, ADDRLEN); 318 } 319 return ERROR; 320 } 321 322 int irdeto_card_info(void) 156 static int irdeto_card_init2(void) 323 157 { 324 158 int i, p; … … 412 246 return OK; 413 247 } 248 249 int irdeto_card_init(ATR newatr) 250 { 251 get_atr; 252 int i, camkey=0; 253 uchar buf[256]={0}; 254 255 if (memcmp(atr+4, "IRDETO", 6)) 256 return ERROR; 257 cs_ri_log("detect Irdeto card"); 258 259 if(reader[ridx].has_rsa) // we use rsa from config as camkey 260 { 261 cs_debug("[irdeto-reader] using camkey data from config"); 262 memcpy(&sc_GetCamKey383C[5], reader[ridx].rsa_mod, 0x40); 263 memcpy(sc_CamKey, reader[ridx].nagra_boxkey, 8); 264 cs_debug("[irdeto-reader] camkey: %s", cs_hexdump (0, sc_CamKey, 8)); 265 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[5], 32)); 266 cs_debug("[irdeto-reader] camkey-data: %s", cs_hexdump (0, &sc_GetCamKey383C[37], 32)); 267 } 268 269 /* 270 * ContryCode 271 */ 272 reader_chk_cmd(sc_GetCountryCode, 18); 273 reader[ridx].acs=(cta_res[0]<<8)|cta_res[1]; 274 reader[ridx].caid[0]=(cta_res[5]<<8)|cta_res[6]; 275 cs_ri_log("caid: %04X, acs: %x.%02x%s", 276 reader[ridx].caid[0], cta_res[0], cta_res[1], buf); 277 278 /* 279 * Ascii/Hex-Serial 280 */ 281 reader_chk_cmd(sc_GetASCIISerial, 22); 282 memcpy(buf, cta_res, 10); 283 buf[10]=0; 284 reader_chk_cmd(sc_GetHEXSerial, 18); 285 memcpy(reader[ridx].hexserial, cta_res+12, 8); 286 reader[ridx].nprov=cta_res[10]; 287 cs_ri_log("ascii serial: %s, hex serial: %02X%02X%02X, hex base: %02X", 288 buf, cta_res[12], cta_res[13], cta_res[14], cta_res[15]); 289 290 /* 291 * CardFile 292 */ 293 for (sc_GetCardFile[2]=2;sc_GetCardFile[2]<4;sc_GetCardFile[2]++) 294 reader_chk_cmd(sc_GetCardFile, 0); 295 296 /* 297 * CamKey 298 */ 299 if ((atr[14]==0x03) && (atr[15]==0x84) && (atr[16]==0x55)) 300 { 301 switch (reader[ridx].caid[0]) 302 { 303 case 0x1702: camkey=1; break; 304 case 0x1722: camkey=2; break; 305 case 0x1762: camkey=3; break; 306 default : camkey=4; break; 307 } 308 } 309 310 if ((reader[ridx].caid[0] >= 0x1700) && (reader[ridx].caid[0] <= 0x1799)) // Betacrypt 311 { 312 memset(reader[ridx].prid, 0xff, sizeof(reader[ridx].prid)); 313 for (i=0; i<reader[ridx].nprov; i++) 314 { 315 //values are needed for AU to work for Nagravision/Aladin/Betacrypt 316 reader[ridx].prid[i][0]=0; 317 reader[ridx].prid[i][1]=0; 318 reader[ridx].prid[i][2]=0; 319 reader[ridx].prid[i][3]=i; 320 //reader[ridx].prid[i][4]=0; //not sure what to do with this one 321 322 //since shared address is not filled, we fill it here 323 reader[ridx].sa[i][0]=0x00; 324 reader[ridx].sa[i][1]=0xFF; 325 reader[ridx].sa[i][2]=0xFF; 326 reader[ridx].sa[i][3]=0xFF; 327 } 328 } 329 330 cs_debug("[irdeto-reader] set camkey for type=%d", camkey); 331 332 switch (camkey) 333 { 334 case 1: 335 reader_chk_cmd(sc_GetCamKey384CZ, 10); 336 break; 337 case 2: 338 reader_chk_cmd(sc_GetCamKey384DZ, 10); 339 break; 340 case 3: 341 reader_chk_cmd(sc_GetCamKey384FZ, 10); 342 break; 343 default: 344 reader_chk_cmd(sc_GetCamKey383C, 0); 345 break; 346 } 347 if (reader[ridx].cardmhz != 600) 348 cs_log("WARNING: For Irdeto cards you will have to set 'cardmhz = 600' in oscam.server"); 349 return irdeto_card_init2(); 350 } 351 352 int irdeto_do_ecm(ECM_REQUEST *er) 353 { 354 static const uchar sc_EcmCmd[] = { 0x05, 0x00, 0x00, 0x02, 0x00 }; 355 uchar cta_cmd[272]; 356 357 memcpy(cta_cmd, sc_EcmCmd, sizeof(sc_EcmCmd)); 358 cta_cmd[4]=(er->ecm[2])-3; 359 memcpy(cta_cmd+sizeof(sc_EcmCmd), &er->ecm[6], cta_cmd[4]); 360 if (irdeto_do_cmd(cta_cmd, 0x9D00)) return ERROR; 361 if (cta_lr<24) return ERROR; 362 ReverseSessionKeyCrypt(sc_CamKey, cta_res+6); 363 ReverseSessionKeyCrypt(sc_CamKey, cta_res+14); 364 memcpy(er->cw, cta_res+6, 16); 365 return OK; 366 } 367 368 int irdeto_do_emm(EMM_PACKET *ep) 369 { 370 static const uchar sc_EmmCmd[] = { 0x01,0x00,0x00,0x00,0x00 }; 371 uchar cta_cmd[272]; 372 373 int i, l=(ep->emm[3]&0x07), ok=0; 374 int mode=(ep->emm[3]>>3); 375 376 uchar *emm=ep->emm; 377 ep->type=emm[3]; 378 if (mode&0x10) // Hex addressed 379 { 380 ok=(mode==reader[ridx].hexserial[3] && 381 (!l || !memcmp(&emm[4], reader[ridx].hexserial, l))); 382 } 383 else // Provider addressed 384 { 385 for(i=0; i<reader[ridx].nprov; i++) 386 { 387 ok=(mode==reader[ridx].prid[i][0] && 388 (!l || !memcmp(&emm[4], &reader[ridx].prid[i][1], l))); 389 if (ok) break; 390 } 391 } 392 393 if (ok) 394 { 395 l++; 396 if (l<=ADDRLEN) 397 { 398 const int dataLen=SCT_LEN(emm)-5-l; // sizeof of emm bytes (nanos) 399 uchar *ptr=cta_cmd; 400 memcpy(ptr, sc_EmmCmd, sizeof(sc_EmmCmd)); // copy card command 401 ptr[4]=dataLen+ADDRLEN; // set card command emm size 402 ptr+=sizeof(sc_EmmCmd); emm+=3; 403 memset(ptr, 0, ADDRLEN); // clear addr range 404 memcpy(ptr, emm, l); // copy addr bytes 405 ptr+=ADDRLEN; emm+=l; 406 memcpy(ptr, &emm[2], dataLen); // copy emm bytes 407 return(irdeto_do_cmd(cta_cmd, 0) ? 0 : 1); 408 } 409 else 410 cs_debug("[irdeto-reader] addrlen %d > %d", l, ADDRLEN); 411 } 412 return ERROR; 413 } 414 415 int irdeto_card_info(void) 416 { 417 //original irdeto_card_info is not pure info, it is actually needed for init 418 return OK; 419 } 420
Note:
See TracChangeset
for help on using the changeset viewer.