Пример #1
0
int init(void)
{
// ARA begin insert new code
#ifdef __ANDROID__
	runNEONTests();
#endif
// ARA end

	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	landscapeMeshId = render_init_mesh(
		LargeMeshVtx,sizeof(float)*6,
		LargeMeshVtx+3,sizeof(float)*6,
		LargeMeshIdx,sizeof(unsigned short)*3,
		LargeMeshVtxCount,LargeMeshIdxCount/3);

	convexMeshId = render_init_mesh(
		BarrelVtx,sizeof(float)*6,
		BarrelVtx+3,sizeof(float)*6,
		BarrelIdx,sizeof(unsigned short)*3,
		BarrelVtxCount,BarrelIdxCount/3);

	return 0;
}
Пример #2
0
Файл: oor.c Проект: biels/oor
JNIEXPORT jint JNICALL Java_org_openoverlayrouter_noroot_OOR_1JNI_oor_1start
  (JNIEnv *env, jobject thisObj, jint vpn_tun_fd, jstring storage_path)
{
    oor_dev_type_e dev_type;
    jintArray fd_list;
    uint32_t iseed = 0;  /* initial random number generator */
    pid_t pid = 0;    /* child pid */
    pid_t sid = 0;
    char log_file[1024];
    const char *path = NULL;
    lisp_xtr_t *tunnel_router;
    memset (log_file,0,sizeof(char)*1024);

    initial_setup();
    jni_init(env,thisObj);

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    oor_timers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    lctrl = ctrl_create();

    /* Detect the data plane type */
    data_plane_select();

    /** parse config and create ctrl_dev **/
    /* obtain the configuration file */
    path = (*env)->GetStringUTFChars(env, storage_path, 0);
    config_file = calloc(1024, sizeof(char));
    strcat(config_file,path);
    strcat(config_file,"oor.conf");
    strcat(log_file,path);
    strcat(log_file,"oor.log");
    (*env)->ReleaseStringUTFChars(env, storage_path, path);
    open_log_file(log_file);
    if (parse_config_file()!=GOOD){
        exit_cleanup();
        close(vpn_tun_fd);
        return (BAD);
    }
    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        OOR_LOG(LDBG_2, "Configuring data plane");
        tunnel_router = CONTAINER_OF(ctrl_dev, lisp_xtr_t, super);
        data_plane->datap_init(dev_type, tr_get_encap_type(tunnel_router), vpn_tun_fd);
        OOR_LOG(LDBG_1, "Data plane initialized");

    }
    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
     if (!ctrl_dev) {
         OOR_LOG(LDBG_1, "device NULL");
         return (BAD);
     }
     return (GOOD);
}
Пример #3
0
void hw_init()
{
	/* Status LED */
	DDRB |= (1<<PB1);

	/* Init onewire */
#ifndef OW_ONE_BUS
	ow_set_bus(&PINB,&PORTB,&DDRB,PB0);
#endif

	/* Init controller */
	ctrl_init();
}
Пример #4
0
int init(void)
{
	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	float angX,angY,r;
	render_get_view_angle(angX,angY,r);
	r *= 0.5f;
	render_set_view_angle(angX,angY,r);

	return 0;
}
int main()
{
  kb_init(&keyboard);
  stb_fake_model_init(&model);

  gl_view_init(&view);

  ctrl_init(&ctrl);
  ctrl_set_view(&view);
  ctrl_set_model(&model);

  kb_set_callback(ctrl.handler);

  view.start();

  ctrl.start();
  keyboard.start();
	model.deinit();
	puts("finish");
}
Пример #6
0
int init(void)
{
	perf_init();
	ctrl_init();
	render_init();
	physics_init();

	landscapeMeshId = render_init_mesh(
		LargeMeshVtx,sizeof(float)*6,
		LargeMeshVtx+3,sizeof(float)*6,
		LargeMeshIdx,sizeof(unsigned short)*3,
		LargeMeshVtxCount,LargeMeshIdxCount/3);

	convexMeshId = render_init_mesh(
		BarrelVtx,sizeof(float)*6,
		BarrelVtx+3,sizeof(float)*6,
		BarrelIdx,sizeof(unsigned short)*3,
		BarrelVtxCount,BarrelIdxCount/3);

	return 0;
}
Пример #7
0
void motor_init()
{
    mylogfd (MOTOFD, "[moto]init\n");
    mylogfd(1, "in motor\n");
    // init ttys
    if ((fd = ttys_init(0)) < 0) {
        exit(-1);
    }
    else
	printf("serial init ok\n");
	mylogfd(1, "in motor 2\n");
    // init ctrl
    ctrl_init(fd);
    tcgetattr(0, &tio);
    // clean up at exit
    if (atexit(cleanup)) {
        mylogfd(2,"[moto]init:atexit error\n");
        exit(-1);
    }
    task_segList = NULL;
}
Пример #8
0
int Init(void *_ctx) {
	ctx = _ctx;

	switch(ctrl_init()) {
	case -1:
		return -1;
	case 0:
		return 0;
	}

	init_memory();

	ctrl_in = NULL;
	if (!init_ctrl_input(ctx)) {
		return 0;
	}

	nof_output_data_itf = 0;
	param_get_int_name("nof_output_data_itf",&nof_output_data_itf);

	if (init_remote_variables(ctx) == -1) {
		return -1;
	}

	nof_remote_itf = scan_remote_itf(ctx,nof_remote_variables);
	if (nof_remote_itf == -1) {
		return -1;
	}

	nof_local_variables = init_local_variables(ctx);
	if (nof_local_variables == -1) {
		return -1;
	}

	if (init_remote_itf(ctx,nof_remote_itf)) {
		return -1;
	}

	return 1;
}
Пример #9
0
/** *****************************************************************************************************************
  @brief the main event loop.

  This will handle signals, poll buddies, poll clients, publish events, and cleanup sockets.
 ********************************************************************************************************************/
