Ejemplo n.º 1
0
void initialize_log (void) {
    if (strncmp( CONF("LogFacility"), "syslog", 6 ) == 0) {
        openlog( CONF("SyslogIdent"), LOG_CONS | LOG_PID, LOG_DAEMON );
        g_log_set_handler( NULL,
                           G_LOG_LEVEL_MASK | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL,
                           g_syslog, NULL );
    }
}
Ejemplo n.º 2
0
int main (int argc, char **argv) {
    GMainLoop  *loop;
    GIOChannel *sock;

    /* Initialize signal handlers */
    signal(SIGPIPE, SIG_IGN);
    signal(SIGINT,  handle_sigint);

    /* read nocat.conf */
    read_conf_file( NC_CONF_PATH "/nocat.conf" );

    initialize_driver();

    /* initialize the firewall */
    fw_init( nocat_conf );

    /* initialize the peer table */
    peer_tab = g_hash_new();

    /* initialize the listen socket */
    sock = http_bind_socket( 
	    CONF("GatewayAddr"), CONFd("GatewayPort"), CONFd("ListenQueue") );

    /* initialize the main loop and handlers */
    loop = g_main_new(FALSE);
    g_io_add_watch( sock, G_IO_IN,  (GIOFunc) handle_accept, NULL );
    g_timeout_add( 30000, (GSourceFunc) check_peers, NULL );
    g_timeout_add( 1000, (GSourceFunc) check_sigint, loop );
    
    /* Go! */
    g_message("starting main loop");
    g_main_run( loop );
    g_message("exiting main loop");
    return 0;
}
Ejemplo n.º 3
0
void
Profile::SetDeviceConfig(unsigned n, const DeviceConfig &config)
{
  TCHAR buffer[64];

  WritePortType(n, config.port_type);

  MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index"));
  Set(buffer, config.port_index);

  MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index"));
  Set(buffer, config.speed_index);

  _tcscpy(buffer, CONF("DeviceA"));
  buffer[_tcslen(buffer) - 1] += n;
  Set(buffer, config.driver_name);
}
Ejemplo n.º 4
0
static void i80286_data_descriptor_full(i80286_state *cpustate, int reg, UINT16 selector, int cpl, UINT32 trap, UINT16 offset, int size)
{
	if (PM) {
		UINT16 desc[3];
		UINT8 r;
		UINT32 addr;
		/* selector format
           15..3 number/address in descriptor table
           2: 0 global, 1 local descriptor table
           1,0: requested privileg level
           must be higher or same as current privileg level in code selector */
		if ((reg != SS) && !IDXTBL(selector)) {
			cpustate->sregs[reg]=0;
			cpustate->limit[reg]=0;
			cpustate->base[reg]=0;
			cpustate->rights[reg]=0;
			cpustate->valid[reg]=0;
			return;
		}

		if ((addr = i80286_selector_address(cpustate,selector)) == -1) throw trap;

		desc[0] = ReadWord(addr);
		desc[1] = ReadWord(addr+2);
		desc[2] = ReadWord(addr+4);
		r = RIGHTS(desc);
		if (!SEGDESC(r)) throw trap;
		if (reg == SS) {
			if (!IDXTBL(selector)) throw trap;
			if (DPL(r)!=cpl) throw trap;
			if (RPL(selector)!=cpl) throw trap;
			if (!RW(r) || CODE(r)) throw trap;
			if (!PRES(r)) throw TRAP(STACK_FAULT,(IDXTBL(selector)+(trap&1)));
		} else {
			if ((DPL(r) < PMAX(cpl,RPL(selector))) && (!CODE(r) || (CODE(r) && !CONF(r)))) throw trap;
			if (CODE(r) && !READ(r)) throw trap;
			if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(selector)+(trap&1)));
		}
		if (offset+size) {
			if ((CODE(r) || !EXPDOWN(r)) && ((offset+size-1) > LIMIT(desc))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap;
			if (!CODE(r) && EXPDOWN(r) && ((offset <= LIMIT(desc)) || ((offset+size-1) > 0xffff))) throw (reg==SS)?TRAP(STACK_FAULT,(trap&1)):trap;
		}

		SET_ACC(desc);
		WriteWord(addr+4, desc[2]);
		cpustate->sregs[reg]=selector;
		cpustate->limit[reg]=LIMIT(desc);
		cpustate->base[reg]=BASE(desc);
		cpustate->rights[reg]=RIGHTS(desc);
	} else {
		cpustate->sregs[reg]=selector;
		cpustate->base[reg]=selector<<4;
	}
	cpustate->valid[reg]=1;
}
Ejemplo n.º 5
0
static enum DeviceConfig::port_type
ReadPortType(unsigned n)
{
  TCHAR name[64], value[64];

  MakeDeviceSettingName(name, CONF("Port"), n, _T("Type"));
  if (!Profile::Get(name, value, sizeof(value) / sizeof(value[0])))
    return DeviceConfig::SERIAL;

  return StringToPortType(value);
}
Ejemplo n.º 6
0
static bool
WritePortType(unsigned n, enum DeviceConfig::port_type type)
{
  const TCHAR *value = PortTypeToString(type);
  if (value == NULL)
    return false;

  TCHAR name[64];

  MakeDeviceSettingName(name, CONF("Port"), n, _T("Type"));
  return Profile::Set(name, value);
}
Ejemplo n.º 7
0
void
Profile::GetDeviceConfig(unsigned n, DeviceConfig &config)
{
  TCHAR buffer[64];
  unsigned Temp = 0;

  config.port_type = ReadPortType(n);

  MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index"));
  if (Get(buffer, Temp))
    config.port_index = Temp;
  else if (is_altair() && n == 0)
    config.port_index = 2;
  else if (is_altair() && n == 2)
    config.port_index = 1;
  else
    config.port_index = 0;

  MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index"));
  if (Get(buffer, Temp))
    config.speed_index = Temp;
  else if (is_altair())
    config.speed_index = 5;
  else
    config.speed_index = 2;

  _tcscpy(buffer, CONF("DeviceA"));
  buffer[_tcslen(buffer) - 1] += n;
  if (!Get(buffer, config.driver_name,
           sizeof(config.driver_name) / sizeof(config.driver_name[0]))) {
    if (is_altair() && n == 0)
      _tcscpy(config.driver_name, _T("Altair RU"));
    else if (is_altair() && n == 1)
      _tcscpy(config.driver_name, _T("Vega"));
    else if (is_altair() && n == 2)
      _tcscpy(config.driver_name, _T("NmeaOut"));
    else
      config.driver_name[0] = '\0';
  }
}
Ejemplo n.º 8
0
void
Profile::GetDeviceConfig(unsigned n, DeviceConfig &config)
{
  TCHAR buffer[64];
  unsigned Temp = 0;

  config.port_type = ReadPortType(n);

  MakeDeviceSettingName(buffer, CONF("Port"), n, _T("Index"));
  if (Get(buffer, Temp))
    config.port_index = Temp;

  MakeDeviceSettingName(buffer, CONF("Speed"), n, _T("Index"));
  if (Get(buffer, Temp))
    config.speed_index = Temp;

  config.driver_name[0] = '\0';

  _tcscpy(buffer, CONF("DeviceA"));
  buffer[_tcslen(buffer) - 1] += n;
  Get(buffer, config.driver_name,
      sizeof(config.driver_name) / sizeof(config.driver_name[0]));
}
Ejemplo n.º 9
0
/* XXX: You must hold "conf->lock" when calling this function! */
static int camqp_write_locked (camqp_config_t *conf, /* {{{ */
        const char *buffer, const char *routing_key)
{
    amqp_basic_properties_t props;
    int status;

    status = camqp_connect (conf);
    if (status != 0)
        return (status);

    memset (&props, 0, sizeof (props));
    props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG
        | AMQP_BASIC_DELIVERY_MODE_FLAG
        | AMQP_BASIC_APP_ID_FLAG;
    if (conf->format == CAMQP_FORMAT_COMMAND)
        props.content_type = amqp_cstring_bytes("text/collectd");
    else if (conf->format == CAMQP_FORMAT_JSON)
        props.content_type = amqp_cstring_bytes("application/json");
    else if (conf->format == CAMQP_FORMAT_GRAPHITE)
        props.content_type = amqp_cstring_bytes("text/graphite");
    else
        assert (23 == 42);
    props.delivery_mode = conf->delivery_mode;
    props.app_id = amqp_cstring_bytes("collectd");

    status = amqp_basic_publish(conf->connection,
                /* channel = */ 1,
                amqp_cstring_bytes(CONF(conf, exchange)),
                amqp_cstring_bytes (routing_key),
                /* mandatory = */ 0,
                /* immediate = */ 0,
                &props,
                amqp_cstring_bytes(buffer));
    if (status != 0)
    {
        ERROR ("amqp plugin: amqp_basic_publish failed with status %i.",
                status);
        camqp_close_connection (conf);
    }

    return (status);
} /* }}} int camqp_write_locked */
Ejemplo n.º 10
0
int main (int argc, char **argv) {
    GMainLoop  *loop;
    GIOChannel *sock;

    /* read nocat.conf */
    read_conf_file( NC_CONF_PATH "/nocat.conf" );

    if (argc < 2 || strncmp(argv[1], "-D", 2) != 0)
        daemonize();

    /* initalize the log */
    initialize_log();

    /* set network parameters */
    set_network_defaults( nocat_conf );

    /* initialize the gateway type driver */
    initialize_driver();

    /* initialize the firewall */
    fw_init( nocat_conf );

    /* initialize the peer table */
    peer_tab = g_hash_new();

    /* initialize the listen socket */
    sock = http_bind_socket(
               CONF("GatewayAddr"), CONFd("GatewayPort"), CONFd("ListenQueue") );

    /* initialize the main loop and handlers */
    loop = g_main_new(FALSE);
    g_io_add_watch( sock, G_IO_IN,  (GIOFunc) handle_accept, NULL );
    g_timeout_add( 30000, (GSourceFunc) check_peers, NULL );
    g_timeout_add( 1000, (GSourceFunc) check_exit_signal, loop );

    /* Go! */
    g_message("starting main loop");
    g_main_run( loop );
    g_message("exiting main loop");
    return 0;
}
Ejemplo n.º 11
0
int
Profile::GetScaleList(fixed *List, size_t Size)
{
  static const TCHAR Name[] = CONF("ScaleList");
  TCHAR Buffer[128];
  int Idx = 0;
  double vlast = 0;
  double val;

  assert(List != NULL);
  assert(Size > 0);

  Set(Name, _T("0.5,1,2,5,10,20,50,100,150,200,500,1000"));

  if (!Get(Name, Buffer, sizeof(Buffer) / sizeof(TCHAR)))
    return 0;

  const TCHAR *p = Buffer;
  while (Idx < (int)Size) {
    TCHAR *endptr;
    val = _tcstod(p, &endptr);
    if (Idx > 0) {
      List[Idx] = fixed(val + vlast) / 2;
      Idx++;
    }
    List[Idx] = fixed(val);
    Idx++;
    vlast = val;

    if (endptr == p)
      return 0;
    else if (*endptr == _T('\0'))
      break;
    else if (*endptr != _T(','))
      return 0;

    p = endptr + 1;
  }

  return Idx;
}
Ejemplo n.º 12
0
static UINT16 i80286_far_return(i8086_state *cpustate, int iret, int bytes)
{
	UINT16 sel, off, flags = 0;
	int spaddr;

	if (PM && NT && iret) {
		i80286_switch_task(cpustate, ReadWord(cpustate->tr.base+TSS_BACK*2), IRET);
		return cpustate->flags;
	}

	// must be restartable
	if(PM) i80286_check_permission(cpustate, SS, cpustate->regs.w[SP], (iret?6:4), I80286_READ);
	spaddr = (cpustate->base[SS] + cpustate->regs.w[SP]) & AMASK;
	off = ReadWord(spaddr);
	sel = ReadWord(spaddr+2);
	if(iret) flags = ReadWord(spaddr+4);

	if(PM) {
		UINT16 desc[3], newsp, newss;
		int addr, r;

		if ((addr = i80286_selector_address(cpustate,sel)) == -1)
			throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));

		if (RPL(sel)<CPL) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
		desc[0] = ReadWord(addr);
		desc[1] = ReadWord(addr+2);
		desc[2] = ReadWord(addr+4);
		r = RIGHTS(desc);

		if (!CODE(r) || !SEGDESC(r)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
		if (CONF(r)) { if(DPL(r)>RPL(sel)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel)); }
		else if (DPL(r)!=RPL(sel)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));

		if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(sel));
		if (off > LIMIT(desc)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
		if (CPL<RPL(sel)) {
			i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]+(iret?6:4)+bytes, 4, I80286_READ);
			newsp = ReadWord(spaddr+((iret?6:4)+bytes));
			newss = ReadWord(spaddr+((iret?8:6)+bytes));
			i80286_data_descriptor_full(cpustate, SS, newss, RPL(sel), TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(newss)), 0, 0);
			cpustate->regs.w[SP] = newsp + bytes;
		} else cpustate->regs.w[SP] += (iret?6:4) + bytes;
		SET_ACC(desc);
		WriteWord(addr+4, desc[2]);
		cpustate->sregs[CS]=sel;
		cpustate->limit[CS]=LIMIT(desc);
		cpustate->base[CS]=BASE(desc);
		cpustate->rights[CS]=RIGHTS(desc);
		cpustate->pc=(cpustate->base[CS]+off)&AMASK;

		// docs say check rpl but windows doesn't like it
		r = cpustate->rights[DS];
		if (i80286_verify(cpustate, cpustate->sregs[DS], I80286_READ, r, 0) || (CODE(r) && CONF(r) ? 0 : (DPL(r) < CPL)))
			i80286_data_descriptor(cpustate, DS, 0);
		r = cpustate->rights[ES];
		if (i80286_verify(cpustate, cpustate->sregs[ES], I80286_READ, r, 0) || (CODE(r) && CONF(r) ? 0 : (DPL(r) < CPL)))
			i80286_data_descriptor(cpustate, ES, 0);
	} else {
		cpustate->regs.w[SP] += (iret?6:4) + bytes;
		cpustate->sregs[CS]=sel;
		cpustate->base[CS]=sel<<4;
		cpustate->rights[CS]=0x9a;
		cpustate->limit[CS]=0xffff;
		cpustate->pc=(cpustate->base[CS]+off)&AMASK;
	}
	CHANGE_PC(cpustate->pc);

	return flags;
}
Ejemplo n.º 13
0
static int camqp_connect (camqp_config_t *conf) /* {{{ */
{
    amqp_rpc_reply_t reply;
    int sockfd;
    int status;

    if (conf->connection != NULL)
        return (0);

    conf->connection = amqp_new_connection ();
    if (conf->connection == NULL)
    {
        ERROR ("amqp plugin: amqp_new_connection failed.");
        return (ENOMEM);
    }

    sockfd = amqp_open_socket (CONF(conf, host), conf->port);
    if (sockfd < 0)
    {
        char errbuf[1024];
        status = (-1) * sockfd;
        ERROR ("amqp plugin: amqp_open_socket failed: %s",
                sstrerror (status, errbuf, sizeof (errbuf)));
        amqp_destroy_connection (conf->connection);
        conf->connection = NULL;
        return (status);
    }
    amqp_set_sockfd (conf->connection, sockfd);

    reply = amqp_login (conf->connection, CONF(conf, vhost),
            /* channel max = */      0,
            /* frame max   = */ 131072,
            /* heartbeat   = */      0,
            /* authentication = */ AMQP_SASL_METHOD_PLAIN,
            CONF(conf, user), CONF(conf, password));
    if (reply.reply_type != AMQP_RESPONSE_NORMAL)
    {
        ERROR ("amqp plugin: amqp_login (vhost = %s, user = %s) failed.",
                CONF(conf, vhost), CONF(conf, user));
        amqp_destroy_connection (conf->connection);
        close (sockfd);
        conf->connection = NULL;
        return (1);
    }

    amqp_channel_open (conf->connection, /* channel = */ 1);
    /* FIXME: Is checking "reply.reply_type" really correct here? How does
     * it get set? --octo */
    if (reply.reply_type != AMQP_RESPONSE_NORMAL)
    {
        ERROR ("amqp plugin: amqp_channel_open failed.");
        amqp_connection_close (conf->connection, AMQP_REPLY_SUCCESS);
        amqp_destroy_connection (conf->connection);
        close(sockfd);
        conf->connection = NULL;
        return (1);
    }

    INFO ("amqp plugin: Successfully opened connection to vhost \"%s\" "
            "on %s:%i.", CONF(conf, vhost), CONF(conf, host), conf->port);

    status = camqp_create_exchange (conf);
    if (status != 0)
        return (status);

    if (!conf->publish)
        return (camqp_setup_queue (conf));
    return (0);
} /* }}} int camqp_connect */
Ejemplo n.º 14
0
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
}
*/

