Ejemplo n.º 1
0
static int32_t dre_set_provider_info(struct s_reader *reader)
{
	def_resp;
	int32_t i;
	uchar cmd59[] = { 0x59, 0x14 };   // subscriptions
	uchar cmd5b[] = { 0x5b, 0x00, 0x14 }; //validity dates
	struct dre_data *csystem_data = reader->csystem_data;

	cs_clear_entitlement(reader);

	cmd59[1] = csystem_data->provider;
	if((dre_cmd(cmd59)))      //ask subscription packages, returns error on 0x11 card
	{
		uchar pbm[32];
		char tmp_dbg[65];
		memcpy(pbm, cta_res + 3, cta_lr - 6);
		rdr_log_dbg(reader, D_READER, "pbm: %s", cs_hexdump(0, pbm, 32, tmp_dbg, sizeof(tmp_dbg)));

		if(pbm[0] == 0xff)
			{ rdr_log(reader, "no active packages"); }
		else
			for(i = 0; i < 32; i++)
				if(pbm[i] != 0xff)
				{
					cmd5b[1] = i;
					cmd5b[2] = csystem_data->provider;
					dre_cmd(cmd5b);   //ask for validity dates

					time_t start;
					time_t end;
					start = (cta_res[3] << 24) | (cta_res[4] << 16) | (cta_res[5] << 8) | cta_res[6];
					end = (cta_res[7] << 24) | (cta_res[8] << 16) | (cta_res[9] << 8) | cta_res[10];

					struct tm temp;

					localtime_r(&start, &temp);
					int32_t startyear = temp.tm_year + 1900;
					int32_t startmonth = temp.tm_mon + 1;
					int32_t startday = temp.tm_mday;
					localtime_r(&end, &temp);
					int32_t endyear = temp.tm_year + 1900;
					int32_t endmonth = temp.tm_mon + 1;
					int32_t endday = temp.tm_mday;
					rdr_log(reader, "active package %i valid from %04i/%02i/%02i to %04i/%02i/%02i", i, startyear, startmonth, startday,
							endyear, endmonth, endday);
					cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), 0, 0, start, end, 1, 1);
				}
	}
	return OK;
}
Ejemplo n.º 2
0
static void show_class(struct s_reader *reader, const char *p, uint32_t provid, const uchar *b, int32_t l)
{
	int32_t i, j;

	// b -> via date (4 bytes)
	b+=4;
	l-=4;

	j=l-1;
	for (; j>=0; j--)
		for (i=0; i<8; i++)
			if (b[j] & (1 << (i&7)))
			{
				uchar cls;
				struct via_date vd;
				parse_via_date(b-4, &vd, 1);
				cls=(l-(j+1))*8+i;
				if (p)
					rdr_log(reader, "%sclass: %02X, expiry date: %04d/%02d/%02d - %04d/%02d/%02d", p, cls,
					vd.year_s+1980, vd.month_s, vd.day_s,
					vd.year_e+1980, vd.month_e, vd.day_e);
				else {
					rdr_log(reader, "class: %02X, expiry date: %04d/%02d/%02d - %04d/%02d/%02d", cls,
					vd.year_s+1980, vd.month_s, vd.day_s,
					vd.year_e+1980, vd.month_e, vd.day_e);

					time_t start_t, end_t;
					struct tm tm;
					//convert time:
					memset(&tm, 0, sizeof(tm));
					tm.tm_year = vd.year_s+80; //via year starts in 1980, tm_year starts in 1900
					tm.tm_mon = vd.month_s-1;  // january is 0 in tm_mon
					tm.tm_mday = vd.day_s;
					start_t = cs_timegm(&tm);

					tm.tm_year = vd.year_e+80; //via year starts in 1980, tm_year starts in 1900
					tm.tm_mon = vd.month_e-1;  // january is 0 in tm_mon
					tm.tm_mday = vd.day_e;
					end_t = cs_timegm(&tm);

					cs_add_entitlement(reader, reader->caid, provid, cls, cls, start_t, end_t, 5);
				}
			}
}
Ejemplo n.º 3
0
static int32_t dre_set_provider_info(struct s_reader *reader)
{
	def_resp;
	int32_t i;
    int subscr_cmd_len = 4;
    uchar subscr[4];// = { 0x59, 0x14 };   // subscriptions
    uchar dates[] = { 0x5b, 0x00, 0x14 }; //validity dates
    uchar subscr_len = 0, n = 0;
	struct dre_data *csystem_data = reader->csystem_data;

	cs_clear_entitlement(reader);

    switch(csystem_data->provider)
    {
        case 0x02:
        case 0x03:
            subscr[0] = 0x84;
            subscr[1] = 0;
            subscr[2] = 0x5F;
            subscr[3] = csystem_data->provider;
            dates[0] = 0x85;
            subscr_len = 0x5F;
            break;
        case 0x18:
        case 0x19:
        case 0x1A:
            subscr[0] = 0x94;
            subscr[1] = 0;
            subscr[2] = 0x5F;
            subscr[3] = csystem_data->provider;
            dates[0] = 0x95;
            subscr_len = 0x5F;
            break;
        default:
            subscr[0] = 0x59;
            subscr[1] = csystem_data->provider;
            subscr_len = 0x20;
            subscr_cmd_len = 2;
    }

chk_subscr:
    
    if((dre_script(subscr, subscr_cmd_len, 0, 0, 0)))      //ask subscription packages, returns error on 0x11 card
    {
        uchar pbm[subscr_len];
        char tmp_dbg[subscr_len*2+1];
		memcpy(pbm, cta_res + 3, cta_lr - 6);
        rdr_log_dbg(reader, D_READER, "pbm: %s", cs_hexdump(0, pbm, subscr_len, tmp_dbg, sizeof(tmp_dbg)));

        for(i = 0; i < subscr_len; i++)
            if(pbm[i] != 0xff)
            {
                dates[1] = i;
                dates[2] = csystem_data->provider;
                dre_cmd(dates);   //ask for validity dates

                time_t start;
                time_t end;
                start = (cta_res[3] << 24) | (cta_res[4] << 16) | (cta_res[5] << 8) | cta_res[6];
                end = (cta_res[7] << 24) | (cta_res[8] << 16) | (cta_res[9] << 8) | cta_res[10];

                struct tm temp;

                localtime_r(&start, &temp);
                int32_t startyear = temp.tm_year + 1900;
                int32_t startmonth = temp.tm_mon + 1;
                int32_t startday = temp.tm_mday;
                localtime_r(&end, &temp);
                int32_t endyear = temp.tm_year + 1900;
                int32_t endmonth = temp.tm_mon + 1;
                int32_t endday = temp.tm_mday;
                rdr_log(reader, "active package %i valid from %04i/%02i/%02i to %04i/%02i/%02i", i+n, startyear, startmonth, startday,
                        endyear, endmonth, endday);
                cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), 0, i+n, start, end, 5, 1);
            }
    }
    
    if(subscr_len == 0x5F) // read second part subscription packages, for DRE3 and DRE4
    {
        subscr[1] = 0x5F;
        subscr[2] = 0x21;
        subscr_len = 0x21;
        n = 0x5F;
        goto chk_subscr;
    }

	return OK;
}
Ejemplo n.º 4
0
static int32_t conax_card_info(struct s_reader * reader)
{
	def_resp;
	int32_t type, i, j, k=0, n=0, l;
	uint16_t provid = 0;
	char provname[32], pdate[32], chid[32];
	static const uchar insC6[] = {0xDD, 0xC6, 0x00, 0x00, 0x03, 0x1C, 0x01, 0x00};
	static const uchar ins26[] = {0xDD, 0x26, 0x00, 0x00, 0x03, 0x1C, 0x01, 0x01};
	uchar insCA[] = {0xDD, 0xCA, 0x00, 0x00, 0x00};
	char *txt[] = { "Package", "PPV-Event" };
	static const uchar *cmd[] = { insC6, ins26 };
	time_t start_t = 0, end_t = 0;
	uint32_t cxclass = 0;

	cs_clear_entitlement(reader); // reset the entitlements

	for (type=0; type<2; type++) {
		n=0;
		write_cmd(cmd[type], cmd[type]+5);
		while (cta_res[cta_lr-2]==0x98) {
			insCA[4]=cta_res[cta_lr-1];		// get len
			write_cmd(insCA, NULL);		// read
			if ((cta_res[cta_lr-2]==0x90) || (cta_res[cta_lr-2]==0x98)) {
				for (j=0; j<cta_lr-2; j+=cta_res[j+1]+2) {
					provid=(cta_res[j+2+type]<<8) | cta_res[j+3+type];
					chid[0] = '\0';
					for (k=0, i=j+4+type; (i<j+cta_res[j+1]); i+=cta_res[i+1]+2) {
						switch(cta_res[i]) {
							case 0x01:
								l=(cta_res[i+1]<(sizeof(provname)-1)) ? cta_res[i+1] : sizeof(provname)-1;
								memcpy(provname, cta_res+i+2, l);
								provname[l]='\0';
								break;
							case 0x30:
								if (k > 1) {
									rdr_log(reader, "%s: %d, id: %04X%s, date: %s - %s, name: %s", txt[type], ++n, provid, chid, pdate, pdate+16, trim(provname));

									// add entitlements to list
									cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), provid, cxclass, start_t, end_t, type + 1);

									k = 0;
									chid[0] = '\0';
								}
								if(k == 0) start_t = chid_date(cta_res+i+2, pdate, 15);
								else end_t = chid_date(cta_res+i+2, pdate+16, 15) /* add 23:59:59 here: */ + 0x1517F;
								++k;
								break;
							case 0x20: // Provider classes
							case 0x90: // (?) not sure what this is, saw it once in log
								snprintf(chid, sizeof(chid), ", classes: %02X%02X%02X%02X", cta_res[i+2], cta_res[i+3], cta_res[i+4] ,cta_res[i+5]);
								cxclass = b2ll(4, &cta_res[i+2]);
								break;
						}
					}
					rdr_log(reader, "%s: %d, id: %04X%s, date: %s - %s, name: %s", txt[type], ++n, provid, chid, pdate, pdate+16, trim(provname));

					// add entitlements to list
					cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), provid, cxclass, start_t, end_t, type + 1);
				}
			}
		}
	}
	rdr_log(reader, "ready for requests");
	return OK;
}
Ejemplo n.º 5
0
static int32_t bulcrypt_card_info(struct s_reader *reader)
{
	char tmp[512];
	time_t last_upd_ts, subs_end_ts;
	struct tm tm;
	def_resp

	rdr_log(reader, "Reading subscription info.");

	cs_clear_entitlement(reader);

	write_cmd(cmd_sub_info1, NULL);
	write_cmd(cmd_sub_info2, NULL);

	if (cta_lr < 45)
	{
		rdr_log(reader, "(info_cmd) Unexpected card answer: %s",
			cs_hexdump(1, cta_res, cta_lr, tmp, sizeof(tmp)));
		return ERROR;
	}

	// Response contains:
	//  13 29 0B
	//  4F 8F 00 E9 - Unix ts set by UNIQUE_EMM_82
	//  3C 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BF
	//  3C 84 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 BF
	//  90 2B

	last_upd_ts = b2i(4, cta_res + 3);
	subs_end_ts = last_upd_ts + (31 * 86400); // *FIXME* this is just a guess

	reader->card_valid_to = subs_end_ts;

	gmtime_r(&last_upd_ts, &tm);
	memset(tmp, 0, sizeof(tmp));
	strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S %Z", &tm);
	rdr_log(reader, "Subscription data last update    : %s", tmp);

	gmtime_r(&subs_end_ts, &tm);
	memset(tmp, 0, sizeof(tmp));
	strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S %Z", &tm);
	rdr_log(reader, "Subscription should be active to : %s", tmp);

	unsigned int subs1 = b2i(2, cta_res + 3 + 4 + 16);
	unsigned int subs2 = b2i(2, cta_res + 3 + 4 + 16 + 18);

	if (subs1 == 0xffff) {
		rdr_log(reader, "No active subscriptions (0x%04x, 0x%04x)", subs1, subs2);
	} else {
		unsigned int i;
		rdr_log(reader, "Subscription data 1 (0x%04x): %s",
			subs1, dec2bin_str(subs1, tmp));
		rdr_log(reader, "Subscription data 2 (0x%04x): %s",
			subs2, dec2bin_str(subs2, tmp));

		// Configure your tiers to get subscription packets name resolution
// # Example oscam.tiers file
// 5581:0001|Economic
// 5581:0002|Standard
// 5581:0004|Premium
// 5581:0008|HBO
// 5581:0010|Unknown Package 10
// 5581:0020|Unknown Package 20
// 5581:0040|Unknown Package 40
// 5581:0080|Unknown Package 80
		for (i = 1; i < 256; i <<= 1)
		{
			if ((subs1 & i) == i) {
				cs_add_entitlement(reader, 0x4AEE,
					0, /* provid */
					i, /* id  */
					0, /* class */
					last_upd_ts, /* start_ts */
					subs_end_ts, /* end_ts */
					4 /* type: Tier */
				);
				cs_add_entitlement(reader, 0x5581,
					0, /* provid */
					i, /* id  */
					0, /* class */
					last_upd_ts, /* start_ts */
					subs_end_ts, /* end_ts */
					4 /* type: Tier */
				);
				get_tiername(i, 0x4aee, tmp);
				if (tmp[0] == 0x00)
					get_tiername(i, 0x5581, tmp);
				rdr_log(reader, "  Package %02x is active: %s", i, tmp);
			}
		}
	}

	return OK;
}
Ejemplo n.º 6
0
static int32_t viaccess_card_info(struct s_reader * reader)
{
	def_resp;
	int32_t i, l, scls, show_cls;
	uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data
	uchar insb8[] = { 0xca, 0xb8, 0x00, 0x00, 0x00 }; // read selected data
	uchar insa4[] = { 0xca, 0xa4, 0x00, 0x00, 0x00 }; // select issuer
	uchar insc0[] = { 0xca, 0xc0, 0x00, 0x00, 0x00 }; // read data item
	static const uchar ins24[] = { 0xca, 0x24, 0x00, 0x00, 0x09 }; // set pin

	static const uchar cls[] = { 0x00, 0x21, 0xff, 0x9f};
	static const uchar pin[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04};

	time_t start_t, end_t;
	uchar via_cls = 0;

	show_cls=reader->show_cls;
	reader->last_geo.provid  = 0;
	reader->last_geo.geo_len = 0;
	reader->last_geo.geo[0]  = 0;

	cs_log("[viaccess-reader] card detected");

	cs_clear_entitlement(reader); //reset the entitlements

	// set pin
	write_cmd(ins24, pin);

	insac[2]=0xa4; write_cmd(insac, NULL); // request unique id
	insb8[4]=0x07; write_cmd(insb8, NULL); // read unique id
	cs_log("[viaccess-reader] serial: %llu", b2ll(5, cta_res+2));

	scls=0;
	insa4[2]=0x00; write_cmd(insa4, NULL); // select issuer 0
	for (i=1; (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0); i++)
	{
		uint32_t l_provid, l_sa;
		uchar l_name[64];
		insc0[4]=0x1a; write_cmd(insc0, NULL); // show provider properties
		cta_res[2]&=0xF0;
		l_provid=b2i(3, cta_res);

		insac[2]=0xa5; write_cmd(insac, NULL); // request sa
		insb8[4]=0x06; write_cmd(insb8, NULL); // read sa
		l_sa=b2i(4, cta_res+2);

		insac[2]=0xa7; write_cmd(insac, NULL); // request name
		insb8[4]=0x02; write_cmd(insb8, NULL); // read name nano + len
		l=cta_res[1];
		insb8[4]=l; write_cmd(insb8, NULL); // read name
		cta_res[l]=0;
		trim((char *)cta_res);
		if (cta_res[0])
			snprintf((char *)l_name, sizeof(l_name), ", name: %s", cta_res);
		else
			l_name[0]=0;

		// read GEO
		insac[2]=0xa6; write_cmd(insac, NULL); // request GEO
		insb8[4]=0x02; write_cmd(insb8, NULL); // read GEO nano + len
		l=cta_res[1];
		char tmp[l*3+1];
		insb8[4]=l; write_cmd(insb8, NULL); // read geo
		cs_ri_log(reader, "provider: %d, id: %06X%s, sa: %08X, geo: %s",
			i, l_provid, l_name, l_sa, (l<4) ? "empty" : cs_hexdump(1, cta_res, l, tmp, sizeof(tmp)));

		// read classes subscription
		insac[2]=0xa9; insac[4]=4;
		write_cmd(insac, cls); // request class subs
		scls=0;
		while( (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0) )
		{
			insb8[4]=0x02; write_cmd(insb8, NULL); // read class subs nano + len
			if( (cta_res[cta_lr-2]==0x90) && (cta_res[cta_lr-1]==0) )
			{
				int32_t fshow;
				l=cta_res[1];
				//fshow=(client[cs_idx].dbglvl==D_DUMP)?1:(scls < show_cls)?1:0;
				fshow=(scls<show_cls);
				insb8[4]=l; write_cmd(insb8, NULL); // read class subs
				if( (cta_res[cta_lr-2]==0x90) && (fshow) &&
					(cta_res[cta_lr-1]==0x00 || cta_res[cta_lr-1]==0x08) )
				{
					show_class(reader, NULL, cta_res, cta_lr-2);

					get_via_data(cta_res, cta_lr-2, &start_t, &end_t, &via_cls);
					cs_add_entitlement(reader, reader->caid, (uint64_t)l_provid, (uint16_t)via_cls, (uint16_t)via_cls, start_t, end_t, 5);

					scls++;
				}
			}
		}

		insac[4]=0;
		insa4[2]=0x02;
		write_cmd(insa4, NULL); // select next provider
	}
	//return ERROR;
	return OK;
}