예제 #1
0
static int
adbkbd_sysctl_right(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	struct adbkbd_softc *sc=(struct adbkbd_softc *)node.sysctl_data;
	const int *np = newp;
	int reg;

	DPRINTF("adbkbd_sysctl_right\n");
	reg = sc->sc_trans[2];
	if (np) {
		/* we're asked to write */	
		node.sysctl_data = ®
		if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
			
			sc->sc_trans[2] = *(int *)node.sysctl_data;
			return 0;
		}
		return EINVAL;
	} else {
		node.sysctl_data = ®
		node.sysctl_size = 4;
		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
	}
}
예제 #2
0
static int
adbkbd_sysctl_usb(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	struct adbkbd_softc *sc=(struct adbkbd_softc *)node.sysctl_data;
	const int *np = newp;
	bool reg;

	DPRINTF("%s\n", __func__);
	reg = sc->sc_emul_usb;
	if (np) {
		/* we're asked to write */	
		node.sysctl_data = ®
		if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
			
			sc->sc_emul_usb = *(bool *)node.sysctl_data;
			if (sc->sc_emul_usb) {
				wskbd_set_evtrans(sc->sc_wskbddev,
				    adb_to_usb, 128);
			} else {
				wskbd_set_evtrans(sc->sc_wskbddev, NULL, 0);
			}
			return 0;
		}
		return EINVAL;
	} else {
		node.sysctl_data = ®
		node.sysctl_size = sizeof(reg);
		return (sysctl_lookup(SYSCTLFN_CALL(&node)));
	}
}
예제 #3
0
/*
 * The sysctl hook that returns the available
 * algorithms.
 */
int
sysctl_portalgo_available(SYSCTLFN_ARGS)
{
	size_t ai, len = 0;
	struct sysctlnode node;
	char availalgo[NALGOS * PORTALGO_MAXLEN];

	DPRINTF("%s called\n", __func__);

	availalgo[0] = '\0';

	for (ai = 0; ai < NALGOS; ai++) {
		len = strlcat(availalgo, algos[ai].name, sizeof(availalgo));
		if (ai < NALGOS - 1)
			strlcat(availalgo, " ", sizeof(availalgo));
	}

	DPRINTF("available algos: %s\n", availalgo);

	node = *rnode;
	node.sysctl_data = availalgo;
	node.sysctl_size = len;

	return sysctl_lookup(SYSCTLFN_CALL(&node));
}
예제 #4
0
static int
sysctl_portalgo_reserve(SYSCTLFN_ARGS, bitmap *bt)
{
	struct sysctlnode node;
	int error;

	DPRINTF("%s called\n", __func__);

	node = *rnode;
	node.sysctl_data = bt;
	node.sysctl_size = sizeof(*bt);

	error = sysctl_lookup(SYSCTLFN_CALL(&node));

	if (error || newp == NULL)
		return error;

#ifdef KAUTH_NETWORK_SOCKET_PORT_RESERVE
	if (l != NULL && (error = kauth_authorize_system(l->l_cred,
	    KAUTH_NETWORK_SOCKET, KAUTH_NETWORK_SOCKET_PORT_RESERVE, bt,
	    NULL, NULL)) != 0)
		return error;
#endif
	return error;
}
예제 #5
0
/*
 * The sysctl hook that is supposed to check that we are picking one
 * of the valid algorithms.
 */
