Esempio n. 1
0
/**
 * \brief Specifies an interface to use for sending.
 *
 * You may call this up to two (2) times with different interfaces
 * when using a tcpprep cache file or dualfile mode.  Note, both interfaces
 * must use the same DLT type
 */
int
tcpreplay_set_interface(tcpreplay_t *ctx, tcpreplay_intf intf, char *value)
{
    static int int1dlt = -1, int2dlt = -1;
    char *intname;
    char ebuf[SENDPACKET_ERRBUF_SIZE];

    assert(ctx);
    assert(value);

    if (intf == intf1) {
        if ((intname = get_interface(ctx->intlist, value)) == NULL) {
            tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", value);
            return -1;
        }

        ctx->options->intf1_name = safe_strdup(intname);

        /* open interfaces for writing */
        if ((ctx->intf1 = sendpacket_open(ctx->options->intf1_name, ebuf, TCPR_DIR_C2S)) == NULL) {
            tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf1_name, ebuf);
            return -1;
        }

        int1dlt = sendpacket_get_dlt(ctx->intf1);
    } else if (intf == intf2) {
        if ((intname = get_interface(ctx->intlist, value)) == NULL) {
            tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", ctx->options->intf2_name);
            return -1;
        }

        ctx->options->intf2_name = safe_strdup(intname);

        /* open interface for writing */
        if ((ctx->intf2 = sendpacket_open(ctx->options->intf2_name, ebuf, TCPR_DIR_S2C)) == NULL) {
            tcpreplay_seterr(ctx, "Can't open %s: %s", ctx->options->intf2_name, ebuf);
            return -1;
        }
        int2dlt = sendpacket_get_dlt(ctx->intf2);
    }

    /*
     * If both interfaces are selected, then make sure both interfaces use
     * the same DLT type
     */
    if (int1dlt != -1 && int2dlt != -1) {
        if (int1dlt != int2dlt) {
            tcpreplay_seterr(ctx, "DLT type missmatch for %s (%s) and %s (%s)", 
                ctx->options->intf1_name, pcap_datalink_val_to_name(int1dlt), 
                ctx->options->intf2_name, pcap_datalink_val_to_name(int2dlt));
            return -1;
        }
    }

    return 0;
}
Esempio n. 2
0
	explicit Heksedit(CWnd *pwndParent)
	{
		pv = LoadLibrary(_T("Frhed\\hekseditU.dll"));
		if (pv == nullptr)
		{
			LangMessageBox(IDS_FRHED_NOTINSTALLED, MB_OK);
			return;
		}
		wnd.Create(_T("heksedit"), nullptr, 0, CRect(), pwndParent, 1);
		get_interface()->read_ini_data();
		get_interface()->get_settings()->bSaveIni = true;
	}
