Exemple #1
0
static afs_int32 do_eval_policy( unsigned int policyIndex, afs_uint64 size,
		    char *fileName, afs_int32 (*evalclient)(void*, afs_int32), void *client,
		     afs_uint32 *props)
{
    osddb_policy *pol = get_pol(policyIndex);
    afs_int32 tcode;
    int r;

    if ( !pol ) {
	ViceLog(0, ("failed to lookup policy %d\n", policyIndex));
	return ENOENT;
    }

    for ( r = 0 ; r < pol->rules.pol_ruleList_len ; r++ ) {
	pol_rule rule = pol->rules.pol_ruleList_val[r];
	int matched = 1;
	if ( rule.used_policy ) {
	    ViceLog(2, ("recursively evaluating policy %d\n", rule.used_policy));
	    tcode = do_eval_policy(
	    		rule.used_policy, size, fileName, evalclient, client, props);
	    ViceLog(2, ("recursion done, props are now 0x%x\n", *props));
	    if ( ( tcode && tcode != ENOENT ) || POLPROP_FORCE(*props) )
		return tcode;
	}
	else {
	    tcode = eval_condtree(&rule.condition, size, fileName, 
				    evalclient, client, &matched);
	    if ( tcode == EINVAL ) {
		ViceLog(0, ("policy %d may contain unknown predicate type\n",
								policyIndex));
	    }
	    if ( tcode )
		return tcode;
	    if ( matched ) {
		ViceLog(2, ("updating: props 0x%x with 0x%x\n", *props, rule.properties));
		UPDATE(POLPROP_LOCATION, POLICY_LOCATION_MASK);
		UPDATE(POLPROP_NSTRIPES, POLICY_NSTRIPES_MASK);
		UPDATE(POLPROP_SSTRIPES, POLICY_SSTRIPES_MASK);
		UPDATE(POLPROP_NCOPIES, POLICY_NCOPIES_MASK);
		UPDATE(POLPROP_FORCE, POLICY_CONT_OP_MASK);
		if ( POLPROP_FORCE(rule.properties) ) {
		    TRACE_POLICY(2);
		    return 0;
		}
	    }
	}
    }

    TRACE_POLICY(2);
    return 0;
}
Exemple #2
0
void display_policy_by_id(afs_uint32 id, int format, int unroll, struct ubik_client *uc)
{
    struct osddb_policy *pol;
    if ( uc )
	osddb_client = uc;
    pol = get_pol(id);

    if ( !pol ) {
	printf("\tpolicy(id=%d) not found in database!\n", id);
	return;
    }
    output_format = format;
    print_policy(pol, unroll);
}
Exemple #3
0
int dvb_tune(int aid, transponder * tp)
{
	int bclear, bpol, iProp = 0;
	adapter *ad = get_adapter(aid);
	int fd_frontend = ad->fe;

	int freq = tp->freq;
	struct dtv_property p_cmd[20];
	struct dtv_properties p =
	{ .num = 0, .props = p_cmd };
	struct dvb_frontend_event ev;

	struct dtv_property p_clear[] =
	{
	{ .cmd = DTV_CLEAR }, };

	struct dtv_properties cmdseq_clear =
	{ .num = 1, .props = p_clear };

	memset(p_cmd, 0, sizeof(p_cmd));
	bclear = getTick();

	if ((ioctl(fd_frontend, FE_SET_PROPERTY, &cmdseq_clear)) == -1)
	{
		LOG("FE_SET_PROPERTY DTV_CLEAR failed for fd %d: %s", fd_frontend,
				strerror(errno));
		//        return -1;
	}

	switch (tp->sys)
	{
	case SYS_DVBS:
	case SYS_DVBS2:

		bpol = getTick();
		freq = setup_switch(fd_frontend, tp);
		if (freq < MIN_FRQ_DVBS || freq > MAX_FRQ_DVBS)
			LOG_AND_RETURN(-404, "Frequency %d is not within range ", freq)

		ADD_PROP(DTV_SYMBOL_RATE, tp->sr)
		ADD_PROP(DTV_INNER_FEC, tp->fec)
		ADD_PROP(DTV_PILOT, tp->plts)
		ADD_PROP(DTV_ROLLOFF, tp->ro)
		ADD_PROP(DTV_STREAM_ID, tp->plp)

		LOG(
				"tuning to %d(%d) pol: %s (%d) sr:%d fec:%s delsys:%s mod:%s rolloff:%s pilot:%s, ts clear=%d, ts pol=%d",
				tp->freq, freq, get_pol(tp->pol), tp->pol, tp->sr,
				fe_fec[tp->fec], fe_delsys[tp->sys], fe_modulation[tp->mtype],
				fe_rolloff[tp->ro], fe_pilot[tp->plts], bclear, bpol)
		break;

	case SYS_DVBT:
	case SYS_DVBT2:

		if (tp->freq < MIN_FRQ_DVBT || tp->freq > MAX_FRQ_DVBT)
			LOG_AND_RETURN(-404, "Frequency %d is not within range ", tp->freq)

		freq = freq * 1000;
		ADD_PROP(DTV_BANDWIDTH_HZ, tp->bw)
		ADD_PROP(DTV_CODE_RATE_HP, tp->fec)
		ADD_PROP(DTV_CODE_RATE_LP, tp->fec)
		ADD_PROP(DTV_GUARD_INTERVAL, tp->gi)
		ADD_PROP(DTV_TRANSMISSION_MODE, tp->tmode)
		ADD_PROP(DTV_HIERARCHY, HIERARCHY_AUTO)
		ADD_PROP(DTV_STREAM_ID, tp->plp & 0xFF)

		LOG(
				"tuning to %d delsys: %s bw:%d inversion:%s mod:%s fec:%s guard:%s transmission: %s, ts clear = %d",
				freq, fe_delsys[tp->sys], tp->bw, fe_specinv[tp->inversion],
				fe_modulation[tp->mtype], fe_fec[tp->fec], fe_gi[tp->gi],
				fe_tmode[tp->tmode], bclear)
		break;

	case SYS_DVBC2:
	case SYS_DVBC_ANNEX_A:

		if (tp->freq < MIN_FRQ_DVBC || tp->freq > MAX_FRQ_DVBC)
			LOG_AND_RETURN(-404, "Frequency %d is not within range ", tp->freq)

		freq = freq * 1000;
		ADD_PROP(DTV_SYMBOL_RATE, tp->sr)
		ADD_PROP(DTV_STREAM_ID, ((tp->ds & 0xFF) << 8) | (tp->plp & 0xFF))
		// valid for DD DVB-C2 devices

		LOG("tuning to %d sr:%d specinv:%s delsys:%s mod:%s ts clear =%d", freq,
				tp->sr, fe_specinv[tp->inversion], fe_delsys[tp->sys],
				fe_modulation[tp->mtype], bclear)
		break;

	case SYS_ATSC:
	case SYS_DVBC_ANNEX_B:

		if (tp->freq < MIN_FRQ_DVBC || tp->freq > MAX_FRQ_DVBC)
			LOG_AND_RETURN(-404, "Frequency %d is not within range ", tp->freq)

		if (tp->mtype == 0)
			tp->mtype = QAM_AUTO;

		freq = freq * 1000;

		LOG("tuning to %d delsys:%s mod:%s specinv:%s ts clear=%d", freq,
				fe_delsys[tp->sys], fe_modulation[tp->mtype],
				fe_specinv[tp->inversion], bclear)

		break;

	case SYS_ISDBT:

		if (tp->freq < MIN_FRQ_DVBT || tp->freq > MAX_FRQ_DVBT)
			LOG_AND_RETURN(-404, "Frequency %d is not within range ", tp->freq)

		freq = freq * 1000;
		ADD_PROP(DTV_ISDBT_PARTIAL_RECEPTION, 0)
		ADD_PROP(DTV_BANDWIDTH_HZ, tp->bw)
//	    ADD_PROP(DTV_ISDBT_LAYERA_SEGMENT_COUNT,   1);  
//	    ADD_PROP(DTV_ISDBT_LAYER_ENABLED,   1); 

		LOG("tuning to %d delsys: %s bw:%d inversion:%s , ts clear = %d", freq,
				fe_delsys[tp->sys], tp->bw, fe_specinv[tp->inversion], bclear)
		;

		break;
	default:
		LOG("tuninng to unknown delsys: %s freq %s ts clear = %d", freq,
				fe_delsys[tp->sys], bclear)
		break;
	}

	ADD_PROP(DTV_FREQUENCY, freq)
	ADD_PROP(DTV_INVERSION, tp->inversion)
	ADD_PROP(DTV_MODULATION, tp->mtype);
	ADD_PROP(DTV_DELIVERY_SYSTEM, tp->sys);
	ADD_PROP(DTV_TUNE, 0)

	p.num = iProp;
	/* discard stale QPSK events */
	while (1)
	{
		if (ioctl(fd_frontend, FE_GET_EVENT, &ev) == -1)
			break;
	}

	if ((ioctl(fd_frontend, FE_SET_PROPERTY, &p)) == -1)
		if (ioctl(fd_frontend, FE_SET_PROPERTY, &p) == -1)
		{
			perror("FE_SET_PROPERTY TUNE failed");
			LOG("set property failed");
			return -404;
		}

	return 0;
}