void
event_loop(int32_t listen_sock)
{
    upk_conn_handle_meta_t *clients;
    fd_set                  lfds;
    double                  sel_ival = upk_runtime_configuration.BuddyPollingInterval / 2;
    struct timeval          timeout, timeoutv = { 0, 0 };

#ifdef UPK_CONTROLLER_TERMINATE_FOR_TESTING_AFTER_N
    int                     connections = 0;
#endif

    clients = ctrl_init();

    while(1) {
        handle_signals();
        handle_buddies();

        FD_ZERO(&lfds);
        FD_SET(listen_sock, &lfds);

        timeout = timeoutv;
        if(select(listen_sock + 1, &lfds, NULL, NULL, &timeout) > 0) {
            if(FD_ISSET(listen_sock, &lfds)) {
                upk_debug1("Accepting connection\n");
                ctrl_accept_conn(listen_sock, clients);
#ifdef UPK_CONTROLLER_TERMINATE_FOR_TESTING_AFTER_N
                connections++;
#endif
            }
        }

        upk_net_event_dispatcher(clients, sel_ival);
        upk_net_flush_closed_sockets(clients);
#ifdef UPK_CONTROLLER_TERMINATE_FOR_TESTING_AFTER_N
        if(n++ > 50 || connections > UPK_CONTROLLER_TERMINATE_FOR_TESTING_AFTER_N)
            break;
#endif
    }
}
Пример #10
0
/* Client program */
int
main(int argc, char *argv[])
{
	char server[256];
	char fullhostname[64];
	char domain[256];
	char shell[256];
	char directory[256];
	RD_BOOL prompt_password, deactivated;
	struct passwd *pw;
	uint32 flags, ext_disc_reason = 0;
	char *p;
	int c;
	char *locale = NULL;
	int username_option = 0;
	RD_BOOL geometry_option = False;
#ifdef WITH_RDPSND
	char *rdpsnd_optarg = NULL;
#endif

#ifdef HAVE_LOCALE_H
	/* Set locale according to environment */
	locale = setlocale(LC_ALL, "");
	if (locale)
	{
		locale = xstrdup(locale);
	}

#endif

	/* Ignore SIGPIPE, since we are using popen() */
	struct sigaction act;
	memset(&act, 0, sizeof(act));
	act.sa_handler = SIG_IGN;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGPIPE, &act, NULL);

	/* setup default flags for TS_INFO_PACKET */
	flags = RDP_INFO_MOUSE | RDP_INFO_DISABLECTRLALTDEL
		| RDP_INFO_UNICODE | RDP_INFO_MAXIMIZESHELL | RDP_INFO_ENABLEWINDOWSKEY;

	prompt_password = False;
	g_seamless_spawn_cmd[0] = domain[0] = g_password[0] = shell[0] = directory[0] = 0;
	g_embed_wnd = 0;

	g_num_devices = 0;