#include "Sizes.h"
#include "Defines.h"
#include "ProfileKeys.hpp"

#define REGKEYNAME  "Software\\MPSR\\XCSoar"

const TCHAR szProfileKey[] = CONF(REGKEYNAME);
const TCHAR *szProfileDisplayType[MAXINFOWINDOWS] = {
  CONF("Info0"),
  CONF("Info1"),
  CONF("Info2"),
  CONF("Info3"),
  CONF("Info4"),
  CONF("Info5"),
  CONF("Info6"),
  CONF("Info7"),
  CONF("Info8"),
  CONF("Info9"),
  CONF("Info10"),
  CONF("Info11"),
  CONF("Info12"),
  CONF("Info13"),
Ejemplo n.º 15
0
void
setconfig (char *name, char *value, struct config_data *cfg)
{
	int len, dstlen;
	void *src, *dst;
	char tmpname[128];
	int i;

#define CONF0(NAMESTR, CFG) \
	setdst (name, NAMESTR, &CFG, sizeof CFG, &dst, &dstlen)
#define CONF(NAME) \
	CONF0 (#NAME, cfg->NAME)
#define CONF1(NAMEFMT, ARG1, CFG) \
	snprintf (tmpname, sizeof tmpname, NAMEFMT, ARG1), \
	CONF0 (tmpname, CFG)

	name = strdup (name);
	len = strlen (value);
	src = strdup (value);
	dst = NULL;
	dstlen = 0;
	/* idman */
	ss (file, &name, &src, &len, "idman.crl01File", "idman.crl01");
	ss (file, &name, &src, &len, "idman.crl02File", "idman.crl02");
	ss (file, &name, &src, &len, "idman.crl03File", "idman.crl03");
	ss (file, &name, &src, &len, "idman.pkc01File", "idman.pkc01");
	ss (file, &name, &src, &len, "idman.pkc02File", "idman.pkc02");
	ss (file, &name, &src, &len, "idman.pkc03File", "idman.pkc03");
	ss (uintnum, &name, &src, &len, "idman.randomSeedSize",
	    "idman.randomSeedSize");
	ss (uintnum, &name, &src, &len, "idman.maxPinLen", "idman.maxPinLen");
	ss (uintnum, &name, &src, &len, "idman.minPinLen", "idman.minPinLen");
	ss (authmethod, &name, &src, &len, "idman.authenticationMethod",
	    "idman.authenticationMethod");
	/* VPN */
	ss (file, &name, &src, &len, "vpn.vpnCertFileV4", "vpn.vpnCertV4");
	ss (file, &name, &src, &len, "vpn.vpnCaCertFileV4", "vpn.vpnCaCertV4");
	ss (file, &name, &src, &len, "vpn.vpnRsaKeyFileV4", "vpn.vpnRsaKeyV4");
	ss (file, &name, &src, &len, "vpn.vpnCertFileV6", "vpn.vpnCertV6");
	ss (file, &name, &src, &len, "vpn.vpnCaCertFileV6", "vpn.vpnCaCertV6");
	ss (file, &name, &src, &len, "vpn.vpnRsaKeyFileV6", "vpn.vpnRsaKeyV6");
	/* storage */
	for (i = 0; i < NUM_OF_STORAGE_KEYS; i++)
		ssi (keyplace, &name, &src, &len,
		     "storage.encryptionKey%d.place", "storage.keys[%d]", i);
	for (i = 0; i < NUM_OF_STORAGE_KEYS_CONF; i++) {
		ssi (storage_conf_guid, &name, &src, &len,
		     "storage.conf%d.guid", "storage.keys_conf[%d].guid", i);
		ssi (storage_conf_type, &name, &src, &len,
		     "storage.conf%d.type", "storage.keys_conf[%d].type", i);
		ssi (u8num, &name, &src, &len, "storage.conf%d.host_id",
		     "storage.keys_conf[%d].host_id", i);
		ssi (u16num, &name, &src, &len, "storage.conf%d.device_id",
		     "storage.keys_conf[%d].device_id", i);
		ssi (u64num, &name, &src, &len, "storage.conf%d.lba_low",
		     "storage.keys_conf[%d].lba_low", i);
		ssi (u64num, &name, &src, &len, "storage.conf%d.lba_high",
		     "storage.keys_conf[%d].lba_high", i);
		ssi (noconv, &name, &src, &len, "storage.conf%d.crypto_name",
		     "storage.keys_conf[%d].crypto_name", i);
		ssi (u8num, &name, &src, &len, "storage.conf%d.keyindex",
		     "storage.keys_conf[%d].keyindex", i);
		ssi (u16num, &name, &src, &len, "storage.conf%d.keybits",
		     "storage.keys_conf[%d].keybits", i);
		ssi (noconv, &name, &src, &len, "storage.conf%d.extend",
		     "storage.keys_conf[%d].extend", i);
	}
	/* vmm */
	ss (uintnum, &name, &src, &len, "vmm.f11panic", "vmm.f11panic");
	ss (uintnum, &name, &src, &len, "vmm.f12msg", "vmm.f12msg");
	ss (uintnum, &name, &src, &len, "vmm.auto_reboot", "vmm.auto_reboot");
	ss (uintnum, &name, &src, &len, "vmm.shell", "vmm.shell");
	ss (uintnum, &name, &src, &len, "vmm.dbgsh", "vmm.dbgsh");
	ss (uintnum, &name, &src, &len, "vmm.status", "vmm.status");
	ss (uintnum, &name, &src, &len, "vmm.boot_active", "vmm.boot_active");
	ss (uintnum, &name, &src, &len, "vmm.tty_pro1000", "vmm.tty_pro1000");
	ss (mac_addr, &name, &src, &len, "vmm.tty_pro1000_mac_address",
	    "vmm.tty_pro1000_mac_address");
	ss (uintnum, &name, &src, &len, "vmm.tty_rtl8169", "vmm.tty_rtl8169");
	ss (mac_addr, &name, &src, &len, "vmm.tty_rtl8169_mac_address",
	    "vmm.tty_rtl8169_mac_address");
	ss (uintnum, &name, &src, &len, "vmm.driver.ata", "vmm.driver.ata");
	ss (uintnum, &name, &src, &len, "vmm.driver.usb.uhci", "vmm.driver.usb.uhci");
	ss (uintnum, &name, &src, &len, "vmm.driver.usb.ehci", "vmm.driver.usb.ehci");
	ss (uintnum, &name, &src, &len, "vmm.driver.concealEHCI",
	    "vmm.driver.concealEHCI");
	ss (uintnum, &name, &src, &len, "vmm.driver.conceal1394",
	    "vmm.driver.conceal1394");
	ss (uintnum, &name, &src, &len, "vmm.driver.concealPRO1000",
	    "vmm.driver.concealPRO1000");
	ss (uintnum, &name, &src, &len, "vmm.driver.vpn.PRO100",
	    "vmm.driver.vpn.PRO100");
	ss (uintnum, &name, &src, &len, "vmm.driver.vpn.PRO1000",
	    "vmm.driver.vpn.PRO1000");
	ss (uintnum, &name, &src, &len, "vmm.driver.vpn.RTL8169",
	    "vmm.driver.vpn.RTL8169");
	ss (uintnum, &name, &src, &len, "vmm.driver.vpn.ve",
	    "vmm.driver.vpn.ve");
	ss (uintnum, &name, &src, &len, "vmm.iccard.enable",
	    "vmm.iccard.enable");
	ss (uintnum, &name, &src, &len, "vmm.iccard.status",
	    "vmm.iccard.status");
	/* idman */
	CONF (idman.crl01);
	CONF (idman.crl02);
	CONF (idman.crl03);
	CONF (idman.pkc01);
	CONF (idman.pkc02);
	CONF (idman.pkc03);
	CONF (idman.randomSeedSize);
	CONF (idman.maxPinLen);
	CONF (idman.minPinLen);
	CONF (idman.authenticationMethod);
	/* VPN */
	CONF (vpn.mode);
	CONF (vpn.virtualGatewayMacAddress);
	CONF (vpn.bindV4);
	CONF (vpn.guestIpAddressV4);
	CONF (vpn.guestIpSubnetV4);
	CONF (vpn.guestMtuV4);
	CONF (vpn.guestVirtualGatewayIpAddressV4);
	CONF (vpn.dhcpV4);
	CONF (vpn.dhcpLeaseExpiresV4);
	CONF (vpn.dhcpDnsV4);
	CONF (vpn.dhcpDomainV4);
	CONF (vpn.adjustTcpMssV4);
	CONF (vpn.hostIpAddressV4);
	CONF (vpn.hostIpSubnetV4);
	CONF (vpn.hostMtuV4);
	CONF (vpn.hostIpDefaultGatewayV4);
	CONF (vpn.optionV4ArpExpires);
	CONF (vpn.optionV4ArpDontUpdateExpires);
	CONF (vpn.vpnGatewayAddressV4);
	CONF (vpn.vpnAuthMethodV4);
	CONF (vpn.vpnPasswordV4);
	CONF (vpn.vpnIdStringV4);
	CONF (vpn.vpnCertV4);
	CONF (vpn.vpnCaCertV4);
	CONF (vpn.vpnRsaKeyV4);
	CONF (vpn.vpnSpecifyIssuerV4);
	CONF (vpn.vpnPhase1CryptoV4);
	CONF (vpn.vpnPhase1HashV4);
	CONF (vpn.vpnPhase1LifeSecondsV4);
	CONF (vpn.vpnPhase1LifeKilobytesV4);
	CONF (vpn.vpnWaitPhase2BlankSpanV4);
	CONF (vpn.vpnPhase2CryptoV4);
	CONF (vpn.vpnPhase2HashV4);
	CONF (vpn.vpnPhase2LifeSecondsV4);
	CONF (vpn.vpnPhase2LifeKilobytesV4);
	CONF (vpn.vpnConnectTimeoutV4);
	CONF (vpn.vpnIdleTimeoutV4);
	CONF (vpn.vpnPingTargetV4);
	CONF (vpn.vpnPingIntervalV4);
	CONF (vpn.vpnPingMsgSizeV4);
	CONF (vpn.bindV6);
	CONF (vpn.guestIpAddressPrefixV6);
	CONF (vpn.guestIpAddressSubnetV6);
	CONF (vpn.guestMtuV6);
	CONF (vpn.guestVirtualGatewayIpAddressV6);
	CONF (vpn.raV6);
	CONF (vpn.raLifetimeV6);
	CONF (vpn.raDnsV6);
	CONF (vpn.hostIpAddressV6);
	CONF (vpn.hostIpAddressSubnetV6);
	CONF (vpn.hostMtuV6);
	CONF (vpn.hostIpDefaultGatewayV6);
	CONF (vpn.optionV6NeighborExpires);
	CONF (vpn.vpnGatewayAddressV6);
	CONF (vpn.vpnAuthMethodV6);
	CONF (vpn.vpnPasswordV6);
	CONF (vpn.vpnIdStringV6);
	CONF (vpn.vpnCertV6);
	CONF (vpn.vpnCaCertV6);
	CONF (vpn.vpnRsaKeyV6);
	CONF (vpn.vpnSpecifyIssuerV6);
	CONF (vpn.vpnPhase1CryptoV6);
	CONF (vpn.vpnPhase1HashV6);
	CONF (vpn.vpnPhase1LifeSecondsV6);
	CONF (vpn.vpnPhase1LifeKilobytesV6);
	CONF (vpn.vpnWaitPhase2BlankSpanV6);
	CONF (vpn.vpnPhase2CryptoV6);
	CONF (vpn.vpnPhase2HashV6);
	CONF (vpn.vpnPhase2LifeSecondsV6);
	CONF (vpn.vpnPhase2LifeKilobytesV6);
	CONF (vpn.vpnPhase2StrictIdV6);
	CONF (vpn.vpnConnectTimeoutV6);
	CONF (vpn.vpnIdleTimeoutV6);
	CONF (vpn.vpnPingTargetV6);
	CONF (vpn.vpnPingIntervalV6);
	CONF (vpn.vpnPingMsgSizeV6);
	/* storage */
	for (i = 0; i < NUM_OF_STORAGE_KEYS; i++)
		CONF1 ("storage.keys[%d]", i, cfg->storage.keys[i]);
	for (i = 0; i < NUM_OF_STORAGE_KEYS_CONF; i++) {
		CONF1 ("storage.keys_conf[%d].guid", i,
		       cfg->storage.keys_conf[i].guid);
		CONF1 ("storage.keys_conf[%d].type", i,
		       cfg->storage.keys_conf[i].type);
		CONF1 ("storage.keys_conf[%d].host_id", i,
		       cfg->storage.keys_conf[i].host_id);
		CONF1 ("storage.keys_conf[%d].device_id", i,
		       cfg->storage.keys_conf[i].device_id);
		CONF1 ("storage.keys_conf[%d].lba_low", i,
		       cfg->storage.keys_conf[i].lba_low);
		CONF1 ("storage.keys_conf[%d].lba_high", i,
		       cfg->storage.keys_conf[i].lba_high);
		CONF1 ("storage.keys_conf[%d].crypto_name", i,
		       cfg->storage.keys_conf[i].crypto_name);
		CONF1 ("storage.keys_conf[%d].keyindex", i,
		       cfg->storage.keys_conf[i].keyindex);
		CONF1 ("storage.keys_conf[%d].keybits", i,
		       cfg->storage.keys_conf[i].keybits);
		CONF1 ("storage.keys_conf[%d].extend", i,
		       cfg->storage.keys_conf[i].extend);
	}
	/* vmm */
	CONF (vmm.f11panic);
	CONF (vmm.f12msg);
	CONF (vmm.auto_reboot);
	CONF (vmm.shell);
	CONF (vmm.dbgsh);
	CONF (vmm.status);
	CONF (vmm.boot_active);
	CONF (vmm.tty_pro1000);
	CONF (vmm.tty_pro1000_mac_address);
	CONF (vmm.tty_rtl8169);
	CONF (vmm.tty_rtl8169_mac_address);
	CONF (vmm.driver.ata);
	CONF (vmm.driver.usb.uhci);
	CONF (vmm.driver.usb.ehci);
	CONF (vmm.driver.concealEHCI);
	CONF (vmm.driver.conceal1394);
	CONF (vmm.driver.concealPRO1000);
	CONF (vmm.driver.vpn.PRO100);
	CONF (vmm.driver.vpn.PRO1000);
	CONF (vmm.driver.vpn.RTL8169);
	CONF (vmm.driver.vpn.ve);
	CONF (vmm.driver.pci_conceal);
	CONF (vmm.iccard.enable);
	CONF (vmm.iccard.status);
	if (!dst) {
		fprintf (stderr, "unknown config \"%s\"\n", name);
		exit (EXIT_FAILURE);
	}
	if (len > dstlen) {
		fprintf (stderr, "config \"%s\" is too long\n", name);
		exit (EXIT_FAILURE);
	}
	memset (dst, 0, dstlen);
	memcpy (dst, src, len);
	free (name);
	free (src);
}
Ejemplo n.º 16
0
static bool
VegaConfigurationUpdated(const TCHAR *name, bool first, bool setvalue = false,
                         long ext_setvalue = 0)
{
  TCHAR updatename[100];
  TCHAR fullname[100];
  TCHAR propname[100];
  TCHAR requesttext[100];
  unsigned updated = 0;
  unsigned lvalue = 0;

  WndProperty* wp;

#ifdef _WIN32_WCE
  if (first)
    ProgressGlue::Step();
#endif

  _stprintf(updatename, CONF("Vega%sUpdated"), name);
  _stprintf(fullname, CONF("Vega%s"), name);
  _stprintf(propname, _T("prp%s"), name);

  if (first) {
    Profile::Set(updatename, 0);
    // we are not ready, haven't received value from vario
    // (do request here)
    _stprintf(requesttext, _T("PDVSC,R,%s"), name);
    VarioWriteNMEA(requesttext);

    if (!is_simulator())
      Sleep(250);
  }

  if (setvalue) {
    wp = (WndProperty*)wf->FindByName(propname);
    if (wp) {
      wp->GetDataField()->SetAsInteger((int)ext_setvalue);
      wp->RefreshDisplay();
    }
    _stprintf(requesttext, _T("PDVSC,S,%s,%d"), name, ext_setvalue);
    VarioWriteNMEA(requesttext);

    if (!is_simulator())
      Sleep(250);

    return true;
  }

  if (!Profile::Get(fullname, lvalue)) {
    // vario hasn't set the value in the registry yet,
    // so no sensible defaults
    return false;
  } else {
    // hack, fix the -1 (plug and play settings)
    if (_tcscmp(name, _T("HasTemperature")) == 0) {
      if (lvalue >= 255)
        lvalue = 2;
    }
    if (first) {
      // at start, set from last known registry value, this
      // helps if variables haven't been modified.
      wp = (WndProperty*)wf->FindByName(propname);
      if (wp) {
        wp->GetDataField()->SetAsInteger(lvalue);
        wp->RefreshDisplay();
      }
    }
  }

  if (Profile::Get(updatename, updated)) {
    if (updated == 1) {
      // value is updated externally, so set the property and can proceed
      // to editing values
      Profile::Set(updatename, 2);

      wp = (WndProperty*)wf->FindByName(propname);
      if (wp) {
        wp->GetDataField()->SetAsInteger(lvalue);
        wp->RefreshDisplay();
      }
    } else if (updated == 2) {
      wp = (WndProperty*)wf->FindByName(propname);
      if (wp) {
        unsigned newval = (wp->GetDataField()->GetAsInteger());
        if (newval != lvalue) {
          // value has changed
          Profile::Set(updatename, 2);
          Profile::Set(fullname, lvalue);

          changed = true;

          // maybe represent all as text?
          // note that this code currently won't work for longs

          // hack, fix the -1 (plug and play settings)
          if (_tcscmp(name, _T("HasTemperature")) == 0) {
            if (newval == 2)
              newval = 255;
          }

          _stprintf(requesttext, _T("PDVSC,S,%s,%d"), name, newval);
          VarioWriteNMEA(requesttext);

          if (!is_simulator())
            Sleep(250);

          return true;
        }
      }
    }
  }
  return false;
}
Ejemplo n.º 17
0
static void i80286_code_descriptor(i80286_state *cpustate, UINT16 selector, UINT16 offset, int gate)
{
	if (PM) {
		UINT16 desc[3];
		UINT8 r;
		UINT32 addr;
		/* selector format
           15..3 number/address in descriptor table
           2: 0 global, 1 local descriptor table
           1,0: requested privileg level
           must be higher or same as current privileg level in code selector */
		if ((addr = i80286_selector_address(cpustate,selector)) == -1) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
		desc[0] = ReadWord(addr);
		desc[1] = ReadWord(addr+2);
		desc[2] = ReadWord(addr+4);
		r = RIGHTS(desc);

		if (SEGDESC(r)) {
			if (!CODE(r)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
			if (CONF(r)) { if(DPL(r)>CPL) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector)); }
			else if ((RPL(selector)>CPL) || (DPL(r)!=CPL)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));

			if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(selector));  // this order is important
			if (offset > LIMIT(desc)) throw TRAP(GENERAL_PROTECTION_FAULT, 0);
			SET_ACC(desc);
			WriteWord(addr+4, desc[2]);
			cpustate->sregs[CS]=IDXTBL(selector) | CPL;
			cpustate->limit[CS]=LIMIT(desc);
			cpustate->base[CS]=BASE(desc);
			cpustate->rights[CS]=RIGHTS(desc);
			cpustate->pc=cpustate->base[CS]+offset;
		} else { // systemdescriptor
			UINT16 gatedesc[3]={0,0,0};
			UINT16 gatesel = GATESEL(desc);
			if (!gate) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector)); // tss cs must be segment
			if (DPL(r) < PMAX(CPL,RPL(selector))) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
			if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT, IDXTBL(selector));

			switch (GATE(r)) {
			case CALLGATE:
				if ((addr = i80286_selector_address(cpustate,gatesel)) == -1)
					throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
				gatedesc[0] = ReadWord(addr);
				gatedesc[1] = ReadWord(addr+2);
				gatedesc[2] = ReadWord(addr+4);
				r = RIGHTS(gatedesc);
				if (!CODE(r) || !SEGDESC(r)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
				if (DPL(r)>CPL) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel));
				if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(gatesel));
				if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,0);

				if (!CONF(r)&&(DPL(r)<CPL)) {  // inner call
					UINT16 tss_ss, tss_sp, oldss, oldsp;
					UINT32 oldstk;
					int i;
					if(gate == JMP) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(gatesel)); // can't jmp to inner
					tss_ss = ReadWord(cpustate->tr.base+TSS_SS0*2+(DPL(r)*4));
					tss_sp = ReadWord(cpustate->tr.base+TSS_SP0*2+(DPL(r)*4));

					oldss = cpustate->sregs[SS];
					oldsp = cpustate->regs.w[SP];
					oldstk = cpustate->base[SS] + oldsp;
					i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,IDXTBL(tss_ss)), tss_sp-8-(GATECNT(desc)*2), 8+(GATECNT(desc)*2));
					cpustate->regs.w[SP] = tss_sp;
					PUSH(oldss);
					PUSH(oldsp);
					for (i = GATECNT(desc)-1; i >= 0; i--)
						PUSH(ReadWord(oldstk+(i*2)));
				} else i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-4, 4, I80286_READ);
				SET_ACC(gatedesc);
				WriteWord(addr+4, gatedesc[2]);
				cpustate->sregs[CS]=IDXTBL(gatesel) | DPL(r);
				cpustate->limit[CS]=LIMIT(gatedesc);
				cpustate->base[CS]=BASE(gatedesc);
				cpustate->rights[CS]=RIGHTS(gatedesc);
				cpustate->pc=(cpustate->base[CS]+GATEOFF(desc))&AMASK;
				break;
			case TASKGATE:
				selector = gatesel;
				if ((addr = i80286_selector_address(cpustate,selector)) == -1)
					throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
				desc[2] = ReadWord(addr+4);
				r = RIGHTS(desc);
				if (SEGDESC(r) || (GATE(r) != TSSDESCIDLE)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
			case TSSDESCIDLE:
				i80286_switch_task(cpustate, selector, gate);
				i80286_load_flags(cpustate, cpustate->flags, CPL);
				break;
			default:
				throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(selector));
			}
		}
	} else {
		cpustate->sregs[CS]=selector;
		cpustate->base[CS]=selector<<4;
		cpustate->rights[CS]=0x9a;
		cpustate->limit[CS]=0xffff;
		cpustate->pc=(cpustate->base[CS]+offset)&AMASK;
	}
}
Ejemplo n.º 18
0
static int camqp_connect (camqp_config_t *conf) /* {{{ */
{
    static time_t last_connect_time = 0;

    amqp_rpc_reply_t reply;
    int status;
#ifdef HAVE_AMQP_TCP_SOCKET
    amqp_socket_t *socket;
#else
    int sockfd;
#endif

    if (conf->connection != NULL)
        return (0);

    time_t now = time(NULL);
    if (now < (last_connect_time + conf->connection_retry_delay))
    {
        DEBUG("amqp plugin: skipping connection retry, "
            "ConnectionRetryDelay: %d", conf->connection_retry_delay);
        return(1);
    }
    else
    {
        DEBUG ("amqp plugin: retrying connection");
        last_connect_time = now;
    }

    conf->connection = amqp_new_connection ();
    if (conf->connection == NULL)
    {
        ERROR ("amqp plugin: amqp_new_connection failed.");
        return (ENOMEM);
    }

#ifdef HAVE_AMQP_TCP_SOCKET
# define CLOSE_SOCKET() /* amqp_destroy_connection() closes the socket for us */
    /* TODO: add support for SSL using amqp_ssl_socket_new
     *       and related functions */
    socket = amqp_tcp_socket_new (conf->connection);
    if (! socket)
    {
        ERROR ("amqp plugin: amqp_tcp_socket_new failed.");
        amqp_destroy_connection (conf->connection);
        conf->connection = NULL;
        return (ENOMEM);
    }

    status = amqp_socket_open (socket, CONF(conf, host), conf->port);
    if (status < 0)
    {
        char errbuf[1024];
        status *= -1;
        ERROR ("amqp plugin: amqp_socket_open failed: %s",
                sstrerror (status, errbuf, sizeof (errbuf)));
        amqp_destroy_connection (conf->connection);
        conf->connection = NULL;
        return (status);
    }
#else /* HAVE_AMQP_TCP_SOCKET */
# define CLOSE_SOCKET() close(sockfd)
    /* this interface is deprecated as of rabbitmq-c 0.4 */
    sockfd = amqp_open_socket (CONF(conf, host), conf->port);
    if (sockfd < 0)
    {
        char errbuf[1024];
        status = (-1) * sockfd;
        ERROR ("amqp plugin: amqp_open_socket failed: %s",
                sstrerror (status, errbuf, sizeof (errbuf)));
        amqp_destroy_connection (conf->connection);
        conf->connection = NULL;
        return (status);
    }
    amqp_set_sockfd (conf->connection, sockfd);
#endif

    reply = amqp_login (conf->connection, CONF(conf, vhost),
            /* channel max = */      0,
            /* frame max   = */ 131072,
            /* heartbeat   = */      0,
            /* authentication = */ AMQP_SASL_METHOD_PLAIN,
            CONF(conf, user), CONF(conf, password));
    if (reply.reply_type != AMQP_RESPONSE_NORMAL)
    {
        ERROR ("amqp plugin: amqp_login (vhost = %s, user = %s) failed.",
                CONF(conf, vhost), CONF(conf, user));
        amqp_destroy_connection (conf->connection);
        CLOSE_SOCKET ();
        conf->connection = NULL;
        return (1);
    }

    amqp_channel_open (conf->connection, /* channel = */ 1);
    /* FIXME: Is checking "reply.reply_type" really correct here? How does
     * it get set? --octo */
    if (reply.reply_type != AMQP_RESPONSE_NORMAL)
    {
        ERROR ("amqp plugin: amqp_channel_open failed.");
        amqp_connection_close (conf->connection, AMQP_REPLY_SUCCESS);
        amqp_destroy_connection (conf->connection);
        CLOSE_SOCKET ();
        conf->connection = NULL;
        return (1);
    }

    INFO ("amqp plugin: Successfully opened connection to vhost \"%s\" "
            "on %s:%i.", CONF(conf, vhost), CONF(conf, host), conf->port);

    status = camqp_create_exchange (conf);
    if (status != 0)
        return (status);

    if (!conf->publish)
        return (camqp_setup_queue (conf));
    return (0);
} /* }}} int camqp_connect */
Ejemplo n.º 19
0
static void i80286_interrupt_descriptor(i80286_state *cpustate,UINT16 number, int hwint, int error)
{
	UINT16 desc[3], gatedesc[3]={0,0,0}, gatesel;
	UINT8 r;
	UINT32 addr;

	if(!PM) return PREFIX86(_interrupt)(cpustate, number);

	if ((number<<3)>=cpustate->idtr.limit)
		throw TRAP(GENERAL_PROTECTION_FAULT,(number*8+2+(hwint&&1)));

	desc[0] = ReadWord(cpustate->idtr.base+(number<<3));
	desc[1] = ReadWord(cpustate->idtr.base+(number<<3)+2);
	desc[2] = ReadWord(cpustate->idtr.base+(number<<3)+4);
	r = RIGHTS(desc);
	if (!hwint && (DPL(r)<CPL)) throw TRAP(GENERAL_PROTECTION_FAULT,(number*8+2+(hwint&&1)));
	if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(number*8+2+(hwint&&1)));
	gatesel = GATESEL(desc);

	switch (GATE(r)) {
	case TASKGATE:
		i80286_switch_task(cpustate, gatesel, CALL);
		if((hwint == 1) && (error != -1)) PUSH(error);
		i80286_load_flags(cpustate, cpustate->flags, CPL);
		break;
	case INTGATE:
	case TRAPGATE:
		if ((addr = i80286_selector_address(cpustate,gatesel)) == -1)
			throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
		gatedesc[0] = ReadWord(addr);
		gatedesc[1] = ReadWord(addr+2);
		gatedesc[2] = ReadWord(addr+4);
		r = RIGHTS(gatedesc);
		if (!CODE(r) || !SEGDESC(r)) throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
		if (DPL(r)>CPL) throw TRAP(GENERAL_PROTECTION_FAULT,(IDXTBL(gatesel)+(hwint&&1)));
		if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,(IDXTBL(gatesel)+(hwint&&1)));
		if (GATEOFF(desc) > LIMIT(gatedesc)) throw TRAP(GENERAL_PROTECTION_FAULT,(int)(hwint&&1));

		if (!CONF(r)&&(DPL(r)<CPL)) {  // inner call
			UINT16 tss_ss, tss_sp, oldss, oldsp;
			tss_ss = ReadWord(cpustate->tr.base+TSS_SS0*2+(DPL(r)*4));
			tss_sp = ReadWord(cpustate->tr.base+TSS_SP0*2+(DPL(r)*4));

			oldss = cpustate->sregs[SS];
			oldsp = cpustate->regs.w[SP];
			i80286_data_descriptor_full(cpustate, SS, tss_ss, DPL(r), TRAP(INVALID_TSS,(IDXTBL(tss_ss)+(hwint&&1))), tss_sp-((error != -1)?12:10), (error != -1)?12:10);
			cpustate->regs.w[SP] = tss_sp;
			PUSH(oldss);
			PUSH(oldsp);
		} else i80286_check_permission(cpustate, SS, cpustate->regs.w[SP]-((error != -1)?8:6), (error != -1)?8:6, I80286_READ);
		SET_ACC(gatedesc);
		WriteWord(addr+4, gatedesc[2]);
		PREFIX(_pushf(cpustate));
		PUSH(cpustate->sregs[CS]);
		PUSH(cpustate->pc-cpustate->base[CS]);
		if((hwint == 1) && (error != -1)) PUSH(error);
		cpustate->sregs[CS]=IDXTBL(gatesel) | DPL(r);
		cpustate->limit[CS]=LIMIT(gatedesc);
		cpustate->base[CS]=BASE(gatedesc);
		cpustate->rights[CS]=RIGHTS(gatedesc);
		cpustate->pc=(cpustate->base[CS]+GATEOFF(desc))&AMASK;
		cpustate->TF = 0;
		cpustate->flags &= ~0x4000;
		if (GATE(RIGHTS(desc)) == INTGATE) cpustate->IF = 0;
		CHANGE_PC(cpustate->pc);
		break;
	default:
		throw TRAP(GENERAL_PROTECTION_FAULT,(number*8+2+(hwint&&1)));
	}
}
Ejemplo n.º 20
0
static void PREFIX286(_0fpre)(i8086_state *cpustate)
{
	unsigned next = FETCHOP;
	UINT16 ModRM, desc[3];
	UINT16 tmp, msw, sel;
	UINT8 r;
	UINT32 addr;

	switch (next) {
	case 0:
		if (!PM) throw TRAP(ILLEGAL_INSTRUCTION,-1);
		ModRM=FETCHOP;
		switch (ModRM&0x38) {
		case 0: /* sldt */
			PutRMWord(ModRM, cpustate->ldtr.sel);
			break;
		case 8: /* str */
			PutRMWord(ModRM, cpustate->tr.sel);
			break;
		case 0x10: /* lldt */
			if (CPL!=0) throw TRAP(GENERAL_PROTECTION_FAULT,0);
			sel=GetRMWord(ModRM);
			if (TBL(sel)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
			if (IDXTBL(sel)) {
				if (IDX(sel)>=cpustate->gdtr.limit) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
				addr = cpustate->gdtr.base + IDX(sel);
				desc[0] = ReadWord(addr);
				desc[1] = ReadWord(addr+2);
				desc[2] = ReadWord(addr+4);
				r = RIGHTS(desc);
				if (SEGDESC(r) || (GATE(r) != LDTDESC)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
				if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(sel));
			} else {
				desc[0] = 0;
				desc[1] = 0;
				desc[2] = 0;
			}
			cpustate->ldtr.sel=sel;
			cpustate->ldtr.limit=LIMIT(desc);
			cpustate->ldtr.base=BASE(desc);
			cpustate->ldtr.rights=RIGHTS(desc);
			break;
		case 0x18: /* ltr */
			if (CPL!=0) throw TRAP(GENERAL_PROTECTION_FAULT,0);
			sel=GetRMWord(ModRM);
			if ((addr = i80286_selector_address(cpustate,sel)) == -1) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
			desc[0] = ReadWord(addr);
			desc[1] = ReadWord(addr+2);
			desc[2] = ReadWord(addr+4);
			r = RIGHTS(desc);
			if (SEGDESC(r) || (GATE(r) != TSSDESCIDLE)) throw TRAP(GENERAL_PROTECTION_FAULT,IDXTBL(sel));
			if (!PRES(r)) throw TRAP(SEG_NOT_PRESENT,IDXTBL(sel));
			desc[2] |= 0x200; // mark busy
			WriteWord(addr+4, desc[2]);
			cpustate->tr.sel=sel;
			cpustate->tr.limit=LIMIT(desc);
			cpustate->tr.base=BASE(desc);
			cpustate->tr.rights=RIGHTS(desc);
			break;
		case 0x20: /* verr */
			tmp=GetRMWord(ModRM);
			if ((addr = i80286_selector_address(cpustate,tmp)) == -1) cpustate->ZeroVal = 1;
			else {
				desc[2] = ReadWord(addr+4);
				r = RIGHTS(desc);
				cpustate->ZeroVal = i80286_verify(cpustate, tmp, I80286_READ, RIGHTS(desc), 0);
				cpustate->ZeroVal = cpustate->ZeroVal || (CODE(r) && CONF(r) ? 0 : (DPL(r)<PMAX(RPL(tmp),CPL)));
			}
			break;
		case 0x28: /* verw */
			tmp=GetRMWord(ModRM);
			if ((addr = i80286_selector_address(cpustate,tmp)) == -1) cpustate->ZeroVal = 1;
			else {
				desc[2] = ReadWord(addr+4);
				r = RIGHTS(desc);
				cpustate->ZeroVal = i80286_verify(cpustate, tmp, I80286_WRITE, RIGHTS(desc), 0);
				cpustate->ZeroVal = cpustate->ZeroVal || (DPL(r)<PMAX(RPL(tmp),CPL));
			}
			break;
		default:
			throw TRAP(ILLEGAL_INSTRUCTION,-1);
			break;
		}
		break;
	case 1:
		/* lgdt, lldt in protected mode privilege level 0 required else common protection
           failure 0xd */
		ModRM = FETCHOP;
		switch (ModRM&0x38) {
		case 0: /* sgdt */
			PutRMWord(ModRM,cpustate->gdtr.limit);
			PutRMWordOffset(2,cpustate->gdtr.base&0xffff);
			PutRMWordOffset(4,0xff00|cpustate->gdtr.base>>16);
			break;
		case 8: /* sidt */
			PutRMWord(ModRM,cpustate->idtr.limit);
			PutRMWordOffset(2,cpustate->idtr.base&0xffff);
			PutRMWordOffset(4,0xff00|cpustate->idtr.base>>16);
			break;
		case 0x10: /* lgdt */
			if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
			cpustate->gdtr.limit=GetRMWord(ModRM);
			cpustate->gdtr.base=GetRMWordOffset(2)|(GetRMByteOffset(4)<<16);
			break;
		case 0x18: /* lidt */
			if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
			cpustate->idtr.limit=GetRMWord(ModRM);
			cpustate->idtr.base=GetRMWordOffset(2)|(GetRMByteOffset(4)<<16);
			break;
		case 0x20: /* smsw */
			PutRMWord(ModRM, cpustate->msw);
			break;
		case 0x30: /* lmsw */
			if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
			msw = GetRMWord(ModRM);
			if (!PM&&(msw&1)) cpustate->sregs[CS] = IDX(cpustate->sregs[CS]); // cheat and set cpl to 0
			cpustate->msw=(cpustate->msw&1)|msw;
			break;
		default:
			throw TRAP(ILLEGAL_INSTRUCTION,-1);
			break;
		}
		break;
	case 2: /* LAR */
		if (!PM) throw TRAP(ILLEGAL_INSTRUCTION,-1);
		ModRM = FETCHOP;
		tmp=GetRMWord(ModRM);
		if ((addr = i80286_selector_address(cpustate,tmp)) == -1) cpustate->ZeroVal = 1;
		else {
			desc[2] = ReadWord(addr+4);
			r = RIGHTS(desc);
			if (DPL(r)>=PMAX(RPL(tmp),CPL)) {
				cpustate->ZeroVal = 0;
				// rights are expected to be in upper byte
				RegWord(ModRM) = r << 8;
			}
			else
				cpustate->ZeroVal = 1;
		}
		break;
	case 3: /* LSL */
		if (!PM) throw TRAP(ILLEGAL_INSTRUCTION,-1);
		ModRM = FETCHOP;
		tmp=GetRMWord(ModRM);
		if ((addr = i80286_selector_address(cpustate,tmp)) == -1) cpustate->ZeroVal = 1;
		else {
			desc[2] = ReadWord(addr+4);
			r = RIGHTS(desc);
			if (!SEGDESC(r) && (GATE(r) >= CALLGATE)) cpustate->ZeroVal = 1; // not valid for gates
			else if (DPL(r)>=PMAX(RPL(tmp),CPL)) {
				cpustate->ZeroVal = 0;
				RegWord(ModRM) = ReadWord(addr);
			}
			else
				cpustate->ZeroVal = 1;
		}
		break;
	case 5: /* loadall */
		if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
		cpustate->msw =        (cpustate->msw&1)|ReadWord(0x806);
		cpustate->tr.sel =     ReadWord(0x816);
		tmp =	               ReadWord(0x818);
		ExpandFlags(tmp);
		cpustate->flags = tmp;
		cpustate->flags = CompressFlags();
		cpustate->pc =         ReadWord(0x81a);
		cpustate->ldtr.sel =   ReadWord(0x81c);
		cpustate->sregs[DS] =  ReadWord(0x81e);
		cpustate->sregs[SS] =  ReadWord(0x820);
		cpustate->sregs[CS] =  ReadWord(0x822);
		cpustate->sregs[ES] =  ReadWord(0x824);
		cpustate->regs.w[DI] = ReadWord(0x826);
		cpustate->regs.w[SI] = ReadWord(0x828);
		cpustate->regs.w[BP] = ReadWord(0x82a);
		cpustate->regs.w[SP] = ReadWord(0x82c);
		cpustate->regs.w[BX] = ReadWord(0x82e);
		cpustate->regs.w[DX] = ReadWord(0x830);
		cpustate->regs.w[CX] = ReadWord(0x832);
		cpustate->regs.w[AX] = ReadWord(0x834);
// loadall uses base-rights-limit order
#define LOADDESC(addr, sreg) {  desc[1] = ReadWord(addr); desc[2] = ReadWord(addr+2); desc[0] = ReadWord(addr+4); \
				cpustate->base[sreg] = BASE(desc); cpustate->rights[sreg] = RIGHTS(desc); \
				cpustate->limit[sreg] = LIMIT(desc); }
		LOADDESC(0x836, ES);
		LOADDESC(0x83C, CS);
		LOADDESC(0x842, SS);
		LOADDESC(0x848, DS);
#undef LOADDESC
// void cast supresses warning
#define LOADDESC(addr, reg, r) { desc[1] = ReadWord(addr); desc[2] = ReadWord(addr+2); desc[0] = ReadWord(addr+4); \
				cpustate->reg.base = BASE(desc); (void)(r); cpustate->reg.limit = LIMIT(desc); }
		LOADDESC(0x84e, gdtr, 1);
		LOADDESC(0x854, ldtr, cpustate->ldtr.rights = RIGHTS(desc));
		LOADDESC(0x85a, idtr, 1);
		LOADDESC(0x860, tr,  cpustate->tr.rights = RIGHTS(desc));
#undef LOADDESC
		cpustate->pc = (cpustate->pc + cpustate->base[CS]) & AMASK;
		CHANGE_PC(cpustate->pc);
		break;

	case 6: /* clts */
		if (PM&&(CPL!=0)) throw TRAP(GENERAL_PROTECTION_FAULT,0);
		cpustate->msw&=~8;
		break;
	default:
		throw TRAP(ILLEGAL_INSTRUCTION,-1);
		break;
	}
}
Ejemplo n.º 21
0
struct usb_sock_t *usb_open()
{
	struct usb_sock_t *usb = calloc(1, sizeof *usb);
	int status = 1;
	status = libusb_init(&usb->context);
	if (status < 0) {
		ERR("libusb init failed with error: %s",
			libusb_error_name(status));
		goto error_usbinit;
	}