int dvb_set_pid(adapter *a, uint16_t i_pid)
{
	char buf[100];
	int fd;
	int hw, ad;

	hw = a->pa;
	ad = a->fn;
	if (i_pid > 8192)
		LOG_AND_RETURN(-1, "pid %d > 8192 for /dev/dvb/adapter%d/demux%d",
				i_pid, hw, ad);

	sprintf(buf, "/dev/dvb/adapter%d/demux%d", hw, ad);
	if ((fd = open(buf, O_RDWR | O_NONBLOCK)) < 0)
	{
		LOG("Could not open demux device /dev/dvb/adapter%d/demux%d: %s ", hw,
				ad, strerror (errno));
		return -1;
	}

	struct dmx_pes_filter_params s_filter_params;

	memset(&s_filter_params, 0, sizeof(s_filter_params));
	s_filter_params.pid = i_pid;
	s_filter_params.input = DMX_IN_FRONTEND;
	s_filter_params.output = DMX_OUT_TS_TAP;
	s_filter_params.flags = DMX_IMMEDIATE_START;
	s_filter_params.pes_type = DMX_PES_OTHER;

	if (ioctl(fd, DMX_SET_PES_FILTER, &s_filter_params) < 0)
	{
		int pids[MAX_PIDS];
		int ep;
		ep = get_enabled_pids(a, (int *) pids, MAX_PIDS);
		LOG("failed setting filter on %d (%s), enabled pids %d", i_pid,
				strerror (errno), ep);
		return -1;
	}

	LOG("setting filter on PID %d for fd %d", i_pid, fd);

	return fd;
}
Exemple #4
0
void netcv_commit(adapter *ad)
{
	int i;

	int m_pos = 0;
	fe_type_t type;
	recv_sec_t m_sec;
	struct dvb_frontend_parameters m_fep;
	dvb_pid_t m_pids[MAX_PIDS];

	/* check if we have to create a receiver instance first */
	SN.err = 0;
	if (!SN.ncv_rec)
	{
		LOGL(0, "netceiver: add a new receiver instance for adapter %d", ad->id);

		/* call recv_add of libmcli to add a new receiver instance */
		SN.ncv_rec = recv_add();

		/* register handlers */
		register_ten_handler(SN.ncv_rec, &handle_ten, ad);
		register_ts_handler(SN.ncv_rec, &handle_ts, sn + ad->id);

		if (!SN.ncv_rec) SN.err = 1;

		SN.want_tune = 0; // wait until netcv_tune triggers the tuning
	}

	/* tune receiver to a new frequency / tranponder */
	if (SN.want_tune)
	{
		transponder *tp = &ad->tp;
		LOGL(0, "tuning to %d@%d pol: %s (%d) sr:%d fec:%s delsys:%s mod:%s (rolloff:%s) (pilot:%s)",
				tp->freq, tp->diseqc, get_pol(tp->pol), tp->pol, tp->sr,
				fe_fec[tp->fec], fe_delsys[tp->sys], fe_modulation[tp->mtype],
				fe_rolloff[tp->ro], fe_pilot[tp->plts]);

		int map_pos[] = { 0, 192, 130, 282, -50 }; // Default sat positions: 19.2E, 13E, 28.2E, 5W
		int map_pol[] = { 0, SEC_VOLTAGE_13, SEC_VOLTAGE_18, SEC_VOLTAGE_OFF };

		switch (tp->sys)
		{
			case SYS_DVBS:
			case SYS_DVBS2:
				m_pos = 1800 + map_pos[tp->diseqc];

				memset(&m_sec, 0, sizeof(recv_sec_t));
				m_sec.voltage = map_pol[tp->pol];

				memset(&m_fep, 0, sizeof(struct dvb_frontend_parameters));
				m_fep.frequency = tp->freq;
				m_fep.inversion = INVERSION_AUTO;
				m_fep.u.qpsk.symbol_rate = tp->sr;

				if (tp->sys == SYS_DVBS)
				{
					m_fep.u.qpsk.fec_inner = tp->fec;
					type = FE_QPSK;
				}
				else
				{
					// Für DVB-S2 PSK8 oder QPSK, siehe vdr-mcli-plugin/device.c
					if (tp->mtype)	m_fep.u.qpsk.fec_inner = tp->fec | (PSK8 << 16);
					else		m_fep.u.qpsk.fec_inner = tp->fec | (QPSK_S2 << 16);
					type = FE_DVBS2;
				}
				break;

				/* set roll-off */
				// TODO: check if needed for DVB-S2 transponders
				m_fep.u.qpsk.fec_inner |= (tp->ro << 24);


				break;

			case SYS_DVBC_ANNEX_A:
				m_pos = 0xfff; /* not sure, to be tested */
				memset(&m_sec, 0, sizeof(recv_sec_t));

				m_fep.frequency = tp->freq * 1000;
				m_fep.inversion = INVERSION_AUTO;
				m_fep.u.qam.fec_inner = FEC_NONE;
				m_fep.u.qam.modulation = tp->mtype;
				m_fep.u.qam.symbol_rate = tp->sr;

				type = FE_QAM;

				break;

			case SYS_DVBT:
				break;
		}

		memset(m_pids, 0, sizeof(m_pids));
		m_pids[0].pid=-1;

		/* call recv_tune of libmcli */
		if(recv_tune(SN.ncv_rec, type, m_pos, &m_sec, &m_fep, m_pids) != 0)
			LOGL(0, "netceiver: Tuning receiver failed");

		ad->strength = 0;
		ad->status = 0;
		ad->snr = 0;
		ad->ber = 0;

		SN.want_tune = 0;
	}

	/* activate or deactivate PIDs */
	if (SN.want_commit)
	{
		if (SN.lp)
		{
			char dbuf[1024] = "REEL: recv_pid: "; //debug

			memset(m_pids, 0, sizeof(m_pids));
			for(i = 0; i < SN.lp; i++)
			{
				sprintf(dbuf + strlen(dbuf), "[%04d]", SN.npid[i]);
				m_pids[i].pid = SN.npid[i];
				m_pids[i].id = 0; // here we maybe have to set the SID if this PID is encrypted

			}
			fprintf(stderr, "%s\n", dbuf);

			m_pids[i].pid = -1;
			/* call recv_pids of libmcli to set the active PIDs */
			if(recv_pids (SN.ncv_rec, m_pids))
				LOGL(0, "netceiver: seting PIDs failed");
		}
		else
		{
			fprintf(stderr, "REEL: recv_pid: none\n");
			/* call recv_stop of libmcli to deactivate all PIDs */
			if(recv_stop (SN.ncv_rec))
				LOGL(0, "netceiver: removing all PIDs failed");
		}

		SN.want_commit = 0;
	}

	return;
}
Exemple #5
0
int
edit_pol (SwitchPol * spol, AppData * a)
{
  uint32_t i, maxx;
  int state = 0;
  uint32_t num_strings;
  int lbl_x, idx = 0;
  MENU *my_menu;
  SwitchPol tmp;
  SwitchCmd *scmd;
  ITEM **my_items;
  char **mnu_str[2];
//      WINDOW * menu_win,*menu_sub;
  uint32_t num;

  spPolDeepCopy (&tmp, spol);
  num = tmp.num_cmds;
  scmd = tmp.cmds;

  message (a,
           "Modify Polarisation parameters or edit Commands.\nPress a to add a command, d to delete, press c to cancel");
  while (state >= 0)
  {
    num_strings = num + 1;
    state = 0;
    debugMsg ("allocating items\n");

    my_items = (ITEM **) utlCalloc (num_strings + 1, sizeof (ITEM *));

    mnu_str[0] = utlCalloc (num_strings, sizeof (char *));
    mnu_str[1] = utlCalloc (num_strings, sizeof (char *));

    debugMsg ("allocating items\n");
    mnu_str[0][0] = "Pol";
    mnu_str[1][0] = (char *) tpiGetPolStr (tmp.pol);
    my_items[0] = new_item (mnu_str[0][0], mnu_str[1][0]);

    for (i = 1; i < num_strings; ++i)
    {
      mnu_str[0][i] = utlCalloc (32, sizeof (char));
      mnu_str[1][i] = (char *) spGetCmdStr (scmd[i - 1].what);
      snprintf (mnu_str[0][i], 32, "Cmd%" PRIu32, i - 1);
      my_items[i] = new_item (mnu_str[0][i], mnu_str[1][i]);
      if (NULL == my_items[i])
      {
        if (errno == E_BAD_ARGUMENT)
          errMsg ("badarg i=%" PRIu32 "\n", i);
        if (errno == E_SYSTEM_ERROR)
          errMsg ("new_item: syserr i=%" PRIu32 "\n", i);
      }
    }
    my_items[num_strings] = (ITEM *) NULL;
    my_menu = new_menu ((ITEM **) my_items);
    set_menu_opts (my_menu,
                   O_ONEVALUE | O_NONCYCLIC | O_ROWMAJOR | O_SHOWDESC);
    maxx = getmaxx (stdscr);
    appDataMakeMenuWnd (my_menu);
    post_menu (my_menu);
    lbl_x = 3 + (maxx - 6) / 2 - strlen ("Pol") / 2;
    mvwprintw (menu_win (my_menu), 1, lbl_x, "%s", "Pol");
    wrefresh (menu_win (my_menu));
    debugMsg ("starting menu loop\n");
    while (state == 0)
    {
      int c;
      ITEM *selection;
      c = getch ();
      switch (c)
      {
      case 263:                //ESC
      case K_BACK:             //Backspace
        state = -1;
        break;
      case KEY_DOWN:
        menu_driver (my_menu, REQ_DOWN_ITEM);
        break;
      case KEY_UP:
        menu_driver (my_menu, REQ_UP_ITEM);
        break;
      case KEY_RESIZE:
        //windows need to be resized.. ignore
        break;
      case 'd':
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 1;
        break;
      case 'a':
        state = 2;
        break;
      case 'c':
        state = 3;
        break;
      case 13:                 //enter
        selection = current_item (my_menu);
        idx = item_index (selection);
        state = 5;
        break;
      default:
        break;
      }
      wrefresh (menu_win (my_menu));
    }
    unpost_menu (my_menu);
    appDataDestroyMenuWnd (my_menu);
    free_menu (my_menu);
    for (i = 0; i < num_strings; ++i)
    {
      free_item (my_items[i]);
    }
    for (i = 1; i < num_strings; ++i)
      utlFAN (mnu_str[0][i]);
    utlFAN (mnu_str[0]);
    utlFAN (mnu_str[1]);
    utlFAN (my_items);
    if (state > 0)
    {
      switch (state)
      {
      case 1:                  //del
        if (idx >= 1)
          spCmdDel (&scmd, &num, idx - 1);
        break;
      case 2:                  //add(at the end)
        spCmdAdd (&scmd, &num, num);
        break;
      case 3:                  //cancel
        spPolClear (&tmp);      //clear temporary
        return 1;
      case 5:                  //edit
        if (idx >= 1)
          edit_cmd (scmd + idx - 1, a);
        else
        {
          int rv;
          rv = get_pol (a);
          if (rv >= 0)
            tmp.pol = rv;
        }
        break;
      default:
        break;
      }
    }
  }
  spPolClear (spol);            //clear original
  *spol = tmp;                  //replace with temporary
  return 0;
}
Exemple #6
0
void print_policy(struct osddb_policy *pol, int unroll)
{
    int r = 1;
    char buf[1024];

    for ( r = 0 ; r < pol->rules.pol_ruleList_len ; r++ ) {
	pol_rule rule = pol->rules.pol_ruleList_val[r];
	int copies = POLPROP_NCOPIES(rule.properties);
	int stripes = POLPROP_NSTRIPES(rule.properties);
	int use_osd = POLPROP_OSD(rule.properties);
	int use_local = POLPROP_LOCAL(rule.properties);
	int use_dynamic = POLPROP_DYNAMIC(rule.properties);
	int force = POLPROP_FORCE(rule.properties);
	int log2size = POLPROP_SSTRIPES(rule.properties);

	if ( !rule.used_policy ) {
	    if ( rule.condition.type != POLCOND_TRUE ) {
		condtree_to_string(&rule.condition, buf, NULL,
		    predicate_printers[output_format], 
		    operator_strings[output_format]);
		printf(predicate_formats[output_format], buf);
	    }
	    else
		printf("%s", empty_predicate[output_format]);

	    if ( output_format == POL_OUTPUT_TABULAR ) printf("[");
	    if ( use_osd || use_local || use_dynamic ) {
		printf(location_format[output_format],
			    use_osd ? string_osd[output_format]
			    : use_local ? string_local[output_format]
			    : string_dynamic[output_format]);
		if ( stripes || log2size || copies )
		    printf("%s", seperator[output_format]);
	    }
	    if ( output_format == POL_OUTPUT_TABULAR ) printf(",");
	    if ( stripes ) {
		printf(stripes_format[output_format], stripes);
		if ( log2size || copies ) printf("%s", seperator[output_format]);
	    }
	    if ( output_format == POL_OUTPUT_TABULAR ) printf(",");
	    if ( log2size ) {
		printf(ssize_format[output_format], log2size);
		if ( copies ) printf("%s", seperator[output_format]);
	    }
	    if ( output_format == POL_OUTPUT_TABULAR ) printf(",");
	    if ( copies )
		printf(copies_format[output_format], copies);
	    if ( output_format == POL_OUTPUT_TABULAR ) printf("] ");
	    if ( force || output_format != POL_OUTPUT_LONG )
		printf("%s", seperator[output_format]);
	    printf("%s", force ? stop_string[output_format]
			       : continue_string[output_format]);
	    printf("%s", ending[output_format]);
	}
	else
	    if ( unroll ) {
		struct osddb_policy *inner_policy = get_pol(rule.used_policy);
		if ( !inner_policy ) {
		    printf("\tpolicy(id=%d) not found!\n", rule.used_policy);
		    continue;
		}
		print_policy(inner_policy, 1);
	    }
	    else switch(output_format) {
		case 0:
		case 1:
		    printf("\tuse the rules from policy %d\n",rule.used_policy);
		    break;
		default:
		    printf("\tuse(%d);\n", rule.used_policy);
		    break;
	    }
    }
}