#ifdef RDP2VNC
#define VNCOPT "V:Q:"
#else
#define VNCOPT
#endif
	while ((c = getopt(argc, argv,
			   VNCOPT "A:u:L:d:s:c:p:n:k:g:o:fbBeEitmzCDKS:T:UNX:a:x:Pr:045h?")) != -1)
	{
		switch (c)
		{
#ifdef RDP2VNC
			case 'V':
				rfb_port = strtol(optarg, NULL, 10);
				if (rfb_port < 100)
					rfb_port += 5900;
				break;

			case 'Q':
				defer_time = strtol(optarg, NULL, 10);
				if (defer_time < 0)
					defer_time = 0;
				break;
#endif

			case 'A':
				g_seamless_rdp = True;
				STRNCPY(g_seamless_shell, optarg, sizeof(g_seamless_shell));
				break;

			case 'u':
				g_username = (char *) xmalloc(strlen(optarg) + 1);
				STRNCPY(g_username, optarg, strlen(optarg) + 1);
				username_option = 1;
				break;

			case 'L':
#ifdef HAVE_ICONV
				STRNCPY(g_codepage, optarg, sizeof(g_codepage));
#else
				error("iconv support not available\n");
#endif
				break;

			case 'd':
				STRNCPY(domain, optarg, sizeof(domain));
				break;

			case 's':
				STRNCPY(shell, optarg, sizeof(shell));
				g_seamless_persistent_mode = False;
				break;

			case 'c':
				STRNCPY(directory, optarg, sizeof(directory));
				break;

			case 'p':
				if ((optarg[0] == '-') && (optarg[1] == 0))
				{
					prompt_password = True;
					break;
				}

				STRNCPY(g_password, optarg, sizeof(g_password));
				flags |= RDP_INFO_AUTOLOGON;

				/* try to overwrite argument so it won't appear in ps */
				p = optarg;
				while (*p)
					*(p++) = 'X';
				break;
#ifdef WITH_SCARD
			case 'i':
				flags |= RDP_INFO_PASSWORD_IS_SC_PIN;
				g_use_password_as_pin = True;
				break;
#endif
			case 't':
				g_use_ctrl = False;
				break;

			case 'n':
				STRNCPY(g_hostname, optarg, sizeof(g_hostname));
				break;

			case 'k':
				STRNCPY(g_keymapname, optarg, sizeof(g_keymapname));
				break;

			case 'g':
				geometry_option = True;
				g_fullscreen = False;
				if (!strcmp(optarg, "workarea"))
				{
					g_sizeopt = 1;
					break;
				}

				g_width = strtol(optarg, &p, 10);
				if (g_width <= 0)
				{
					error("invalid geometry\n");
					return EX_USAGE;
				}

				if (*p == 'x')
					g_height = strtol(p + 1, &p, 10);

				if (g_height <= 0)
				{
					error("invalid geometry\n");
					return EX_USAGE;
				}

				if (*p == '%')
				{
					g_sizeopt = -g_width;
					g_width = 800;
					p++;
				}

				if (*p == '+' || *p == '-')
				{
					g_pos |= (*p == '-') ? 2 : 1;
					g_xpos = strtol(p, &p, 10);

				}
				if (*p == '+' || *p == '-')
				{
					g_pos |= (*p == '-') ? 4 : 1;
					g_ypos = strtol(p, NULL, 10);
				}

				break;

			case 'f':
				g_fullscreen = True;
				break;

			case 'b':
				g_bitmap_cache = False;
				break;

			case 'B':
				g_ownbackstore = False;
				break;

			case 'e':
				g_encryption_initial = g_encryption = False;
				break;
			case 'E':
				g_packet_encryption = False;
				break;
			case 'm':
				g_sendmotion = False;
				break;

			case 'C':
				g_owncolmap = True;
				break;

			case 'D':
				g_hide_decorations = True;
				break;

			case 'K':
				g_grab_keyboard = False;
				break;

			case 'U':
				g_ungrab_on_ctrlalt = True;
				break;

			case 'S':
				if (!strcmp(optarg, "standard"))
				{
					g_win_button_size = 18;
					break;
				}

				g_win_button_size = strtol(optarg, &p, 10);

				if (*p)
				{
					error("invalid button size\n");
					return EX_USAGE;
				}

				break;

			case 'T':
				STRNCPY(g_title, optarg, sizeof(g_title));
				break;

			case 'N':
				g_numlock_sync = True;
				break;

			case 'X':
				g_embed_wnd = strtol(optarg, NULL, 0);
				break;

			case 'a':
				g_server_depth = strtol(optarg, NULL, 10);
				if (g_server_depth != 8 &&
				    g_server_depth != 16 &&
				    g_server_depth != 15 && g_server_depth != 24
				    && g_server_depth != 32)
				{
					error("Invalid server colour depth.\n");
					return EX_USAGE;
				}
				break;

			case 'z':
				DEBUG(("rdp compression enabled\n"));
				flags |= (RDP_INFO_COMPRESSION | RDP_INFO_COMPRESSION2);
				break;

			case 'x':
				if (str_startswith(optarg, "m"))	/* modem */
				{
					g_rdp5_performanceflags = RDP5_NO_CURSOR_SHADOW |
						RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG |
						RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING;
				}
				else if (str_startswith(optarg, "b"))	/* broadband */
				{
					g_rdp5_performanceflags =
						RDP5_NO_CURSOR_SHADOW | RDP5_NO_WALLPAPER;
				}
				else if (str_startswith(optarg, "l"))	/* lan */
				{
					g_rdp5_performanceflags =
						RDP5_NO_CURSOR_SHADOW | RDP5_DISABLE_NOTHING;
				}
				else
				{
					g_rdp5_performanceflags =
						RDP5_NO_CURSOR_SHADOW | strtol(optarg, NULL, 16);
				}
				break;

			case 'P':
				g_bitmap_cache_persist_enable = True;
				break;

			case 'r':

				if (str_startswith(optarg, "sound"))
				{
					optarg += 5;

					if (*optarg == ':')
					{
						optarg++;
						while ((p = next_arg(optarg, ',')))
						{
							if (str_startswith(optarg, "remote"))
								flags |= RDP_INFO_REMOTE_CONSOLE_AUDIO;

							if (str_startswith(optarg, "local"))
#ifdef WITH_RDPSND
							{
								rdpsnd_optarg =
									next_arg(optarg, ':');
								g_rdpsnd = True;
							}

#else
								warning("Not compiled with sound support\n");
#endif

							if (str_startswith(optarg, "off"))
#ifdef WITH_RDPSND
								g_rdpsnd = False;
#else
								warning("Not compiled with sound support\n");
#endif

							optarg = p;
						}
					}
					else
					{
#ifdef WITH_RDPSND
						g_rdpsnd = True;
#else
						warning("Not compiled with sound support\n");
#endif
					}
				}
				else if (str_startswith(optarg, "disk"))
				{
					/* -r disk:h:=/mnt/floppy */
					disk_enum_devices(&g_num_devices, optarg + 4);
				}
				else if (str_startswith(optarg, "comport"))
				{
					serial_enum_devices(&g_num_devices, optarg + 7);
				}
				else if (str_startswith(optarg, "lspci"))
				{
					g_lspci_enabled = True;
				}
				else if (str_startswith(optarg, "lptport"))
				{
					parallel_enum_devices(&g_num_devices, optarg + 7);
				}
				else if (str_startswith(optarg, "printer"))
				{
					printer_enum_devices(&g_num_devices, optarg + 7);
				}
				else if (str_startswith(optarg, "clientname"))
				{
					g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1);
					strcpy(g_rdpdr_clientname, optarg + 11);
				}
				else if (str_startswith(optarg, "clipboard"))
				{
					optarg += 9;

					if (*optarg == ':')
					{
						optarg++;

						if (str_startswith(optarg, "off"))
							g_rdpclip = False;
						else
							cliprdr_set_mode(optarg);
					}
					else
						g_rdpclip = True;
				}
				else if (strncmp("scard", optarg, 5) == 0)
				{
#ifdef WITH_SCARD
					scard_enum_devices(&g_num_devices, optarg + 5);
#else
					warning("Not compiled with smartcard support\n");
#endif
				}
				else
				{
					warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound, clipboard, scard\n");
				}
				break;

			case '0':
				g_console_session = True;
				break;

			case '4':
				g_rdp_version = RDP_V4;
				break;

			case '5':
				g_rdp_version = RDP_V5;
				break;
#if WITH_SCARD
			case 'o':
				{
					char *p = strchr(optarg, '=');
					if (p == NULL)
					{
						warning("Skipping option '%s' specified, lacks name=value format.\n");
						continue;
					}

					if (strncmp(optarg, "sc-csp-name", strlen("sc-scp-name")) ==
					    0)
						g_sc_csp_name = strdup(p + 1);
					else if (strncmp
						 (optarg, "sc-reader-name",
						  strlen("sc-reader-name")) == 0)
						g_sc_reader_name = strdup(p + 1);
					else if (strncmp
						 (optarg, "sc-card-name",
						  strlen("sc-card-name")) == 0)
						g_sc_card_name = strdup(p + 1);
					else if (strncmp
						 (optarg, "sc-container-name",
						  strlen("sc-container-name")) == 0)
						g_sc_container_name = strdup(p + 1);

				}
				break;
#endif
			case 'h':
			case '?':
			default:
				usage(argv[0]);
				return EX_USAGE;
		}
	}

	if (argc - optind != 1)
	{
		usage(argv[0]);
		return EX_USAGE;
	}

	STRNCPY(server, argv[optind], sizeof(server));
	parse_server_and_port(server);

	if (g_seamless_rdp)
	{
		if (shell[0])
			STRNCPY(g_seamless_spawn_cmd, shell, sizeof(g_seamless_spawn_cmd));

		STRNCPY(shell, g_seamless_shell, sizeof(shell));

		if (g_win_button_size)
		{
			error("You cannot use -S and -A at the same time\n");
			return EX_USAGE;
		}
		g_rdp5_performanceflags &= ~RDP5_NO_FULLWINDOWDRAG;
		if (geometry_option)
		{
			error("You cannot use -g and -A at the same time\n");
			return EX_USAGE;
		}
		if (g_fullscreen)
		{
			error("You cannot use -f and -A at the same time\n");
			return EX_USAGE;
		}
		if (g_hide_decorations)
		{
			error("You cannot use -D and -A at the same time\n");
			return EX_USAGE;
		}
		if (g_embed_wnd)
		{
			error("You cannot use -X and -A at the same time\n");
			return EX_USAGE;
		}
		if (g_rdp_version < RDP_V5)
		{
			error("You cannot use -4 and -A at the same time\n");
			return EX_USAGE;
		}
		g_sizeopt = -100;
		g_grab_keyboard = False;
	}

	if (!username_option)
	{
		pw = getpwuid(getuid());
		if ((pw == NULL) || (pw->pw_name == NULL))
		{
			error("could not determine username, use -u\n");
			return EX_OSERR;
		}
		/* +1 for trailing \0 */
		int pwlen = strlen(pw->pw_name) + 1;
		g_username = (char *) xmalloc(pwlen);
		STRNCPY(g_username, pw->pw_name, pwlen);
	}