	libusb_device **device_list = NULL;
	ssize_t device_count = libusb_get_device_list(usb->context, &device_list);
	if (device_count < 0) {
		ERR("failed to get list of usb devices");
		goto error;
	}


	// Discover device and count interfaces ==---------------------------==
	int selected_config = -1;
	unsigned int selected_ipp_interface_count = 0;
	int auto_pick = !(g_options.vendor_id ||
	                  g_options.product_id ||
	                  g_options.serial_num);

	libusb_device *printer_device = NULL;
	for (ssize_t i = 0; i < device_count; i++) {
		libusb_device *candidate = device_list[i];
		struct libusb_device_descriptor desc;
		libusb_get_device_descriptor(candidate, &desc);

		if (!is_our_device(candidate, desc))
			continue;

		for (uint8_t config_num = 0;
		     config_num < desc.bNumConfigurations;
		     config_num++) {
			struct libusb_config_descriptor *config = NULL;
			status = libusb_get_config_descriptor(candidate,
			                                      config_num,
			                                      &config);
			if (status < 0)
				ERR_AND_EXIT("USB: didn't get config desc %s",
					libusb_error_name(status));

			int interface_count = count_ippoverusb_interfaces(config);
			libusb_free_config_descriptor(config);
			if (interface_count >= 2) {
				selected_config = config_num;
				selected_ipp_interface_count = (unsigned) interface_count;
				printer_device = candidate;
				goto found_device;
			}

			// CONFTEST: Two or more interfaces are required
			if (interface_count == 1) {
				CONF("usb device has only one ipp interface "
				    "in violation of standard");
				goto error;
			}

			if (!auto_pick) {
				ERR_AND_EXIT("No ipp-usb interfaces found");
			}
		}
	}
found_device:

