static void device_fn(const char *token, char *value, void *setting, FILE *f)
{
	struct s_reader *rdr = setting;
	int32_t isphysical = !is_network_reader(rdr);
	if(value)
	{
		int32_t i;
		char *ptr, *saveptr1 = NULL;
		for(i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < 3) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++)
		{
			trim(ptr);
			switch(i)
			{
			case 0:
				cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
				break;
			case 1:
				rdr->r_port = atoi(ptr);
				break;
			case 2:
				rdr->l_port = atoi(ptr);
				break;
			}
		}
		return;
	}
	fprintf_conf(f, token, "%s", rdr->device); // it should not have \n at the end
	if((rdr->r_port || cfg.http_full_cfg) && !isphysical)
		{ fprintf(f, ",%d", rdr->r_port); }
	if((rdr->l_port || cfg.http_full_cfg) && !isphysical && strncmp(reader_get_type_desc(rdr, 0), "cccam", 5))
		{ fprintf(f, ",%d", rdr->l_port); }
	fprintf(f, "\n");
}
Beispiel #2
0
const char *client_get_proto(struct s_client *cl)
{
    char *ctyp;
    switch (cl->typ) {
    case 's':
        ctyp = "server";
        break;
    case 'h':
        ctyp = "http";
        break;
    case 'p':
    case 'r':
        ctyp = reader_get_type_desc(cl->reader, 1);
        break;
#ifdef CS_ANTICASC
    case 'a':
        ctyp = "anticascader";
        break;
#endif
    case 'c':
        if (cccam_client_extended_mode(cl)) {
            ctyp = "cccam ext";
            break;
        }
    default:
        ctyp = get_module(cl)->desc;
    }
    return ctyp;
}
static void protocol_fn(const char *token, char *value, void *setting, FILE *f) {
    struct s_reader *rdr = setting;
    if (value) {
        if (strlen(value) == 0)
            return;
        struct protocol_map {
            char *name;
            int typ;
        } protocols[] = {
            { "serial",     R_SERIAL },
            { "camd35",     R_CAMD35 },
            { "cs378x",     R_CS378X },
            { "cs357x",     R_CAMD35 },
            { "camd33",     R_CAMD33 },
            { "gbox",       R_GBOX },
            { "cccam",      R_CCCAM },
            { "cccam ext",  R_CCCAM },
            { "constcw",    R_CONSTCW },
            { "radegast",   R_RADEGAST },
            { "ghttp",      R_GHTTP },
            { "newcamd",    R_NEWCAMD },
            { "newcamd525", R_NEWCAMD },
            { "newcamd524", R_NEWCAMD },
            { NULL        , 0 }
        }, *p;
        int i;
        // Parse card readers
        for (i = 0; i < CS_MAX_MOD; i++) {
            if (streq(value, cardreaders[i].desc)) {
                rdr->crdr = cardreaders[i];
                rdr->typ  = cardreaders[i].typ;
                return;
            }
        }
        // Parse protocols
        for(i = 0, p = &protocols[0]; p->name; p = &protocols[++i]) {
            if (streq(p->name, value)) {
                rdr->typ = p->typ;
                break;
            }
        }
        if (rdr->typ == R_NEWCAMD)
            rdr->ncd_proto = streq(value, "newcamd524") ? NCD_524 : NCD_525;
        if (!rdr->typ)
            fprintf(stderr, "ERROR: '%s' is unsupported reader protocol!\n", value);
        return;
    }
    fprintf_conf(f, token, "%s\n", reader_get_type_desc(rdr, 0));
}
Beispiel #4
0
void azbox_send_dcw(struct s_client *client, ECM_REQUEST *er) {
	cs_debug_mask(D_DVBAPI, LOG_PREFIX "send_dcw");

	FILE *ecmtxt;
	if ((ecmtxt = fopen(ECMINFO_FILE, "w"))) {
		char tmp[25];
		if(er->rc <= E_CACHEEX) {
			fprintf(ecmtxt, "caid: 0x%04X\npid: 0x%04X\nprov: 0x%06X\n", er->caid, er->pid, (uint) er->prid);
			fprintf(ecmtxt, "reader: %s\n", er->selected_reader->label);
			if (is_cascading_reader(er->selected_reader))
				fprintf(ecmtxt, "from: %s\n", er->selected_reader->device);
			else
				fprintf(ecmtxt, "from: local\n");
			fprintf(ecmtxt, "protocol: %s\n", reader_get_type_desc(er->selected_reader, 1));
			fprintf(ecmtxt, "hops: %d\n", er->selected_reader->currenthops);
			fprintf(ecmtxt, "ecm time: %.3f\n", (float) client->cwlastresptime/1000);
			fprintf(ecmtxt, "cw0: %s\n", cs_hexdump(1,demux[0].lastcw[0],8, tmp, sizeof(tmp)));
			fprintf(ecmtxt, "cw1: %s\n", cs_hexdump(1,demux[0].lastcw[1],8, tmp, sizeof(tmp)));
			fclose(ecmtxt);
			ecmtxt = NULL;
		} else {
			fprintf(ecmtxt, "ECM information not found\n");
			fclose(ecmtxt);
		}
	}

	openxcas_busy = 0;

	int32_t i;
	for (i=0; i < MAX_DEMUX; i++) {
		if (er->rc >= E_NOTFOUND) {
			cs_debug_mask(D_DVBAPI, "cw not found");

			if (demux[i].pidindex==-1)
			  dvbapi_try_next_caid(i);

			openxcas_stop_filter(openxcas_stream_id, OPENXCAS_FILTER_ECM);
			openxcas_remove_filter(openxcas_stream_id, OPENXCAS_FILTER_ECM);

			unsigned char mask[12];
			unsigned char comp[12];
			memset(&mask, 0x00, sizeof(mask));
			memset(&comp, 0x00, sizeof(comp));

			mask[0] = 0xfe;
			comp[0] = 0x80;

			if (openxcas_add_filter(openxcas_stream_id, OPENXCAS_FILTER_ECM, 0, 0xffff, openxcas_ecm_pid, mask, comp, (void *)azbox_openxcas_ecm_callback) < 0) {
				cs_log(LOG_PREFIX "unable to add ecm filter (0)");
				if (openxcas_add_filter(openxcas_stream_id, OPENXCAS_FILTER_ECM, openxcas_caid, 0xffff, openxcas_ecm_pid, mask, comp, (void *)azbox_openxcas_ecm_callback) < 0)
					cs_log(LOG_PREFIX "unable to add ecm filter (%04x)", openxcas_caid);
				else
					cs_debug_mask(D_DVBAPI, LOG_PREFIX "ecm filter added, pid = %x, caid = %x", openxcas_ecm_pid, openxcas_caid);
			} else
				cs_debug_mask(D_DVBAPI, LOG_PREFIX "ecm filter added, pid = %x, caid = %x", openxcas_ecm_pid, 0);

			if (openxcas_start_filter(openxcas_stream_id, openxcas_seq, OPENXCAS_FILTER_ECM) < 0)
				cs_log(LOG_PREFIX "unable to start ecm filter");
			else
				cs_debug_mask(D_DVBAPI, LOG_PREFIX "ecm filter started");

			return;
		}
	}

	unsigned char nullcw[8];
	memset(nullcw, 0, 8);

	int32_t n;
	for (n=0;n<2;n++) {
		if (memcmp(er->cw + (n * 8), demux[0].lastcw[n], 8) && memcmp(er->cw + (n * 8), nullcw, 8)) {
			memcpy(demux[0].lastcw[n], er->cw + (n * 8), 8);
			memcpy(openxcas_cw + (n * 8), er->cw + (n * 8), 8);
		}
	}

	if (openxcas_set_key(openxcas_stream_id, openxcas_seq, 0, openxcas_cipher_idx, openxcas_cw, openxcas_cw + 8) != 1)
		cs_log(LOG_PREFIX "set cw failed");
	else
		cs_ddump_mask(D_DVBAPI, openxcas_cw, 16, LOG_PREFIX "write cws to descrambler");
}