#ifdef HAVE_ICONV
	if (g_codepage[0] == 0)
	{
		if (setlocale(LC_CTYPE, ""))
		{
			STRNCPY(g_codepage, nl_langinfo(CODESET), sizeof(g_codepage));
		}
		else
		{
			STRNCPY(g_codepage, DEFAULT_CODEPAGE, sizeof(g_codepage));
		}
	}
#endif

	if (g_hostname[0] == 0)
	{
		if (gethostname(fullhostname, sizeof(fullhostname)) == -1)
		{
			error("could not determine local hostname, use -n\n");
			return EX_OSERR;
		}

		p = strchr(fullhostname, '.');
		if (p != NULL)
			*p = 0;

		STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
	}

	if (g_keymapname[0] == 0)
	{
		if (locale && xkeymap_from_locale(locale))
		{
			fprintf(stderr, "Autoselected keyboard map %s\n", g_keymapname);
		}
		else
		{
			STRNCPY(g_keymapname, "en-us", sizeof(g_keymapname));
		}
	}
	if (locale)
		xfree(locale);


	if (prompt_password && read_password(g_password, sizeof(g_password)))
		flags |= RDP_INFO_AUTOLOGON;

	if (g_title[0] == 0)
	{
		strcpy(g_title, "rdesktop - ");
		strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - "));
	}

#ifdef RDP2VNC
	rdp2vnc_connect(server, flags, domain, g_password, shell, directory);
	return EX_OK;
#else

	/* Only startup ctrl functionality is seamless are used for now. */
	if (g_use_ctrl && g_seamless_rdp)
	{
		if (ctrl_init(server, domain, g_username) < 0)
		{
			error("Failed to initialize ctrl mode.");
			exit(1);
		}

		if (ctrl_is_slave())
		{
			fprintf(stdout,
				"rdesktop in slave mode sending command to master process.\n");

			if (g_seamless_spawn_cmd[0])
				return ctrl_send_command("seamless.spawn", g_seamless_spawn_cmd);

			fprintf(stdout, "No command specified to be spawn in seamless mode.\n");
			return EX_USAGE;
		}
	}

	if (!ui_init())
		return EX_OSERR;