	if (printer_device == NULL) {
		if (!auto_pick) {
			ERR("No printer found by that vid, pid, serial");
		} else {
			ERR("No IPP over USB printer found");
		}
		goto error;
	}


	// Open the printer ==-----------------------------------------------==
	status = libusb_open(printer_device, &usb->printer);
	if (status != 0) {
		ERR("failed to open device");
		goto error;
	}


	// Open every IPP-USB interface ==-----------------------------------==
	usb->num_interfaces = selected_ipp_interface_count;
	usb->interfaces = calloc(usb->num_interfaces,
	                         sizeof(*usb->interfaces));
	if (usb->interfaces == NULL) {
		ERR("Failed to alloc interfaces");
		goto error;
	}

	struct libusb_config_descriptor *config = NULL;
	status = libusb_get_config_descriptor(printer_device,
	                                      (uint8_t)selected_config,
	                                      &config);
	if (status != 0 || config == NULL) {
		ERR("Failed to aquire config descriptor");
		goto error;
	}

	unsigned int interfs = selected_ipp_interface_count;
	for (uint8_t interf_num = 0;
	     interf_num < config->bNumInterfaces;
	     interf_num++) {
	
		const struct libusb_interface *interf = NULL;
		interf = &config->interface[interf_num];
		for (int alt_num = 0;
		     alt_num < interf->num_altsetting;
		     alt_num++) {
	
			const struct libusb_interface_descriptor *alt = NULL;
			alt = &interf->altsetting[alt_num];

			// Skip non-IPP-USB interfaces
			if (!is_ippusb_interface(alt))
				continue;

			interfs--;

			struct usb_interface *uf = usb->interfaces + interfs;
			uf->interface_number = interf_num;
			uf->libusb_interface_index = alt->bInterfaceNumber;
			uf->interface_alt = alt_num;

			// Store interface's two endpoints
			for (int end_i = 0; end_i < alt->bNumEndpoints;
			     end_i++) {
				const struct libusb_endpoint_descriptor *end;
				end = &alt->endpoint[end_i];

				usb->max_packet_size = end->wMaxPacketSize;

				// High bit set means endpoint
				// is an INPUT or IN endpoint.
				uint8_t address = end->bEndpointAddress;
				if (address & 0x80)
					uf->endpoint_in = address;
				else
					uf->endpoint_out = address;
			}

			break;
		}
	}
	libusb_free_config_descriptor(config);
	libusb_free_device_list(device_list, 1);