Esempio n. 3
0
/*!
	Extracts the neighbours of the specified cell for the given face.

	\param id is the id of the cell
	\param face is a face of the cell
	\param blackList is a list of cells that are excluded from the search
	\result The neighbours of the specified cell for the given face.
*/
std::vector<long> Patch::extract_cell_face_neighs(const long &id, const int &face, const std::vector<long> &blackList) const
{
	std::vector<long> neighs;
	const Cell &cell = get_cell(id);
	for (int i = 0; i < cell.get_interface_count(face); ++i) {
		long interfaceId = cell.get_interface(face, i);
		const Interface &interface = get_interface(interfaceId);
		if (interface.is_border()) {
			continue;
		}

		long neighId = interface.get_neigh();
		if (neighId == cell.get_id()) {
			neighId = interface.get_owner();
		}

		if (std::find(blackList.begin(), blackList.end(), neighId) != blackList.end()) {
			continue;
		}

		// Add the cell to the negihbour list
		utils::add_to_ordered_vector<long>(neighId, neighs);
	}

	return neighs;
}
Esempio n. 4
0
void send_arp_request(struct sr_instance* sr, uint32_t tip /* Net byte order */, const char* interface)
{

	assert(sr);
	assert(interface);

	iface_entry *inter = get_interface(sr, interface);
	uint8_t *request_packet = 0;
	eth_hdr *eth_request = 0;
	arp_hdr *arp_request = 0;
	uint32_t len = 0;
	uint8_t default_addr[ETH_ADDR_LEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

	/* construct the ARP request */
	len = sizeof(eth_hdr) + sizeof(arp_hdr);
	request_packet = calloc(len, sizeof(uint8_t));
	eth_request = (eth_hdr *)request_packet;
	arp_request = (arp_hdr *)(request_packet + sizeof(eth_hdr));

	populate_eth_hdr(eth_request, default_addr, inter->addr,
			 ETH_TYPE_ARP);
	populate_arp_hdr(arp_request, NULL, tip, inter->addr, inter->ip,
		         ARP_OP_REQUEST);


	/* send the ARP reply */
	if (send_packet(sr, request_packet, len, interface) != 0) {
		printf("Failure sending arp request\n");
	}

	/* recover allocated memory */
	free(request_packet);
}
Esempio n. 5
0
File: interface.c Progetto: naa/SLE
void generate_interfaces(int M, int N, int **table, double beta, int measurements)
{
  long long niter=(long long)((double)(M*10)*log(M)); //size*size*floor(1/fabs(1/beta-2.2698));
  long long i,j;
  long long len;
  interface inter;
  //  interface uniform;
  init_table_pm_third_boundary(M,N,table);
  for (i=0;i<niter;i++) modify_cluster_bc(M,N,table,1+rand_int(M-2), 1+rand_int(N-2), beta);
  printf("{");
  fprintf(stderr,"{");  
  for (i=0;i<measurements; i++){
    inter=get_interface(M,N,table);
    print_interface_to_file(stderr, inter);

    //    uniform=uniformize_interface(inter);
    //    print_interface_to_file(stderr, uniform);

    print_interface_as_ts_to_file(stdout, inter);
    
    free(inter.points);
    //    free(uniform.points);        
    if (i<measurements-1){    
      for (j=0;j<M/10;j++)
	modify_cluster_bc(M,N,table,1+rand_int(M-2), 1+rand_int(N-2), beta);
      printf(",\n");
      fprintf(stderr,",\n");
    }
  }
  printf("}");
  fprintf(stderr,"}");  
  free_2d_array(M,table);
}
Esempio n. 6
0
void
taskbar_progress_c::set_state(TBPFLAG state) {
  m_state = state;

  if (NULL != get_interface())
    m_interface->lpVtbl->SetProgressState(m_interface, GetHwndOf(m_window), m_state);
}
Esempio n. 7
0
/**
 * Turn on ip forwarding on the usb interface
 * @return: 0 on success, 1 on failure
 */
static int set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_data *ipforward)
{
  char *interface, *nat_interface;
  char command[128];

  interface = get_interface(data);
  nat_interface = get_network_nat_interface();
  if((nat_interface == NULL) && (ipforward->nat_interface != NULL))
	nat_interface = strdup(ipforward->nat_interface);
  else
  {
	log_debug("No nat interface available!\n");
#ifdef CONNMAN
	/* in case the cellular did not come up we want to make sure wifi gets restored */
	connman_reset_state();
#endif
	free((char *)interface);
	return(1);
  }
  write_to_file("/proc/sys/net/ipv4/ip_forward", "1");
  snprintf(command, 128, "/sbin/iptables -t nat -A POSTROUTING -o %s -j MASQUERADE", nat_interface);
  system(command);

  snprintf(command, 128, "/sbin/iptables -A FORWARD -i %s -o %s  -m state  --state RELATED,ESTABLISHED -j ACCEPT", nat_interface, interface);
  system(command);

  snprintf(command, 128, "/sbin/iptables -A FORWARD -i %s -o %s -j ACCEPT", interface, nat_interface);
  system(command);

  free(interface);
  free(nat_interface);
  log_debug("ipforwarding success!\n");
  return(0);
}
Esempio n. 8
0
static DEVICE_START( cdp1852 )
{
	cdp1852_t *cdp1852 = get_safe_token(device);
	const cdp1852_interface *intf = get_interface(device);

	/* resolve callbacks */
	devcb_resolve_read8(&cdp1852->in_data_func, &intf->in_data_func, device);
	devcb_resolve_write8(&cdp1852->out_data_func, &intf->out_data_func, device);
	devcb_resolve_write_line(&cdp1852->out_sr_func, &intf->out_sr_func, device);

	/* set initial values */
	cdp1852->mode = (cdp1852_mode)intf->mode;

	if (device->clock() > 0)
	{
		/* create the scan timer */
		cdp1852->scan_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1852_scan_tick), (void *)device);
		cdp1852->scan_timer->adjust(attotime::zero, 0, attotime::from_hz(device->clock()));
	}

	/* register for state saving */
	device->save_item(NAME(cdp1852->new_data));
	device->save_item(NAME(cdp1852->data));
	device->save_item(NAME(cdp1852->next_data));
	device->save_item(NAME(cdp1852->sr));
	device->save_item(NAME(cdp1852->next_sr));
}
Esempio n. 9
0
krb5_error_code
k5_plugin_load(krb5_context context, int interface_id, const char *modname,
               krb5_plugin_initvt_fn *module)
{
    krb5_error_code ret;
    struct plugin_interface *interface = get_interface(context, interface_id);
    struct plugin_mapping **mp, *map;

    if (interface == NULL)
        return EINVAL;
    ret = configure_interface(context, interface_id);
    if (ret != 0)
        return ret;
    for (mp = interface->modules; mp != NULL && *mp != NULL; mp++) {
        map = *mp;
        if (strcmp(map->modname, modname) == 0) {
            load_if_needed(context, map, interface_names[interface_id]);
            if (map->module != NULL) {
                *module = map->module;
                return 0;
            }
            break;
        }
    }
    krb5_set_error_message(context, KRB5_PLUGIN_NAME_NOTFOUND,
                           _("Could not find %s plugin module named '%s'"),
                           interface_names[interface_id], modname);
    return KRB5_PLUGIN_NAME_NOTFOUND;
}
Esempio n. 10
0
krb5_error_code
k5_plugin_load_all(krb5_context context, int interface_id,
                   krb5_plugin_initvt_fn **modules)
{
    krb5_error_code ret;
    struct plugin_interface *interface = get_interface(context, interface_id);
    struct plugin_mapping **mp, *map;
    krb5_plugin_initvt_fn *list;
    size_t count;

    if (interface == NULL)
        return EINVAL;
    ret = configure_interface(context, interface_id);
    if (ret != 0)
        return ret;

    /* Count the modules and allocate a list to hold them. */
    mp = interface->modules;
    for (count = 0; mp != NULL && mp[count] != NULL; count++);
    list = calloc(count + 1, sizeof(*list));
    if (list == NULL)
        return ENOMEM;

    /* Place each module's initvt function into list. */
    count = 0;
    for (mp = interface->modules; mp != NULL && *mp != NULL; mp++) {
        map = *mp;
        load_if_needed(context, map, interface_names[interface_id]);
        if (map->module != NULL)
            list[count++] = map->module;
    }

    *modules = list;
    return 0;
}
Esempio n. 11
0
int load_plugin(struct oh_plugin_config *config)
{
    lt_dlhandle h;
    int (*get_interface) (struct oh_abi_v1 ** pp, const uuid_t uuid);
    int err;

    h = lt_dlopenext(config->name);
    if (h == NULL) {
        dbg("Can not find %s plugin", config->name);
        goto err1;
    }

    get_interface = lt_dlsym(h, "get_interface");
    if (!get_interface) {
        dbg("Can not get 'get_interface' symbol, is it a plugin?!");
        goto err1;
    }

    err = get_interface(&config->abi, UUID_OH_ABI_V1);
    if (err < 0 || !config->abi || !config->abi->open) {
        dbg("Can not get ABI V1");
        goto err1;
    }

    return 0;
err1:
    lt_dlclose(h);
    return -1;
}
Esempio n. 12
0
static int xusb_fill_strings(struct xusb *xusb)
{
	const struct usb_device_descriptor	*dev_desc;
	const struct usb_interface_descriptor	*iface_desc;


	dev_desc = &xusb->dev->descriptor;
	assert(dev_desc);
	if (GET_USB_STRING(xusb, dev_desc, iManufacturer) < 0) {
		ERR("Failed reading iManufacturer string: %s\n",
			usb_strerror());
		return 0;
	}
	if (GET_USB_STRING(xusb, dev_desc, iProduct) < 0) {
		ERR("Failed reading iProduct string: %s\n",
			usb_strerror());
		return 0;
	}
	if (GET_USB_STRING(xusb, dev_desc, iSerialNumber) < 0) {
		ERR("Failed reading iSerialNumber string: %s\n",
			usb_strerror());
		return 0;
	}
	iface_desc = get_interface(xusb->dev, xusb->interface_num, 0);
	if (!iface_desc) {
		ERR("Could not get interface descriptor of device: %s\n",
			usb_strerror());
		return 0;
	}
	if (GET_USB_STRING(xusb, iface_desc, iInterface) < 0) {
		ERR("Failed reading iInterface string: %s\n", usb_strerror());
		return 0;
	}
	return 1;
}
Esempio n. 13
0
static DEVICE_START( cdp1861 )
{
	cdp1861_t *cdp1861 = get_safe_token(device);
	const cdp1861_interface *intf = get_interface(device);

	/* resolve callbacks */
	devcb_resolve_write_line(&cdp1861->out_int_func, &intf->out_int_func, device);
	devcb_resolve_write_line(&cdp1861->out_dmao_func, &intf->out_dmao_func, device);
	devcb_resolve_write_line(&cdp1861->out_efx_func, &intf->out_efx_func, device);

	/* get the cpu */
	cdp1861->cpu = device->machine().device<cpu_device>(intf->cpu_tag);

	/* get the screen device */
	cdp1861->screen =  device->machine().device<screen_device>(intf->screen_tag);
	assert(cdp1861->screen != NULL);

	/* allocate the temporary bitmap */
	cdp1861->bitmap = auto_bitmap_alloc(device->machine(), cdp1861->screen->width(), cdp1861->screen->height(), cdp1861->screen->format());

	/* create the timers */
	cdp1861->int_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1861_int_tick), (void *)device);
	cdp1861->efx_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1861_efx_tick), (void *)device);
	cdp1861->dma_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1861_dma_tick), (void *)device);

	/* register for state saving */
	device->save_item(NAME(cdp1861->disp));
	device->save_item(NAME(cdp1861->dispon));
	device->save_item(NAME(cdp1861->dispoff));
	device->save_item(NAME(cdp1861->dmaout));
	device->save_item(NAME(*cdp1861->bitmap));
}
Esempio n. 14
0
static DEVICE_START( cdp1852 )
{
	cdp1852_t *cdp1852 = get_safe_token(device);
	const cdp1852_interface *intf = get_interface(device);

	/* resolve callbacks */
	devcb_resolve_read8(&cdp1852->in_data_func, &intf->in_data_func, device);
	devcb_resolve_write8(&cdp1852->out_data_func, &intf->out_data_func, device);
	devcb_resolve_write_line(&cdp1852->out_sr_func, &intf->out_sr_func, device);

	/* set initial values */
	cdp1852->mode = (cdp1852_mode)intf->mode;

	if (device->clock > 0)
	{
		/* create the scan timer */
		cdp1852->scan_timer = timer_alloc(device->machine, cdp1852_scan_tick, (void *)device);
		timer_adjust_periodic(cdp1852->scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock));
	}

	/* register for state saving */
	state_save_register_device_item(device, 0, cdp1852->new_data);
	state_save_register_device_item(device, 0, cdp1852->data);
	state_save_register_device_item(device, 0, cdp1852->next_data);
	state_save_register_device_item(device, 0, cdp1852->sr);
	state_save_register_device_item(device, 0, cdp1852->next_sr);
}
/*
 * This method gets called when user tapped tab key.
 * line - points to command line
 * len - size of line that should be used for completions. This should be
 *   cursor position during tab hit.
 */