#ifdef WITH_RDPSND
	if (!rdpsnd_init(rdpsnd_optarg))
		warning("Initializing sound-support failed!\n");
#endif

	if (g_lspci_enabled)
		lspci_init();

	rdpdr_init();
	g_reconnect_loop = False;
	while (1)
	{
		rdesktop_reset_state();

		if (g_redirect)
		{
			STRNCPY(domain, g_redirect_domain, sizeof(domain));
			xfree(g_username);
			g_username = (char *) xmalloc(strlen(g_redirect_username) + 1);
			STRNCPY(g_username, g_redirect_username, strlen(g_redirect_username) + 1);
			STRNCPY(server, g_redirect_server, sizeof(server));
			flags |= RDP_INFO_AUTOLOGON;

			fprintf(stderr, "Redirected to %s@%s session %d.\n",
				g_redirect_username, g_redirect_server, g_redirect_session_id);

			/* A redirect on SSL from a 2003 WTS will result in a 'connection reset by peer'
			   and therefor we just clear this error before we connect to redirected server.
			 */
			g_network_error = False;
			g_redirect = False;
		}

		ui_init_connection();
		if (!rdp_connect
		    (server, flags, domain, g_password, shell, directory, g_reconnect_loop))
		{

			g_network_error = False;

			if (g_reconnect_loop == False)
				return EX_PROTOCOL;

			/* check if auto reconnect cookie has timed out */
			if (time(NULL) - g_reconnect_random_ts > RECONNECT_TIMEOUT)
			{
				fprintf(stderr, "Tried to reconnect for %d minutes, giving up.\n",
					RECONNECT_TIMEOUT / 60);
				return EX_PROTOCOL;
			}

			sleep(4);
			continue;
		}

		if (g_redirect)
		{
			rdp_disconnect();
			continue;
		}

		/* By setting encryption to False here, we have an encrypted login 
		   packet but unencrypted transfer of other packets */
		if (!g_packet_encryption)
			g_encryption_initial = g_encryption = False;

		DEBUG(("Connection successful.\n"));

		rd_create_ui();
		tcp_run_ui(True);

		deactivated = False;
		g_reconnect_loop = False;
		rdp_main_loop(&deactivated, &ext_disc_reason);

		tcp_run_ui(False);

		DEBUG(("Disconnecting...\n"));
		rdp_disconnect();

		if (g_redirect)
			continue;

		/* handle network error and start autoreconnect */
		if (g_network_error && !deactivated)
		{
			fprintf(stderr,
				"Disconnected due to network error, retrying to reconnect for %d minutes.\n",
				RECONNECT_TIMEOUT / 60);
			g_network_error = False;
			g_reconnect_loop = True;
			continue;
		}

		ui_seamless_end();
		ui_destroy_window();

		/* Enter a reconnect loop if we have a pending resize request */
		if (g_pending_resize)
		{
			g_pending_resize = False;
			g_reconnect_loop = True;
			continue;
		}
		break;
	}

	cache_save_state();
	ui_deinit();

	if (g_user_quit)
		return EXRD_WINDOW_CLOSED;

	return handle_disconnect_reason(deactivated, ext_disc_reason);

#endif
	if (g_redirect_username)
		xfree(g_redirect_username);

	xfree(g_username);
}
Пример #11
0
int
main(int argc, char **argv)
{
    lisp_dev_type_e dev_type;

    initial_setup();

    handle_lispd_command_line(argc, argv);

    /* see if we need to daemonize, and if so, do it */
    demonize_start();

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    lmtimers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    if ((lctrl = ctrl_create())==NULL){
        exit_cleanup();
    }

    /* Detect the data plane type */
    data_plane_select();

    /* parse config and create ctrl_dev */
    if (parse_config_file() != GOOD){
        exit_cleanup();
    }


    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        data_plane->datap_init(dev_type);
    }

    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
    if (!ctrl_dev) {
        LMLOG(LDBG_1, "device NULL");
        exit(0);
    }
    ctrl_dev_run(ctrl_dev);

    LMLOG(LINF,"\n\n LISPmob (%s): 'lispd' started... \n\n",LISPD_VERSION);

#ifndef ANDROID
    /* Initialize API for external access */
    lmapi_init_server(&lmapi_connection);

    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
        lmapi_loop(&lmapi_connection);
    }
#else
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
    }
#endif



    /* EVENT LOOP */
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
#ifndef ANDROID
        lmapi_loop(&lmapi_connection);