	// Pour interfaces into pool ==--------------------------------------==
	usb->num_avail = usb->num_interfaces;
	usb->interface_pool = calloc(usb->num_avail,
	                             sizeof(*usb->interface_pool));
	if (usb->interface_pool == NULL) {
		ERR("Failed to alloc interface pool");
		goto error;
	}
	for (uint32_t i = 0; i < usb->num_avail; i++) {
		usb->interface_pool[i] = i;
	}


	// Stale lock
	int status_lock = sem_init(&usb->num_staled_lock, 0, 1);
	if (status_lock != 0) {
		ERR("Failed to create num_staled lock");
		goto error;
	}

	// Pool management lock
	status_lock = sem_init(&usb->pool_manage_lock, 0, 1);
	if (status_lock != 0) {
		ERR("Failed to create high priority pool lock");
		goto error;
	}
	// High priority lock
	status_lock = sem_init(&usb->pool_high_priority_lock, 0, 1);
	if (status_lock != 0) {
		ERR("Failed to create low priority pool lock");
		goto error;
	}
	// Low priority lock
	status_lock = sem_init(&usb->pool_low_priority_lock,
	                       0, usb->num_avail - 1);
	if (status_lock != 0) {
		ERR("Failed to create high priority pool lock");
		goto error;
	}