static int
sysctl_portalgo_selected(SYSCTLFN_ARGS, int *algo)
{
	struct sysctlnode node;
	int error;
	char newalgo[PORTALGO_MAXLEN];

	DPRINTF("%s called\n", __func__);

	strlcpy(newalgo, algos[*algo].name, sizeof(newalgo));

	node = *rnode;
	node.sysctl_data = newalgo;
	node.sysctl_size = sizeof(newalgo);

	error = sysctl_lookup(SYSCTLFN_CALL(&node));

	DPRINTF("newalgo: %s\n", newalgo);

	if (error || newp == NULL ||
	    strncmp(newalgo, algos[*algo].name, sizeof(newalgo)) == 0)
		return error;

#ifdef KAUTH_NETWORK_SOCKET_PORT_RANDOMIZE
	if (l != NULL && (error = kauth_authorize_system(l->l_cred,
	    KAUTH_NETWORK_SOCKET, KAUTH_NETWORK_SOCKET_PORT_RANDOMIZE, newname,
	    NULL, NULL)) != 0)
		return error;
#endif

	mutex_enter(softnet_lock);
	error = portalgo_algo_name_select(newalgo, algo);
	mutex_exit(softnet_lock);
	return error;
}
예제 #6
0
static int
sysctl_wmi_hp_set_als(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	int err;
	int als = wmihp_als;
	struct wmi_hp_softc *sc = wmi_hp_sc;

	node = *rnode;
	node.sysctl_data = &als;

	err = sysctl_lookup(SYSCTLFN_CALL(&node));

	if (err != 0 || newp == NULL)
		return err;;

	if (als < 0 || als > 1)
		return EINVAL;

	if (wmi_hp_method_write(sc, WMI_HP_METHOD_CMD_ALS, als) == true) {
		wmihp_als = als;
		return 0;
	}

	return EIO;
}
예제 #7
0
/* TBD factor with sysctl_ath_verify, sysctl_ieee80211_verify. */
static int
sysctl_ieee80211_rssadapt_expavgctl(SYSCTLFN_ARGS)
{
	struct ieee80211_rssadapt_expavgctl rc;
	int error;
	struct sysctlnode node;

	node = *rnode;
	rc = *(struct ieee80211_rssadapt_expavgctl *)rnode->sysctl_data;
	node.sysctl_data = &rc;
	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return (error);

	if (/* rc.rc_decay_old < 0 || */
	    rc.rc_decay_denom < rc.rc_decay_old)
		return (EINVAL);

	if (/* rc.rc_thresh_old < 0 || */
	    rc.rc_thresh_denom < rc.rc_thresh_old)
		return (EINVAL);

	if (/* rc.rc_avgrssi_old < 0 || */
	    rc.rc_avgrssi_denom < rc.rc_avgrssi_old)
		return (EINVAL);

	*(struct ieee80211_rssadapt_expavgctl *)rnode->sysctl_data = rc;

	return (0);
}
예제 #8
0
static int
gpiopwm_set_off(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	struct gpiopwm_softc *sc;
	int val, error;

	node = *rnode;
	sc = node.sysctl_data;

	callout_halt(&sc->sc_pulse, NULL);
	gpio_pin_write(sc->sc_gpio, &sc->sc_map, 0, GPIO_PIN_LOW);
	node.sysctl_data = &val;

	val = sc->sc_ticks_off;
	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return error;

	sc->sc_ticks_off = val;
	if (sc->sc_ticks_on > 0 && sc->sc_ticks_off > 0) {
		gpio_pin_write(sc->sc_gpio, &sc->sc_map, 0, GPIO_PIN_HIGH);
		callout_schedule(&sc->sc_pulse, sc->sc_ticks_on);
	}
	return 0;
}
예제 #9
0
파일: obio.c 프로젝트: ryo/netbsd-src
static int
sysctl_cpuspeed_temp(SYSCTLFN_ARGS)
{
    struct sysctlnode node = *rnode;
    struct obio_softc *sc = node.sysctl_data;
    int speed, mhz;

    speed = obio_get_cpu_speed(sc);
    switch (speed) {
    case 0:
        mhz = sc->sc_spd_lo;
        break;
    case 1:
        mhz = sc->sc_spd_hi;
        break;
    default:
        speed = -1;
    }
    node.sysctl_data = &mhz;
    if (sysctl_lookup(SYSCTLFN_CALL(&node)) == 0) {
        int new_reg;

        new_reg = *(int *)node.sysctl_data;
        if (new_reg == sc->sc_spd_lo) {
            obio_set_cpu_speed(sc, 0);
        } else if (new_reg == sc->sc_spd_hi) {
            obio_set_cpu_speed(sc, 1);
        } else {
            printf("%s: new_reg %d\n", __func__, new_reg);
            return EINVAL;
        }
        return 0;
    }
    return EINVAL;
}
예제 #10
0
static int
tegra_cpufreq_freq_helper(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	int fq, oldfq = 0, error;
	uint64_t xc;

	node = *rnode;
	node.sysctl_data = &fq;

	fq = cpufreq_get_rate();
	if (rnode->sysctl_num == cpufreq_node_target)
		oldfq = fq;

	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return error;

	if (fq == oldfq || rnode->sysctl_num != cpufreq_node_target)
		return 0;

	if (atomic_cas_uint(&cpufreq_busy, 0, 1) != 0)
		return EBUSY;

	error = cpufreq_set_rate(fq);
	if (error == 0) {
		xc = xc_broadcast(0, tegra_cpufreq_post, NULL, NULL);
		xc_wait(xc);
		pmf_event_inject(NULL, PMFE_SPEED_CHANGED);
	}

	atomic_dec_uint(&cpufreq_busy);

	return error;
}
예제 #11
0
static int
sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
{
        struct vfsconf vfc;
        extern const char * const mountcompatnames[];
        extern int nmountcompatnames;
	struct sysctlnode node;
	struct vfsops *vfsp;
	u_int vfsnum;

	if (namelen != 1)
		return (ENOTDIR);
	vfsnum = name[0];
	if (vfsnum >= nmountcompatnames ||
	    mountcompatnames[vfsnum] == NULL)
		return (EOPNOTSUPP);
	vfsp = vfs_getopsbyname(mountcompatnames[vfsnum]);
	if (vfsp == NULL)
		return (EOPNOTSUPP);

	vfc.vfc_vfsops = vfsp;
	strncpy(vfc.vfc_name, vfsp->vfs_name, sizeof(vfc.vfc_name));
	vfc.vfc_typenum = vfsnum;
	vfc.vfc_refcount = vfsp->vfs_refcount;
	vfc.vfc_flags = 0;
	vfc.vfc_mountroot = vfsp->vfs_mountroot;
	vfc.vfc_next = NULL;
	vfs_delref(vfsp);

	node = *rnode;
	node.sysctl_data = &vfc;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #12
0
파일: fujhk_acpi.c 프로젝트: ryo/netbsd-src
static int
fujitsu_hk_sysctl_backlight(SYSCTLFN_ARGS)
{
    struct sysctlnode node;
    struct fujitsu_hk_softc *sc;
    bool val;
    int error;

    node = *rnode;
    sc = node.sysctl_data;

    mutex_enter(&sc->sc_mtx);
    error = fujitsu_hk_get_backlight(sc, &val);
    mutex_exit(&sc->sc_mtx);

    if (error)
        return error;

    node.sysctl_data = &val;
    error = sysctl_lookup(SYSCTLFN_CALL(&node));
    if (error || newp == NULL)
        return error;

    mutex_enter(&sc->sc_mtx);
    error = fujitsu_hk_set_backlight(sc, val);
    mutex_exit(&sc->sc_mtx);

    return error;
}
예제 #13
0
static int
auich_sysctl_verify(SYSCTLFN_ARGS)
{
	int error, tmp;
	struct sysctlnode node;
	struct auich_softc *sc;

	node = *rnode;
	sc = rnode->sysctl_data;
	if (node.sysctl_num == sc->sc_ac97_clock_mib) {
		tmp = sc->sc_ac97_clock;
		node.sysctl_data = &tmp;
		error = sysctl_lookup(SYSCTLFN_CALL(&node));
		if (error || newp == NULL)
			return error;

		if (tmp < 48000 || tmp > 96000)
			return EINVAL;
		mutex_enter(&sc->sc_lock);
		sc->sc_ac97_clock = tmp;
		mutex_exit(&sc->sc_lock);
	}

	return 0;
}
예제 #14
0
static int
asus_sysctl_verify(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	struct asus_softc *sc;
	ACPI_INTEGER cfv;
	ACPI_STATUS rv;
	int err, tmp;

	node = *rnode;
	sc = rnode->sysctl_data;
	if (node.sysctl_num == sc->sc_cfv_mib) {
		rv = acpi_eval_integer(sc->sc_node->ad_handle,
		    ASUS_METHOD_CFVG, &cfv);
		if (ACPI_FAILURE(rv))
			return ENXIO;
		tmp = cfv & 0xff;
		node.sysctl_data = &tmp;
		err = sysctl_lookup(SYSCTLFN_CALL(&node));
		if (err || newp == NULL)
			return err;

		if (tmp < 0 || (uint64_t)tmp >= sc->sc_cfvnum)
			return EINVAL;

		rv = acpi_eval_set_integer(sc->sc_node->ad_handle,
		    ASUS_METHOD_CFVS, tmp);

		if (ACPI_FAILURE(rv))
			return ENXIO;
	}

	return 0;
}
예제 #15
0
파일: vmt.c 프로젝트: goroutines/rumprun
static int
vmt_sysctl_update_clock_sync_period(SYSCTLFN_ARGS)
{
	int error, period;
	struct sysctlnode node;
	struct vmt_softc *sc;

	node = *rnode;
	sc = (struct vmt_softc *)node.sysctl_data;

	period = sc->sc_clock_sync_period_seconds;
	node.sysctl_data = &period;
	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return error;

	if (sc->sc_clock_sync_period_seconds != period) {
		callout_halt(&sc->sc_clock_sync_tick, NULL);
		sc->sc_clock_sync_period_seconds = period;
		if (sc->sc_clock_sync_period_seconds > 0)
			callout_schedule(&sc->sc_clock_sync_tick,
			    mstohz(sc->sc_clock_sync_period_seconds * 1000));
	}
	return 0;
}
예제 #16
0
파일: ieee80211.c 프로젝트: MarginC/kame
/* TBD factor with sysctl_ath_verify. */
static int
sysctl_ieee80211_verify(SYSCTLFN_ARGS)
{
	int error, t;
	struct sysctlnode node;

	node = *rnode;
	t = *(int*)rnode->sysctl_data;
	node.sysctl_data = &t;
	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return (error);

	IEEE80211_DPRINTF(("%s: t = %d, nodenum = %d, rnodenum = %d\n",
	    __func__, t, node.sysctl_num, rnode->sysctl_num));

	if (node.sysctl_num == ieee80211_inact_max_nodenum) {
		if (t < 1)
			return (EINVAL);
		t = roundup(t, IEEE80211_INACT_WAIT) / IEEE80211_INACT_WAIT;
#ifdef IEEE80211_DEBUG
	} else if (node.sysctl_num == ieee80211_debug_nodenum) {
		if (t < 0 || t > 2)
			return (EINVAL);
#endif /* IEEE80211_DEBUG */
	} else
		return (EINVAL);

	*(int*)rnode->sysctl_data = t;

	return (0);
}
예제 #17
0
파일: if_tap.c 프로젝트: ryo/netbsd-src
/*
 * The helper functions make Andrew Brown's interface really
 * shine.  It makes possible to create value on the fly whether
 * the sysctl value is read or written.
 *
 * As shown as an example in the man page, the first step is to
 * create a copy of the node to have sysctl_lookup work on it.
 *
 * Here, we have more work to do than just a copy, since we have
 * to create the string.  The first step is to collect the actual
 * value of the node, which is a convenient pointer to the softc
 * of the interface.  From there we create the string and use it
 * as the value, but only for the *copy* of the node.
 *
 * Then we let sysctl_lookup do the magic, which consists in
 * setting oldp and newp as required by the operation.  When the
 * value is read, that means that the string will be copied to
 * the user, and when it is written, the new value will be copied
 * over in the addr array.
 *
 * If newp is NULL, the user was reading the value, so we don't
 * have anything else to do.  If a new value was written, we
 * have to check it.
 *
 * If it is incorrect, we can return an error and leave 'node' as
 * it is:  since it is a copy of the actual node, the change will
 * be forgotten.
 *
 * Upon a correct input, we commit the change to the ifnet
 * structure of our interface.
 */
static int
tap_sysctl_handler(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	struct tap_softc *sc;
	struct ifnet *ifp;
	int error;
	size_t len;
	char addr[3 * ETHER_ADDR_LEN];
	uint8_t enaddr[ETHER_ADDR_LEN];

	node = *rnode;
	sc = node.sysctl_data;
	ifp = &sc->sc_ec.ec_if;
	(void)ether_snprintf(addr, sizeof(addr), CLLADDR(ifp->if_sadl));
	node.sysctl_data = addr;
	error = sysctl_lookup(SYSCTLFN_CALL(&node));
	if (error || newp == NULL)
		return (error);

	len = strlen(addr);
	if (len < 11 || len > 17)
		return (EINVAL);

	/* Commit change */
	if (ether_aton_r(enaddr, sizeof(enaddr), addr) != 0)
		return (EINVAL);
	if_set_sadl(ifp, enaddr, ETHER_ADDR_LEN, false);
	return (error);
}
static int
acpi_debug_sysctl_level(SYSCTLFN_ARGS)
{
	char buf[ACPI_DEBUG_MAX];
	struct sysctlnode node;
	prop_object_t obj;
	int error;

	node = *rnode;
	node.sysctl_data = buf;

	(void)memcpy(node.sysctl_data, rnode->sysctl_data, ACPI_DEBUG_MAX);

	error = sysctl_lookup(SYSCTLFN_CALL(&node));

	if (error || newp == NULL)
		return error;

	obj = prop_dictionary_get(acpi_debug_level_d, node.sysctl_data);

	if (obj == NULL)
		return EINVAL;

	AcpiDbgLevel = prop_number_unsigned_integer_value(obj);

	(void)memcpy(rnode->sysctl_data, node.sysctl_data, ACPI_DEBUG_MAX);

	return 0;
}
예제 #19
0
static int
sysctl_hw_machine_arch(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	node.sysctl_data = l->l_proc->p_md.md_march;
	node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
	return sysctl_lookup(SYSCTLFN_CALL(&node));
}
예제 #20
0
static int
sysctl_machdep_cpu_arch(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	node.sysctl_data = __UNCONST(cpu_arch);
	node.sysctl_size = strlen(cpu_arch) + 1;
	return sysctl_lookup(SYSCTLFN_CALL(&node));
}
예제 #21
0
static int
sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;

	node.sysctl_data = some permutation on booted_kernel;
	node.sysctl_size = strlen(booted_kernel) + 1;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #22
0
/*
 * machine dependent system variables.
 */
#if 0	/* XXX - Not yet... */
static int
sysctl_machdep_root_device(SYSCTLFN_ARGS)
{
    struct sysctlnode node = *rnode;

    node.sysctl_data = some permutation on root_device;
    node.sysctl_size = strlen(root_device) + 1;
    return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #23
0
파일: machdep.c 프로젝트: ryo/netbsd-src
static int
sysctl_machdep_booted_device(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;

	if (booted_device == NULL)
		return (EOPNOTSUPP);
	node.sysctl_data = __UNCONST(device_xname(booted_device));
	node.sysctl_size = strlen(device_xname(booted_device)) + 1;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #24
0
파일: obio.c 프로젝트: ryo/netbsd-src
static int
sysctl_cpuspeed_available(SYSCTLFN_ARGS)
{
    struct sysctlnode node = *rnode;
    struct obio_softc *sc = node.sysctl_data;
    char buf[128];

    snprintf(buf, 128, "%d %d", sc->sc_spd_lo, sc->sc_spd_hi);
    node.sysctl_data = buf;
    return(sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #25
0
파일: pwmclock.c 프로젝트: ryo/netbsd-src
static int
pwmclock_cpuspeed_cur(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	struct pwmclock_softc *sc = node.sysctl_data;
	int mhz;

	mhz = sc->sc_scale[sc->sc_step];
	node.sysctl_data = &mhz;
	return sysctl_lookup(SYSCTLFN_CALL(&node));
}
예제 #26
0
파일: exynos_soc.c 프로젝트: ryo/netbsd-src
static int
sysctl_cpufreq_current(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	uint32_t freq;

	freq = exynos_get_cpufreq() / (1000*1000);
	node.sysctl_data = &freq;

	return sysctl_lookup(SYSCTLFN_CALL(&node));
}
예제 #27
0
/*
 * sysctl helper routine for netbsd32's vm.loadavg node
 */
static int
netbsd32_sysctl_vm_loadavg(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	struct netbsd32_loadavg av32;

	netbsd32_from_loadavg(&av32, &averunnable);

	node = *rnode;
	node.sysctl_data = &av32;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #28
0
/*
 * sysctl helper routine for netbsd32's kern.boottime node
 */
static int
netbsd32_sysctl_kern_boottime(SYSCTLFN_ARGS)
{
	struct sysctlnode node;
	struct netbsd32_timespec bt32;

	netbsd32_from_timespec(&boottime, &bt32);

	node = *rnode;
	node.sysctl_data = &bt32;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #29
0
static int
sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
{
	struct sysctlnode node;

	if (booted_kernel == NULL || booted_kernel[0] == '\0')
		return (EOPNOTSUPP);

	node = *rnode;
	node.sysctl_data = booted_kernel;
	node.sysctl_size = strlen(booted_kernel) + 1;
	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
}
예제 #30
0
파일: pwmclock.c 프로젝트: ryo/netbsd-src
static int
pwmclock_cpuspeed_available(SYSCTLFN_ARGS)
{
	struct sysctlnode node = *rnode;
	struct pwmclock_softc *sc = node.sysctl_data;
	char buf[128];

	snprintf(buf, 128, "%d %d %d %d %d %d %d", sc->sc_scale[1],
	    sc->sc_scale[2], sc->sc_scale[3], sc->sc_scale[4],
	    sc->sc_scale[5], sc->sc_scale[6], sc->sc_scale[7]);
	node.sysctl_data = buf;
	return(sysctl_lookup(SYSCTLFN_CALL(&node)));
}