#endif
    }

    /* event_loop returned: bad! */
    LMLOG(LINF, "Exiting...");
    exit_cleanup();
    return(0);
}
Пример #12
0
JNIEXPORT jint JNICALL Java_org_lispmob_noroot_LISPmob_1JNI_startLispd
  (JNIEnv *env, jobject thisObj, jint vpn_tun_fd, jstring storage_path)
{
    lisp_dev_type_e dev_type;
    jintArray fd_list;
    uint32_t iseed = 0;  /* initial random number generator */
    pid_t pid = 0;    /* child pid */
    pid_t sid = 0;
    char log_file[1024];
    const char *path = NULL;

    memset (log_file,0,sizeof(char)*1024);


    initial_setup();
    jni_init(env,thisObj);

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    lmtimers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    lctrl = ctrl_create();

    /* Detect the data plane type */
    data_plane_select();

    /** parse config and create ctrl_dev **/

    /* obtain the configuration file */
    path = (*env)->GetStringUTFChars(env, storage_path, 0);
    config_file = calloc(1024, sizeof(char));
    strcat(config_file,path);
    strcat(config_file,"lispd.conf");
    strcat(log_file,path);
    strcat(log_file,"lispd.log");
    (*env)->ReleaseStringUTFChars(env, storage_path, path);
    open_log_file(log_file);

    if (parse_config_file()!=GOOD){
        exit_cleanup();
        return (BAD);
    }

    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        data_plane->datap_init(dev_type, vpn_tun_fd);
    }

    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
     if (!ctrl_dev) {
         LMLOG(LDBG_1, "device NULL");
         return (BAD);
     }

     return (GOOD);
}
Пример #13
0
int main(int argc, char *argv[])
{
	int c;
	const char *read_file = NULL;
	const char *read_wired_file = NULL;
	const char *write_file = NULL;
	const char *ifname = NULL;
	const char *ifname_wired = NULL;
	struct wlantest wt;
	int ctrl_iface = 0;

	wpa_debug_level = MSG_INFO;
	wpa_debug_show_keys = 1;

	if (os_program_init())
		return -1;

	wlantest_init(&wt);

	for (;;) {
		c = getopt(argc, argv, "cdf:hi:I:p:P:qr:R:w:W:");
		if (c < 0)
			break;
		switch (c) {
		case 'c':
			ctrl_iface = 1;
			break;
		case 'd':
			if (wpa_debug_level > 0)
				wpa_debug_level--;
			break;
		case 'f':
			if (add_pmk_file(&wt, optarg) < 0)
				return -1;
			break;
		case 'h':
			usage();
			return 0;
		case 'i':
			ifname = optarg;
			break;
		case 'I':
			ifname_wired = optarg;
			break;
		case 'p':
			add_passphrase(&wt, optarg);
			break;
		case 'P':
			add_secret(&wt, optarg);
			break;
		case 'q':
			wpa_debug_level++;
			break;
		case 'r':
			read_file = optarg;
			break;
		case 'R':
			read_wired_file = optarg;
			break;
		case 'w':
			write_file = optarg;
			break;
		case 'W':
			if (add_wep(&wt, optarg) < 0)
				return -1;
			break;
		default:
			usage();
			return -1;
		}
	}

	if (ifname == NULL && ifname_wired == NULL &&
	    read_file == NULL && read_wired_file == NULL) {
		usage();
		return 0;
	}

	if (eloop_init())
		return -1;

	if (write_file && write_pcap_init(&wt, write_file) < 0)
		return -1;

	if (read_wired_file && read_wired_cap_file(&wt, read_wired_file) < 0)
		return -1;

	if (read_file && read_cap_file(&wt, read_file) < 0)
		return -1;

	if (ifname && monitor_init(&wt, ifname) < 0)
		return -1;

	if (ifname_wired && monitor_init_wired(&wt, ifname_wired) < 0)
		return -1;

	if (ctrl_iface && ctrl_init(&wt) < 0)
		return -1;

	eloop_register_signal_terminate(wlantest_terminate, &wt);

	eloop_run();

	wpa_printf(MSG_INFO, "Processed: rx_mgmt=%u rx_ctrl=%u rx_data=%u "
		   "fcs_error=%u",
		   wt.rx_mgmt, wt.rx_ctrl, wt.rx_data, wt.fcs_error);

	wlantest_deinit(&wt);

	eloop_destroy();
	os_program_deinit();

	return 0;
}
Пример #14
0
int main(void)
{
	
	// INITIALISATIONS
	float x = 0.0;
	float y = 0.0;
	float theta = 0.0;
	float vel = 0.0;
	float velref = 0.0;
	float Mvel = 0.0;
	char* word_array[MAX_CMDS];
	int no_of_words = 0;
	int error = 1;


	DDRC |= 1 << 5; 	// PortC.5 as output 


	lb_init(&lb);		// init line buffer lb 
	uart_init(); 		// init USART
	enc_init();			// init Encoder
	ctrl_init();		// init Controller
	motor_init();		// init Motor
	sei();  			// enable interrupts

	printf_P(PSTR("Sup Bitches\nThis is Command\n"));


	for (;/*ever*/;)
	{
		while (uart_avail())
		{
			char c = uart_getc();		//gets character from circular buffer

			if (lb_append(&lb, c) == LB_BUFFER_FULL)		// Add character "c" to line buffer, report status(putc) and handle special characters(append)
			{
				lb_init(&lb); // Clear line  buffer, discards input
				printf_P(PSTR("\nMax line length exceeded\n"));
			}
		}
		error = 1;

		// Process command if line buffer is terminated by a line feed or carriage return
		if (lb_line_ready(&lb))		//if not empty and has null terminator
		{ 
			for (int j = 0; j < NUM_CMDS; j++)	//re-setting word_array to zero
			{
				word_array[j] = 0;
			}
			
			no_of_words = string_parser( lb_gets(&lb), word_array);		// gets serial, puts into word_array 

			for (int i=0; cmd_table[i].cmd != NULL; ++i)							// 
			{
				if( !strcmp(word_array[0], cmd_table[i].cmd))
		     	{
					error = 0;
                    cmd_table[i].func(no_of_words, word_array);
		       	}	
			}
			lb_init(&lb);

			// Error checking
			if(!no_of_words)
			{
				printf_P(PSTR("No Command Entered\n"));
			}
			if(error)
			{
				printf_P(PSTR("Invalid Command\n"));
			}



		/*	// Note: The following is a terrible way to process strings from the user
			//       See recommendations section of the lab guide for a better way to
			//       handle commands with arguments, which scales well to a large
			//       number of commands.
			if (!strncmp_P(lb_gets(&lb), PSTR("help"), 4))
			{
				printf_P(PSTR(
					"MCHA3000 RS232 lab help.\n"
					"Replace these lines with your own help instructions.\n"));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("x="), 2))			// takes 'x' co-ordinate
			{
				x = atof(lb_gets_at(&lb, 2));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("x?"), 2))			// prints 'x' co-ordinate to serial
			{
				printf_P(PSTR("x is %f\n"), x);
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("y="), 2))			// takes 'y' co-ordinate
			{
				y = atof(lb_gets_at(&lb, 2));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("xy?"), 3))			// prints 'x'*'y' to serial
			{
				printf_P(PSTR("%f\n"), x*y);
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("theta="), 6))		// HIL: takes 'theta'
			{
				theta = atof(lb_gets_at(&lb, 6));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("vel="), 4))			// HIL: takes 'vel'
			{
				vel = atof(lb_gets_at(&lb, 4));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("velref="), 7))		// HIL: takes 'velref'
			{
				velref = atof(lb_gets_at(&lb, 7));
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("ctrl?"), 5))		// HIL: initialises feedback loop for cascade controller 
			{															// and prints control action to serial
				float outer_loop = velocity_controller(velref - vel);
				float inner_loop = angle_controller(outer_loop - theta);
				printf_P(PSTR("%g\n"), inner_loop);
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("ecount?"), 7))		// prints enc_count
			{
				printf_P(PSTR("Encoder1 Count =  %d\n"), enc_read1());
				printf_P(PSTR("Encoder2 Count =  %d\n"), enc_read2());
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("ereset"), 6))		// Resets enc_count then prints count
			{
				enc_reset();
				printf_P(PSTR("Encoder1 Count =  %d\n"), enc_read1());
				printf_P(PSTR("Encoder2 Count =  %d\n"), enc_read2());
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("mvel="), 5))		// Motor On/Off
			{
				Mvel=atof(lb_gets_at(&lb, 5));
				motor_vel(Mvel);
				printf_P(PSTR("Motor Velocity = %f\n"), Mvel);
			}
			else if (!strncmp_P(lb_gets(&lb), PSTR("I"), 1))			// Motor Current
			{
				printf_P(PSTR("Motor Current =  %f\n"), motor_current());
			}
			else														// WARNING: Unknown command
			{
				printf_P(PSTR("Unknown command: \"%s\"\n"), lb_gets(&lb));
			}

			lb_init(&lb);	// Reset line buffer 
			*/
		}
	}
	return 0;
}
Пример #15
0
Файл: oor.c Проект: biels/oor
int
main(int argc, char **argv)
{
    oor_dev_type_e dev_type;
    lisp_xtr_t *tunnel_router;

    initial_setup();

    handle_oor_command_line(argc, argv);

    /* see if we need to daemonize, and if so, do it */
    demonize_start();

    /* create socket master, timer wheel, initialize interfaces */
    smaster = sockmstr_create();
    oor_timers_init();
    ifaces_init();

    /* create control. Only one instance for now */
    if ((lctrl = ctrl_create())==NULL){
        exit_cleanup();
    }

    /* Detect the data plane type */
    data_plane_select();

    /* parse config and create ctrl_dev */
    if (parse_config_file() != GOOD){
        exit_cleanup();
    }


    dev_type = ctrl_dev_mode(ctrl_dev);
    if (dev_type == xTR_MODE || dev_type == RTR_MODE || dev_type == MN_MODE) {
        OOR_LOG(LDBG_2, "Configuring data plane");
        tunnel_router = CONTAINER_OF(ctrl_dev, lisp_xtr_t, super);
        if (data_plane->datap_init(dev_type,tr_get_encap_type(tunnel_router))!=GOOD){
            exit_cleanup();
        }
        OOR_LOG(LDBG_1, "Data plane initialized");
    }

    /* The control should be initialized after data plane */
    ctrl_init(lctrl);
    init_netlink();

    /* run lisp control device xtr/ms */
    if (!ctrl_dev) {
        OOR_LOG(LDBG_1, "device NULL");
        exit(0);
    }

    ctrl_dev_run(ctrl_dev);

    OOR_LOG(LINF,"\n\n Open Overlay Router (%s): started... \n\n",OOR_VERSION);

#ifndef ANDROID
    /* Initialize API for external access */
    oor_api_init_server(&oor_api_connection);

    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
        oor_api_loop(&oor_api_connection);
    }