	return usb;

error:
	if (device_list != NULL)
		libusb_free_device_list(device_list, 1);
error_usbinit:
	if (usb != NULL) {
		if (usb->context != NULL)
			libusb_exit(usb->context);
		if (usb->interfaces != NULL)
			free(usb->interfaces);
		if (usb->interface_pool != NULL)
			free(usb->interface_pool);
		free(usb);
	}
	return NULL;
}
Ejemplo n.º 22
0
Archivo: amqp.c Proyecto: brd/collectd
/* XXX: You must hold "conf->lock" when calling this function! */
static int camqp_write_locked (camqp_config_t *conf, /* {{{ */
        const char *buffer, const char *routing_key)
{
    int status;

    status = camqp_connect (conf);
    if (status != 0)
        return (status);

    amqp_basic_properties_t props = {
        ._flags = AMQP_BASIC_CONTENT_TYPE_FLAG
            | AMQP_BASIC_DELIVERY_MODE_FLAG
            | AMQP_BASIC_APP_ID_FLAG,
        .delivery_mode = conf->delivery_mode,
        .app_id = amqp_cstring_bytes("collectd")
    };

    if (conf->format == CAMQP_FORMAT_COMMAND)
        props.content_type = amqp_cstring_bytes("text/collectd");
    else if (conf->format == CAMQP_FORMAT_JSON)
        props.content_type = amqp_cstring_bytes("application/json");
    else if (conf->format == CAMQP_FORMAT_GRAPHITE)
        props.content_type = amqp_cstring_bytes("text/graphite");
    else
        assert (23 == 42);

    status = amqp_basic_publish(conf->connection,
                /* channel = */ 1,
                amqp_cstring_bytes(CONF(conf, exchange)),
                amqp_cstring_bytes (routing_key),
                /* mandatory = */ 0,
                /* immediate = */ 0,
                &props,
                amqp_cstring_bytes(buffer));
    if (status != 0)
    {
        ERROR ("amqp plugin: amqp_basic_publish failed with status %i.",
                status);
        camqp_close_connection (conf);
    }

    return (status);
} /* }}} int camqp_write_locked */

