static void device_devup_setup(int index) { configure_device(index); start_security_manager(index); /* Return value 1 means ioctl(DEVDOWN) was performed */ if (manager_start_adapter(index) == 1) stop_security_manager(index); }
static void complete_device(struct netdev *dev) { postprocess_device(dev); configure_device(dev); dump_device_config(dev); print_device_config(dev); ++configured; dev->next = ifaces; ifaces = dev; }
/****************************************************** * Function Definitions ******************************************************/ void application_start( ) { /* Initialise the device */ wiced_init( ); //WPRINT_APP_INFO(("Version data & time 2015/09/06 10:00\n")); /* Configure the device */ configure_device(); if(device_init() != WICED_SUCCESS){ WPRINT_APP_INFO(("device_init failed\n")); return; } WPRINT_APP_INFO(("end ...\n")); }
int configure_mrr_device(const char* mac, const char* dest_ip, int dest_port, const char* local_ip, int local_port, const char* mask_ip, const char* gateway) { DEVICE_CONF_PARAM_T conf_param; sprintf(conf_param.mac, "%s", mac); sprintf(conf_param.password, "%s", DEFAULT_CONF_PASSWORD); sprintf(conf_param.dest_ip, "%s", dest_ip); sprintf(conf_param.local_ip, "%s", local_ip); sprintf(conf_param.mask_ip, "%s", mask_ip); sprintf(conf_param.gateway, "%s", gateway); conf_param.dest_port = dest_port; conf_param.local_port = local_port; conf_param.work_mode = 1; conf_param.bit_rate = 9600; conf_param.id = 0; conf_param.com_flag = 3; return configure_device(&conf_param); }
/* Set some sockaddr type of info. */ static kern_return_t siocsifXaddr (io_t port, ifname_t ifnam, sockaddr_t *addr, enum siocgif_type type) { struct sock_user *user = begin_using_socket_port(port); error_t err = 0; struct device *dev; struct sockaddr_in *sin = (struct sockaddr_in *) addr; uint32_t addrs[4]; if (!user) return EOPNOTSUPP; dev = get_dev (ifnam); if (!user->isroot) err = EPERM; else if (!dev) err = ENODEV; else if (sin->sin_family != AF_INET) err = EINVAL; else if (user->sock->sk->family != AF_INET) err = EINVAL; else { inquire_device (dev, &addrs[0], &addrs[1], &addrs[2], &addrs[3]); addrs[type] = sin->sin_addr.s_addr; err = configure_device (dev, addrs[0], addrs[1], addrs[2], addrs[3]); } __mutex_unlock (&global_lock); end_using_socket_port (user); return err; }
static void setup_tun_net(char *arg) { struct device *dev; struct net_info *net_info = malloc(sizeof(*net_info)); int ipfd; u32 ip = INADDR_ANY; bool bridging = false; char tapif[IFNAMSIZ], *p; struct virtio_net_config conf; net_info->tunfd = get_tun_device(tapif); dev = new_device("net", VIRTIO_ID_NET); dev->priv = net_info; add_virtqueue(dev, VIRTQUEUE_NUM, net_input); add_virtqueue(dev, VIRTQUEUE_NUM, net_output); ipfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (ipfd < 0) err(1, "opening IP socket"); if (!strncmp(BRIDGE_PFX, arg, strlen(BRIDGE_PFX))) { arg += strlen(BRIDGE_PFX); bridging = true; } p = strchr(arg, ':'); if (p) { str2mac(p+1, conf.mac); add_feature(dev, VIRTIO_NET_F_MAC); *p = '\0'; } if (bridging) add_to_bridge(ipfd, tapif, arg); else ip = str2ip(arg); configure_device(ipfd, tapif, ip); add_feature(dev, VIRTIO_NET_F_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_TSO4); add_feature(dev, VIRTIO_NET_F_GUEST_TSO6); add_feature(dev, VIRTIO_NET_F_GUEST_ECN); add_feature(dev, VIRTIO_NET_F_HOST_TSO4); add_feature(dev, VIRTIO_NET_F_HOST_TSO6); add_feature(dev, VIRTIO_NET_F_HOST_ECN); add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC); set_config(dev, sizeof(conf), &conf); close(ipfd); devices.device_num++; if (bridging) verbose("device %u: tun %s attached to bridge: %s\n", devices.device_num, tapif, arg); else verbose("device %u: tun %s: %s\n", devices.device_num, tapif, arg); }
void setup(){ //! Clear the interrupt flag, to void all interrupts //! coming in during the setup phase cli(); //! Loads the settings saved in NVRAM //! Also loads the commands to the cached mem. nvram.load(); configure_device(&nvram); #ifdef DEBUG DEBUG_SERIAL.println("STARTING DEBUG ENGINE"); #endif #ifdef DEBUG //! Start Debug Engine. debug_api.enable_debug(); #endif #ifdef DEBUG_LEDs //! Check LEDs debug_api.test_leds(); debug_api.set_leds(CLEAR_ERRORS); #endif #ifdef DEBUG DEBUG_SERIAL.println("STARTED DEBUG ENGINE"); #endif //! sets the sdecoder objdect. packet_parser.set_handler(&packet_decoder); //! Reset and reboot device. attachInterrupt(SELECT_BUTTON_2, reset_device, CHANGE); #ifdef DEBUG DEBUG_SERIAL.println("INTERRUPT ATTACHED TO BUTTON 2"); DEBUG_SERIAL.println("ENTERING SELECT LOOP"); #endif //! Wait 5sec to check the pin. delay(FIVE_SECONDS); //! Check choice (default = Emulation). //! 1 - Emulation //! 0 - Real USB device if(digitalRead(SELECT_BUTTON_1) == HIGH){ //! Defines the generic pointer (EMULATION). //! This is where we setup the object pointer. EMULATION_DEVICE emulation_device(&joystick_report); generic_pointer = &emulation_device; emulation_chosen = true; #ifdef DEBUG DEBUG_SERIAL.println("EMULATION CHOSEN"); #endif }else if(digitalRead(SELECT_BUTTON_1) == LOW){ //! Define the generic pointer (USB HOST DEVICE). //! This is where we setup the object pointer. USB_DEVICE usb_host_device(&command_interpreter, &packet_parser, &joystick_report); generic_pointer = &usb_host_device; usb_device_chosen = true; #ifdef DEBUG DEBUG_SERIAL.println("USB DEVICE CHOSEN"); #endif }else{ //! If none of the above, reset the device. #ifdef DEBUG_LEDs debug_api.set_leds(REBOOT_ERROR); #endif error((void*)__LINE__, (void*)__func__); } //! Timer is initialized to keep track of the CPU idle time. TCCR1B = _BV(CS12) | _BV(CS11); #ifdef DEBUG DEBUG_SERIAL.println("USB INIT STATE"); #endif #ifdef DEBUG DEBUG_SERIAL.println("MEM CHECK"); #endif //! Check memory integrity if(memory_check() <= EMPTY) #ifdef DEBUG_LEDs debug_api.set_leds(MEMORY_ERROR); #endif error((void*)__LINE__, (void*)__func__); #ifdef DEBUG DEBUG_SERIAL.println("RESUME INTERRUPTS"); #endif //! Resume interrupt handling sei(); }
/*L:195 * Our network is a Host<->Guest network. This can either use bridging or * routing, but the principle is the same: it uses the "tun" device to inject * packets into the Host as if they came in from a normal network card. We * just shunt packets between the Guest and the tun device. */ static void setup_tun_net(char *arg) { struct device *dev; struct net_info *net_info = malloc(sizeof(*net_info)); int ipfd; u32 ip = INADDR_ANY; bool bridging = false; char tapif[IFNAMSIZ], *p; struct virtio_net_config conf; net_info->tunfd = get_tun_device(tapif); /* First we create a new network device. */ dev = new_device("net", VIRTIO_ID_NET); dev->priv = net_info; /* Network devices need a recv and a send queue, just like console. */ add_virtqueue(dev, VIRTQUEUE_NUM, net_input); add_virtqueue(dev, VIRTQUEUE_NUM, net_output); /* * We need a socket to perform the magic network ioctls to bring up the * tap interface, connect to the bridge etc. Any socket will do! */ ipfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); if (ipfd < 0) err(1, "opening IP socket"); /* If the command line was --tunnet=bridge:<name> do bridging. */ if (!strncmp(BRIDGE_PFX, arg, strlen(BRIDGE_PFX))) { arg += strlen(BRIDGE_PFX); bridging = true; } /* A mac address may follow the bridge name or IP address */ p = strchr(arg, ':'); if (p) { str2mac(p+1, conf.mac); add_feature(dev, VIRTIO_NET_F_MAC); *p = '\0'; } /* arg is now either an IP address or a bridge name */ if (bridging) add_to_bridge(ipfd, tapif, arg); else ip = str2ip(arg); /* Set up the tun device. */ configure_device(ipfd, tapif, ip); /* Expect Guest to handle everything except UFO */ add_feature(dev, VIRTIO_NET_F_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_CSUM); add_feature(dev, VIRTIO_NET_F_GUEST_TSO4); add_feature(dev, VIRTIO_NET_F_GUEST_TSO6); add_feature(dev, VIRTIO_NET_F_GUEST_ECN); add_feature(dev, VIRTIO_NET_F_HOST_TSO4); add_feature(dev, VIRTIO_NET_F_HOST_TSO6); add_feature(dev, VIRTIO_NET_F_HOST_ECN); /* We handle indirect ring entries */ add_feature(dev, VIRTIO_RING_F_INDIRECT_DESC); set_config(dev, sizeof(conf), &conf); /* We don't need the socket any more; setup is done. */ close(ipfd); devices.device_num++; if (bridging) verbose("device %u: tun %s attached to bridge: %s\n", devices.device_num, tapif, arg); else verbose("device %u: tun %s: %s\n", devices.device_num, tapif, arg); }
int main (int argc, char **argv) { error_t err; mach_port_t bootstrap; struct stat st; pthread_t thread; pfinet_bucket = ports_create_bucket (); addrport_class = ports_create_class (clean_addrport, 0); socketport_class = ports_create_class (clean_socketport, 0); mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &fsys_identity); /* Generic initialization */ init_time (); ethernet_initialize (); err = pthread_create (&thread, NULL, net_bh_worker, NULL); if (!err) pthread_detach (thread); else { errno = err; perror ("pthread_create"); } pthread_mutex_lock (&global_lock); prepare_current (1); /* Set up to call into Linux initialization. */ sk_init (); #ifdef SLAB_SKB skb_init (); #endif inet_proto_init (0); /* This initializes the Linux network device layer, including initializing each device on the `dev_base' list. For us, that means just loopback_dev, which will get fully initialized now. After this, we can use `register_netdevice' for new interfaces. */ net_dev_init (); /* ifconfig lo up 127.0.0.1 netmask 0xff000000 */ configure_device (&loopback_dev, htonl (INADDR_LOOPBACK), htonl (IN_CLASSA_NET), htonl (INADDR_NONE), htonl (INADDR_NONE)); pthread_mutex_unlock (&global_lock); /* Parse options. When successful, this configures the interfaces before returning; to do so, it will acquire the global_lock. (And when not successful, it never returns.) */ argp_parse (&pfinet_argp, argc, argv, 0,0,0); task_get_bootstrap_port (mach_task_self (), &bootstrap); pfinet_owner = pfinet_group = 0; if (bootstrap != MACH_PORT_NULL) { /* Create portclass to install on the bootstrap port. */ if(pfinet_protid_portclasses[pfinet_bootstrap_portclass] != MACH_PORT_NULL) error(1, 0, "No portclass left to assign to bootstrap port"); #ifdef CONFIG_IPV6 if (pfinet_bootstrap_portclass == PORTCLASS_INET6) pfinet_activate_ipv6 (); #endif err = trivfs_add_protid_port_class ( &pfinet_protid_portclasses[pfinet_bootstrap_portclass]); if (err) error (1, 0, "error creating control port class"); err = trivfs_add_control_port_class ( &pfinet_cntl_portclasses[pfinet_bootstrap_portclass]); if (err) error (1, 0, "error creating control port class"); /* Talk to parent and link us in. */ err = trivfs_startup (bootstrap, 0, pfinet_cntl_portclasses[pfinet_bootstrap_portclass], pfinet_bucket, pfinet_protid_portclasses[pfinet_bootstrap_portclass], pfinet_bucket, &pfinetctl); if (err) error (1, err, "contacting parent"); /* Initialize status from underlying node. */ err = io_stat (pfinetctl->underlying, &st); if (! err) { pfinet_owner = st.st_uid; pfinet_group = st.st_gid; } } else { /* no bootstrap port. */ int i; /* Check that at least one portclass has been bound, error out otherwise. */ for (i = 0; i < ARRAY_SIZE (pfinet_protid_portclasses); i++) if (pfinet_protid_portclasses[i] != MACH_PORT_NULL) break; if (i == ARRAY_SIZE (pfinet_protid_portclasses)) error (1, 0, "should be started as a translator.\n"); } /* Ask init to tell us when the system is going down, so we can try to be friendly to our correspondents on the network. */ arrange_shutdown_notification (); /* Launch */ ports_manage_port_operations_multithread (pfinet_bucket, pfinet_demuxer, 30 * 1000, 2 * 60 * 1000, 0); return 0; }