#else
    for (;;) {
        sockmstr_wait_on_all_read(smaster);
        sockmstr_process_all(smaster);
    }
#endif

    /* event_loop returned: bad! */
    OOR_LOG(LINF, "Exiting...");
    exit_cleanup();
    return(0);
}
Пример #16
0
int main(int argc, char *argv[])
{
	int opt;
	uint8_t quiet = 0;
	config_t cfg;
	switch_cfg = calloc(1, sizeof(struct switch_cfg));

	signal(SIGINT, int_handler);

	while ((opt = getopt(argc, argv, "qvh")) != -1) {
		switch (opt) {
		case 'q':
			quiet = 1;
			break;
		case 'v':
			fprintf(stdout, "netvirt-switch %s\n", NVSWITCH_VERSION);
			return 0;
		default:
		case 'h':
			fprintf(stdout, "netvirt-switch:\n"
					"-q\t\tquiet mode\n"
					"-v\t\tshow version\n"
					"-h\t\tshow this help\n");
			return 0;
		}
	}

	if (!quiet) {
		jlog_init_cb(on_log);
	}

	config_init(&cfg);
	switch_cfg->ctrl_initialized = 0;

	if (config_parse(&cfg, switch_cfg)) {
		jlog(L_ERROR, "config parse failed");
		exit(EXIT_FAILURE);
	}


	if (krypt_init()) {
		jlog(L_ERROR, "krypt_init failed");
		exit(EXIT_FAILURE);
	}

	netbus_tcp_init();
	if (netbus_init()) {
		jlog(L_ERROR, "netbus_init failed");
		exit(EXIT_FAILURE);
	}

	if (ctrl_init(switch_cfg)) {
		jlog(L_ERROR, "ctrl_init failed");
		exit(EXIT_FAILURE);
	}

	/* make sure control is properly initialized before
		accepting connection */
	while (switch_cfg->ctrl_initialized == 0) {
		sleep(1);
	}

	if (switch_init(switch_cfg)) {
		jlog(L_ERROR, "switch_init failed");
		exit(EXIT_FAILURE);
	}

	while (switch_cfg->ctrl_running || switch_cfg->switch_running) {
		sleep(1);
	}

	/* clean up */
	ctrl_fini();
	switch_fini();
	netbus_fini();
	krypt_fini();
	config_destroy(&cfg);
	free(switch_cfg);

	printf("Goodbye netvirt-switch !\n");

	return 0;
}
Пример #17
0
void _main(int argc, char *argv[])
{
   (void)argc;
   (void)argv;
   syslog(LOG_INFO, "initializing core");
   
   /* init SCL subsystem: */
   syslog(LOG_INFO, "initializing signaling and communication link (SCL)");
   if (scl_init("core") != 0)
   {
      syslog(LOG_CRIT, "could not init scl module");
      exit(EXIT_FAILURE);
   }
   
   /* init params subsystem: */
   syslog(LOG_INFO, "initializing opcd interface");
   opcd_params_init("core.", 1);
   
   /* initialize logger: */
   syslog(LOG_INFO, "opening logger");
   if (logger_open() != 0)
   {
      syslog(LOG_CRIT, "could not open logger");
      exit(EXIT_FAILURE);
   }
   syslog(LOG_CRIT, "logger opened");
   sleep(1); /* give scl some time to establish
                a link between publisher and subscriber */

   LOG(LL_INFO, "+------------------+");
   LOG(LL_INFO, "|   core startup   |");
   LOG(LL_INFO, "+------------------+");

   LOG(LL_INFO, "initializing system");

   /* set-up real-time scheduling: */
   struct sched_param sp;
   sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
   sched_setscheduler(getpid(), SCHED_FIFO, &sp);
   if (mlockall(MCL_CURRENT | MCL_FUTURE))
   {
      LOG(LL_ERROR, "mlockall() failed");
      exit(EXIT_FAILURE);
   }

   /* initialize hardware/drivers: */
   omap_i2c_bus_init();
   baro_altimeter_init();
   ultra_altimeter_init();
   ahrs_init();
   motors_init();
   voltage_reader_start();
   //gps_init();
   
   LOG(LL_INFO, "initializing model/controller");
   model_init();
   ctrl_init();
   
   /* initialize command interface */
   LOG(LL_INFO, "initializing cmd interface");
   cmd_init();
   
   /* prepare main loop: */
   for (int i = 0; i < NUM_AVG; i++)
   {
      output_avg[i] = sliding_avg_create(OUTPUT_RATIO, 0.0f);
   }

   LOG(LL_INFO, "system up and running");
   struct timespec ts_curr;
   struct timespec ts_prev;
   struct timespec ts_diff;
   clock_gettime(CLOCK_REALTIME, &ts_curr);
 
   /* run model and controller: */
   while (1)
   {
      /* calculate dt: */
      ts_prev = ts_curr;
      clock_gettime(CLOCK_REALTIME, &ts_curr);
      TIMESPEC_SUB(ts_diff, ts_curr, ts_prev);
      float dt = (float)ts_diff.tv_sec + (float)ts_diff.tv_nsec / (float)NSEC_PER_SEC;

      /* read sensor values into model input structure: */
      model_input_t model_input;
      model_input.dt = dt;
      ahrs_read(&model_input.ahrs_data);
      gps_read(&model_input.gps_data);
      model_input.ultra_z = ultra_altimeter_read();
      model_input.baro_z = baro_altimeter_read();

      /* execute model step: */
      model_state_t model_state;
      model_step(&model_state, &model_input);

      /* execute controller step: */
      mixer_in_t mixer_in;
      ctrl_step(&mixer_in, dt, &model_state);
 
      /* set up mixer input: */
      mixer_in.pitch = sliding_avg_calc(output_avg[AVG_PITCH], mixer_in.pitch);
      mixer_in.roll = sliding_avg_calc(output_avg[AVG_ROLL], mixer_in.roll);
      mixer_in.yaw = sliding_avg_calc(output_avg[AVG_YAW], mixer_in.yaw);
      mixer_in.gas = sliding_avg_calc(output_avg[AVG_GAS], mixer_in.gas);

      /* write data to motor mixer: */
      EVERY_N_TIMES(OUTPUT_RATIO, motors_write(&mixer_in));
   }
}