void process_tab(const char *line, int len)
{
	int argc;
	static split_arg_t buf[(LINE_BUF_MAX * 2) / sizeof(split_arg_t)];
	const struct method *method;

	argc = split_command(line, len, buf, sizeof(buf));
	tab_hit_count++;

	if (argc == 0)
		return;

	if (argc == 1) {
		command_completion(buf);
		return;
	}

	method = get_command(buf[0].ntcopy);
	if (method != NULL) {
		param_completion(argc, buf, method, 1);
	} else if (argc == 2) {
		method_completion(get_interface(buf[0].ntcopy), buf);
	} else {
		/* Find method for <interface, name> pair */
		method = get_interface_method(buf[0].ntcopy,
							buf[0].next->ntcopy);
		param_completion(argc, buf, method, 2);
	}
}
Esempio n. 16
0
static int xusb_fill_strings(struct xusb *xusb)
{
	const struct usb_device_descriptor	*dev_desc;
	const struct usb_interface_descriptor	*iface_desc;


	dev_desc = &xusb->dev->descriptor;
	assert(dev_desc);
	if(get_usb_string(xusb, dev_desc->iManufacturer, xusb->iManufacturer, BUFSIZ) < 0) {
		ERR("Failed reading iManufacturer string: %s\n", usb_strerror());
		return 0;
	}
	if(get_usb_string(xusb, dev_desc->iProduct, xusb->iProduct, BUFSIZ) < 0) {
		ERR("Failed reading iProduct string: %s\n", usb_strerror());
		return 0;
	}
	if(get_usb_string(xusb, dev_desc->iSerialNumber, xusb->iSerialNumber, BUFSIZ) < 0) {
		ERR("Failed reading iSerialNumber string: %s\n", usb_strerror());
		return 0;
	}
	if((iface_desc = get_interface(xusb->dev, xusb->interface_num, 0)) == NULL) {
		ERR("Could not get interface descriptor of device: %s\n", usb_strerror());
		return 0;
	}
	if(get_usb_string(xusb, iface_desc->iInterface, xusb->iInterface, BUFSIZ) < 0) {
		ERR("Failed reading iInterface string: %s\n", usb_strerror());
		return 0;
	}
	return 1;
}
Esempio n. 17
0
static DEVICE_START( nmk112 )
{
	nmk112_state *nmk112 = get_safe_token(device);
	const nmk112_interface *intf = get_interface(device);

	if (intf->rgn0 == NULL)
	{
		nmk112->rom0 = NULL;
		nmk112->size0 = 0;
	}
	else
	{
		nmk112->rom0 = device->machine().root_device().memregion(intf->rgn0)->base();
		nmk112->size0 = device->machine().root_device().memregion(intf->rgn0)->bytes() - 0x40000;
	}

	if (intf->rgn1 == NULL)
	{
		nmk112->rom1 = NULL;
		nmk112->size1 = 0;
	}
	else
	{
		nmk112->rom1 = device->machine().root_device().memregion(intf->rgn1)->base();
		nmk112->size1 = device->machine().root_device().memregion(intf->rgn1)->bytes() - 0x40000;
	}

	nmk112->page_mask = ~intf->disable_page_mask;

	device->save_item(NAME(nmk112->current_bank));
	device->machine().save().register_postload(save_prepost_delegate(FUNC(nmk112_postload_bankswitch), nmk112));
}
Esempio n. 18
0
static void tc8521_set_alarm_output(device_t *device)
{
	tc8521_t *rtc = get_token(device);
	const tc8521_interface *rtc_interface = get_interface(device);
	unsigned char alarm_output;

	alarm_output = 0;

	/* what happens when all are enabled? I assume they are all or'd together */

	/* 16 Hz enabled? */
    if ((rtc->registers[TC8521_RESET_REGISTER] & (1<<2))==0)
    {
		/* yes */

		/* add in state of 16 Hz output */
		alarm_output |= (rtc->alarm_outputs & ALARM_OUTPUT_16HZ);
	}

	if ((rtc->registers[TC8521_RESET_REGISTER] & (1<<3))==0)
	{
		/* yes */
		/* add in stat of 1 Hz output */
		alarm_output |= ((rtc->alarm_outputs & ALARM_OUTPUT_1HZ)>>1);
	}
Esempio n. 19
0
bool Entity::get_prototype_as_scheme(char *buf, int bufsz) {
	E_RETURN_VAL_IF_FAIL(name != NULL, false);
	E_RETURN_VAL_IF_FAIL(tp != ENTITY_NONE, false);

	String ret;
	if(tp == ENTITY_SIGNAL) {
		ret.printf("(dbus-signal \"%s\" \"%s\" \"%s\"", get_path(), get_interface(), get_name());
		if(args.empty()) {
			ret += ")";
		} else {
			String scm_params;
			signature_to_scheme(args, scm_params);

			if(!scm_params.empty()) {
				ret += ' ';
				ret += scm_params;
			}

			ret += ')';
		}
	} else if(tp == ENTITY_METHOD) {
		ret.printf("(dbus-call \"%s\" \"%s\" \"%s\" \"%s\"", get_service(), get_path(), get_interface(), get_name());
		if(args.empty())
			ret += ")";
		else {
			String scm_params;
			signature_to_scheme(args, scm_params);

			if(!scm_params.empty()) {
				ret += ' ';
				ret += scm_params;
			}

			ret += ')';
		}
	} else {
		/* property */
		ret.printf("(dbus-property-get \"%s\" \"%s\" \"%s\" \"%s\")", get_service(), get_path(), get_interface(), get_name());
	}

	if(!ret.empty()) {
		edelib_strlcpy(buf, ret.c_str(), bufsz);
		return true;
	}

	return false;
}
Esempio n. 20
0
void
taskbar_progress_c::set_value(ULONGLONG completed,
                              ULONGLONG total) {
  m_completed = completed;
  m_total     = total;

  if (NULL != get_interface())
    m_interface->lpVtbl->SetProgressValue(m_interface, GetHwndOf(m_window), m_completed, m_total);
}
/* function returns method of given name or NULL if not found */
const struct method *get_interface_method(const char *iname,
							const char *mname)
{
	const struct interface *iface = get_interface(iname);

	if (iface == NULL)
		return NULL;

	return get_method(iface->methods, mname);
}
Esempio n. 22
0
static DEVICE_START( pia6821 )
{
	pia6821_state *p = get_token(device);
	const pia6821_interface *intf = get_interface(device);

	/* clear structure */
	memset(p, 0, sizeof(*p));

	/* resolve callbacks */
	devcb_resolve_read8(&p->in_a_func, &intf->in_a_func, device);
	devcb_resolve_read8(&p->in_b_func, &intf->in_b_func, device);
	devcb_resolve_read_line(&p->in_ca1_func, &intf->in_ca1_func, device);
	devcb_resolve_read_line(&p->in_cb1_func, &intf->in_cb1_func, device);
	devcb_resolve_read_line(&p->in_ca2_func, &intf->in_ca2_func, device);
	devcb_resolve_read_line(&p->in_cb2_func, &intf->in_cb2_func, device);
	devcb_resolve_write8(&p->out_a_func, &intf->out_a_func, device);
	devcb_resolve_write8(&p->out_b_func, &intf->out_b_func, device);
	devcb_resolve_write_line(&p->out_ca2_func, &intf->out_ca2_func, device);
	devcb_resolve_write_line(&p->out_cb2_func, &intf->out_cb2_func, device);
	devcb_resolve_write_line(&p->irq_a_func, &intf->irq_a_func, device);
	devcb_resolve_write_line(&p->irq_b_func, &intf->irq_b_func, device);

	state_save_register_device_item(device, 0, p->in_a);
	state_save_register_device_item(device, 0, p->in_ca1);
	state_save_register_device_item(device, 0, p->in_ca2);
	state_save_register_device_item(device, 0, p->out_a);
	state_save_register_device_item(device, 0, p->out_ca2);
	state_save_register_device_item(device, 0, p->port_a_z_mask);
	state_save_register_device_item(device, 0, p->ddr_a);
	state_save_register_device_item(device, 0, p->ctl_a);
	state_save_register_device_item(device, 0, p->irq_a1);
	state_save_register_device_item(device, 0, p->irq_a2);
	state_save_register_device_item(device, 0, p->irq_a_state);
	state_save_register_device_item(device, 0, p->in_b);
	state_save_register_device_item(device, 0, p->in_cb1);
	state_save_register_device_item(device, 0, p->in_cb2);
	state_save_register_device_item(device, 0, p->out_b);
	state_save_register_device_item(device, 0, p->out_cb2);
	state_save_register_device_item(device, 0, p->last_out_cb2_z);
	state_save_register_device_item(device, 0, p->ddr_b);
	state_save_register_device_item(device, 0, p->ctl_b);
	state_save_register_device_item(device, 0, p->irq_b1);
	state_save_register_device_item(device, 0, p->irq_b2);
	state_save_register_device_item(device, 0, p->irq_b_state);
	state_save_register_device_item(device, 0, p->in_a_pushed);
	state_save_register_device_item(device, 0, p->out_a_needs_pulled);
	state_save_register_device_item(device, 0, p->in_ca1_pushed);
	state_save_register_device_item(device, 0, p->in_ca2_pushed);
	state_save_register_device_item(device, 0, p->out_ca2_needs_pulled);
	state_save_register_device_item(device, 0, p->in_b_pushed);
	state_save_register_device_item(device, 0, p->out_b_needs_pulled);
	state_save_register_device_item(device, 0, p->in_cb1_pushed);
	state_save_register_device_item(device, 0, p->in_cb2_pushed);
	state_save_register_device_item(device, 0, p->out_cb2_needs_pulled);
}
Esempio n. 23
0
static DEVICE_START( adc0831 )
{
	adc0831_state *adc083x = get_safe_token( device );
	const adc083x_interface *intf = get_interface( device );

	adc083x->cs = 0;
	adc083x->clk = 0;
	adc083x->di = 0;
	adc083x->se = 0;
	adc083x_clear_sars( device, adc083x );
	adc083x->_do = 1;
	adc083x->sgl = 0;
	adc083x->odd = 0;
	adc083x->sel1 = 0;
	adc083x->sel0 = 0;
	adc083x->state = STATE_IDLE;
	adc083x->bit = 0;
	adc083x->output = 0;

	if( device->type() == ADC0831 )
	{
		adc083x->mux_bits = 0;
	}
	else if( device->type() == ADC0832 )
	{
		adc083x->mux_bits = 2;
	}
	else if( device->type() == ADC0834 )
	{
		adc083x->mux_bits = 3;
	}
	else if( device->type() == ADC0838 )
	{
		adc083x->mux_bits = 4;
	}

	/* resolve callbacks */
	adc083x->input_callback_r = intf->input_callback_r;

	/* register for state saving */
	device->save_item( NAME(adc083x->cs) );
	device->save_item( NAME(adc083x->clk) );
	device->save_item( NAME(adc083x->di) );
	device->save_item( NAME(adc083x->se) );
	device->save_item( NAME(adc083x->sars) );
	device->save_item( NAME(adc083x->_do) );
	device->save_item( NAME(adc083x->sgl) );
	device->save_item( NAME(adc083x->odd) );
	device->save_item( NAME(adc083x->sel1) );
	device->save_item( NAME(adc083x->sel0) );
	device->save_item( NAME(adc083x->state) );
	device->save_item( NAME(adc083x->bit) );
	device->save_item( NAME(adc083x->output) );
	device->save_item( NAME(adc083x->mux_bits) );
}
Esempio n. 24
0
static struct frame_t *create_frame_t(struct sr_instance *sr, void *frame, size_t len, char *if_name)
{
    struct frame_t *new_frame = (struct frame_t *)malloc(sizeof(struct frame_t));
    
    assert(new_frame);
    
    new_frame->frame = malloc(len);
    
    assert(new_frame->frame);
    
    memcpy(new_frame->frame, frame, len); //we make a copy of the frame so we can keep it around in queue, etc
    new_frame->len = len;
    new_frame->ether_header = (struct sr_ethernet_hdr *)new_frame->frame;
    new_frame->in_or_out = IN;
    new_frame->MAC_set = 1;
    memcpy(new_frame->from_MAC, new_frame->ether_header->ether_shost, ETHER_ADDR_LEN);
    memcpy(new_frame->to_MAC, new_frame->ether_header->ether_dhost, ETHER_ADDR_LEN);
    new_frame->icmp_header = NULL;
    new_frame->ip_len = 0;
    new_frame->ip_hl = 0;
    
    if (ntohs(new_frame->ether_header->ether_type)==ETHERTYPE_IP){
        new_frame->ip_header = (struct ip *)(new_frame->frame + sizeof(struct sr_ethernet_hdr));
        new_frame->arp_header = NULL;
        
        assert (new_frame->ip_header);
        
        new_frame->ip_len = ntohs(new_frame->ip_header->ip_len);
        new_frame->ip_hl = new_frame->ip_header->ip_hl * WORDTOBYTE;
        new_frame->from_ip = new_frame->ip_header->ip_src.s_addr;
        new_frame->to_ip = new_frame->ip_header->ip_dst.s_addr;
        if (new_frame->ip_header->ip_p == IPPROTO_ICMP)
            new_frame->icmp_header = (struct icmp_hdr *)((void *)new_frame->ip_header + new_frame->ip_hl);

    }
    else if(ntohs(new_frame->ether_header->ether_type)==ETHERTYPE_ARP){
        new_frame->arp_header = (struct sr_arphdr *) (new_frame->frame + sizeof(struct sr_ethernet_hdr));
        new_frame->ip_header = NULL;
        
        assert(new_frame->arp_header);
        
        new_frame->from_ip = new_frame->arp_header->ar_sip;
        new_frame->to_ip = new_frame->arp_header->ar_tip;
    }
    else{
        perror("Unrecognized protocol");
        free(new_frame->frame);
        free(new_frame);
        return NULL;
    }
    new_frame->iface = get_interface(sr, if_name);
    
    return new_frame;
}
Esempio n. 25
0
static void scc_updateirqs(device_t *device)
{
	scc8530_t *scc = get_token(device);
	int irqstat;

	irqstat = 0;
	if (scc->MasterIRQEnable)
	{
		if ((scc->channel[0].txIRQEnable) && (scc->channel[0].txIRQPending))
		{
			scc->IRQType = IRQ_B_TX;
			irqstat = 1;
		}
		else if ((scc->channel[1].txIRQEnable) && (scc->channel[1].txIRQPending))
		{
			scc->IRQType = IRQ_A_TX;
			irqstat = 1;
		}
		else if ((scc->channel[0].extIRQEnable) && (scc->channel[0].extIRQPending))
		{
			scc->IRQType = IRQ_B_EXT;
			irqstat = 1;
		}
		else if ((scc->channel[1].extIRQEnable) && (scc->channel[1].extIRQPending))
		{
			scc->IRQType = IRQ_A_EXT;
			irqstat = 1;
		}
	}
	else
	{
		scc->IRQType = IRQ_NONE;
	}

//  printf("SCC: irqstat %d, last %d\n", irqstat, scc->lastIRQStat);
//  printf("ch0: en %d pd %d  ch1: en %d pd %d\n", scc->channel[0].txIRQEnable, scc->channel[0].txIRQPending, scc->channel[1].txIRQEnable, scc->channel[1].txIRQPending);

	// don't spam the driver with unnecessary transitions
	if (irqstat != scc->lastIRQStat)
	{
		const scc8530_interface *intf = get_interface(device);

		scc->lastIRQStat = irqstat;

		// tell the driver the new IRQ line status if possible
		if ((intf != NULL) && (intf->irq != NULL))
		{
			#if LOG_SCC
			printf("SCC8530 IRQ status => %d\n", irqstat);
			#endif
			(*intf->irq)(device, irqstat);
		}
	}
}
Esempio n. 26
0
//-----------------------------------------------------------------
// usb_process_request:
//-----------------------------------------------------------------
static void usb_process_request(struct device_request *request, unsigned char type, unsigned char req, unsigned char *data)
{
	if ( type == USB_STANDARD_REQUEST )
	{
        // Standard requests
        switch (req)
        {
        case REQ_GET_STATUS:
            get_status(request);
            break;
        case REQ_CLEAR_FEATURE:
            clear_feature(request);
            break;
        case REQ_SET_FEATURE:
            set_feature(request);
            break;
        case REQ_SET_ADDRESS:
            set_address(request);
            break;
        case REQ_GET_DESCRIPTOR:
            get_descriptor(request);
            break;
        case REQ_GET_CONFIGURATION:
            get_configuration(request);
            break;
        case REQ_SET_CONFIGURATION:
            set_configuration(request);
            break;
        case REQ_GET_INTERFACE:
            get_interface(request);
            break;
        case REQ_SET_INTERFACE:
            set_interface(request);
            break;
        default:
            log_printf(USBLOG_ERR, "USB: Unknown standard request %x\n", req);
		    usbhw_control_endpoint_stall();
            break;
        }
	}
	else if ( type == USB_VENDOR_REQUEST )
	{
        log_printf(USBLOG_ERR, "Vendor: Unknown command\n");

        // None supported
		usbhw_control_endpoint_stall();
	}
	else if ( type == USB_CLASS_REQUEST && _class_request)
	{
        _class_request(req, request->wValue, request->wIndex, data, request->wLength);
	}
	else
        usbhw_control_endpoint_stall();
}
Esempio n. 27
0
/*
 * Called only in main thread.  Note that wireless interfaces are considered
 * "ok" even if the IFF_RUNNING bit isn't set.  This is because AP attach
 * occurs as part of the LLP selection process.
 */
boolean_t
is_interface_ok(const char *ifname)
{
	boolean_t is_ok = B_FALSE;
	struct interface *ifp;

	if ((ifp = get_interface(ifname)) != NULL &&
	    !(ifp->if_lflags & IF_DHCPFAILED) && is_startable(ifp))
		is_ok = B_TRUE;
	return (is_ok);
}
void
sc_inout_resolved::end_of_elaboration()
{
    base_type::end_of_elaboration();
    // check if bound channel is a resolved signal
    if( DCAST<sc_signal_resolved*>( get_interface() ) == 0 ) {
	char msg[BUFSIZ];
	std::sprintf( msg, "%s (%s)", name(), kind() );
	SC_REPORT_ERROR( SC_ID_RESOLVED_PORT_NOT_BOUND_, msg );
    }
}
Esempio n. 29
0
static int read_packet(llist *l, probe_ctx *ctx, oval_schema_version_t over)
{
	int line = 0;
	FILE *f;
	char buf[256];

	void *s;
	int refcnt, sk_type, ifindex, running;
	unsigned long inode;
	unsigned rmem, uid, proto_num;
	struct interface_t interface;


	f = fopen("/proc/net/packet", "rt");
	if (f == NULL) {
		if (errno != ENOENT)
			return 1;
		else
			return 0;
	}
	__fsetlocking(f, FSETLOCKING_BYCALLER);
	while (fgets(buf, sizeof(buf), f)) {
		if (line == 0) {
			line++;
			continue;
		}
		/* follow structure from net/packet/af_packet.c */
		sscanf(buf,
			"%p %d %d %04x %d %d %u %u %lu\n",
			&s, &refcnt, &sk_type, &proto_num, &ifindex, &running, &rmem, &uid, &inode
		);
		if (list_find_inode(l, inode) && get_interface(ifindex, &interface)) {
			struct result_info r;
			SEXP_t *r0;
			dI("Have interface_name: %s, hw_address: %s\n",
					interface.interface_name, interface.hw_address);

			r0 = SEXP_string_newf("%s", interface.interface_name);
			if (probe_entobj_cmp(interface_name_ent, r0) != OVAL_RESULT_TRUE) {
				SEXP_free(r0);
				continue;
			}
			SEXP_free(r0);

			r.interface_name = interface.interface_name;
			r.protocol = oscap_enum_to_string(ProtocolType, proto_num);
			r.hw_address = interface.hw_address;
			report_finding(&r, l, ctx, over);
		}
	}
	fclose(f);
	return 0;
}
Esempio n. 30
0
void pim_router::data_available(uint32_t) {
	int recvlen = pim_sock.recvfrom(g_mrd->ipktb->buffer(), g_mrd->ipktb->bufferlen());

	if (recvlen < 0) {
		if (should_log(WARNING))
			log().perror("recv failed");
		return;
	}

	if (recvlen < (int)sizeof(pim_message)) {
		// discard
		return;
	}

	sockaddr_in6 dst;
	int index;

	if (!pim_sock.destination_address(dst, index) || index == 0) {
		pim_message *pimmsg = g_mrd->ipktb->header<pim_message>();

		if (should_log(INTERNAL_FLOW)) {
			log().xprintf("Dropped %s message from %{addr}, no "
				      "input interface.\n", pimmsg->type_name(),
				      pim_sock.source_address().sin6_addr);
		}

		return;
	}

	g_mrd->ipktb->rlength = recvlen;
	g_mrd->ipktb->read_offset = 0;

	pim_interface *pimintf = get_interface(index);
	if (!pimintf) {
		pim_message *pimmsg = g_mrd->ipktb->header<pim_message>();

		if (should_log(INTERNAL_FLOW)) {
			log().xprintf("Dropped %s message from %{addr}, PIM "
				      "interface %i is disabled.\n",
				      pimmsg->type_name(),
				      pim_sock.source_address().sin6_addr,
				      index);
		}

		return;
	}

	g_mrd->ipktb->source = pimintf->owner();

	sockaddr_in6 _recvfrom = pim_sock.source_address();

	pimintf->data_available(&_recvfrom, &dst);
}