static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
        user_data_t *user_data)
{
    camqp_config_t *conf = user_data->data;
    char routing_key[6 * DATA_MAX_NAME_LEN];
    char buffer[8192];
    int status;

    if ((ds == NULL) || (vl == NULL) || (conf == NULL))
        return (EINVAL);

    if (conf->routing_key != NULL)
    {
        sstrncpy (routing_key, conf->routing_key, sizeof (routing_key));
    }
    else
    {
        ssnprintf (routing_key, sizeof (routing_key), "collectd/%s/%s/%s/%s/%s",
                vl->host,
                vl->plugin, vl->plugin_instance,
                vl->type, vl->type_instance);

        /* Switch slashes (the only character forbidden by collectd) and dots
         * (the separation character used by AMQP). */
        for (size_t i = 0; routing_key[i] != 0; i++)
        {
            if (routing_key[i] == '.')
                routing_key[i] = '/';
            else if (routing_key[i] == '/')
                routing_key[i] = '.';
        }
    }

    if (conf->format == CAMQP_FORMAT_COMMAND)
    {
        status = create_putval (buffer, sizeof (buffer), ds, vl);
        if (status != 0)
        {
            ERROR ("amqp plugin: create_putval failed with status %i.",
                    status);
            return (status);
        }
    }
    else if (conf->format == CAMQP_FORMAT_JSON)
    {
        size_t bfree = sizeof (buffer);
        size_t bfill = 0;

        format_json_initialize (buffer, &bfill, &bfree);
        format_json_value_list (buffer, &bfill, &bfree, ds, vl, conf->store_rates);
        format_json_finalize (buffer, &bfill, &bfree);
    }
    else if (conf->format == CAMQP_FORMAT_GRAPHITE)
    {
        status = format_graphite (buffer, sizeof (buffer), ds, vl,
                    conf->prefix, conf->postfix, conf->escape_char,
                    conf->graphite_flags);
        if (status != 0)
        {
            ERROR ("amqp plugin: format_graphite failed with status %i.",
                    status);
            return (status);
        }
    }
    else
    {
        ERROR ("amqp plugin: Invalid format (%i).", conf->format);
        return (-1);
    }

    pthread_mutex_lock (&conf->lock);
    status = camqp_write_locked (conf, buffer, routing_key);
    pthread_mutex_unlock (&conf->lock);

    return (status);
} /* }}} int camqp_write */