Exemplo n.º 1
0
static int hostapd_cli_cmd_interface(struct hostapd_ctrl *ctrl, int argc,
				     char *argv[])
{
	if (argc < 1) {
		hostapd_cli_list_interfaces(ctrl);
		return 0;
	}

	hostapd_cli_close_connection();
	free(ctrl_ifname);
	ctrl_ifname = strdup(argv[0]);

	if (hostapd_cli_open_connection(ctrl_ifname)) {
		printf("Connected to interface '%s.\n", ctrl_ifname);
		if (hostapd_ctrl_attach(ctrl_conn) == 0) {
			hostapd_cli_attached = 1;
		} else {
			printf("Warning: Failed to attach to "
			       "hostapd.\n");
		}
	} else {
		printf("Could not connect to interface '%s' - re-trying\n",
			ctrl_ifname);
	}
	return 0;
}
Exemplo n.º 2
0
static int hostapd_cli_reconnect(const char *ifname)
{
	char *next_ctrl_ifname;

	hostapd_cli_close_connection();

	if (!ifname)
		return -1;

	next_ctrl_ifname = os_strdup(ifname);
	os_free(ctrl_ifname);
	ctrl_ifname = next_ctrl_ifname;
	if (!ctrl_ifname)
		return -1;

	ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
	if (!ctrl_conn)
		return -1;
	if (!interactive && !action_file)
		return 0;
	if (wpa_ctrl_attach(ctrl_conn) == 0) {
		hostapd_cli_attached = 1;
		register_event_handler(ctrl_conn);
		update_stations(ctrl_conn);
	} else {
		printf("Warning: Failed to attach to hostapd.\n");
	}
	return 0;
}
Exemplo n.º 3
0
static void hostapd_cli_cleanup(void)
{
	hostapd_cli_close_connection();
	if (pid_file)
		os_daemonize_terminate(pid_file);

	os_program_deinit();
}
Exemplo n.º 4
0
static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx)
{
	if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
		printf("Connection to hostapd lost - trying to reconnect\n");
		hostapd_cli_close_connection();
	}
	if (!ctrl_conn && hostapd_cli_reconnect(ctrl_ifname) == 0)
		printf("Connection to hostapd re-established\n");
	if (ctrl_conn)
		hostapd_cli_recv_pending(ctrl_conn, 1, 0);
	eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
}
Exemplo n.º 5
0
static void hostapd_cli_alarm(int sig)
{
	if (ctrl_conn && _hostapd_ctrl_command(ctrl_conn, "PING", 0)) {
		printf("Connection to hostapd lost - trying to reconnect\n");
		hostapd_cli_close_connection();
	}
	if (!ctrl_conn) {
		ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			printf("Connection to hostapd re-established\n");
			if (hostapd_ctrl_attach(ctrl_conn) == 0) {
				hostapd_cli_attached = 1;
			} else {
				printf("Warning: Failed to attach to "
				       "hostapd.\n");
			}
		}
	}
	if (ctrl_conn)
		hostapd_cli_recv_pending(ctrl_conn, 1);
	alarm(1);
}
Exemplo n.º 6
0
static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx)
{
	if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
		printf("Connection to hostapd lost - trying to reconnect\n");
		hostapd_cli_close_connection();
	}
	if (!ctrl_conn) {
		ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			printf("Connection to hostapd re-established\n");
			if (wpa_ctrl_attach(ctrl_conn) == 0) {
				hostapd_cli_attached = 1;
			} else {
				printf("Warning: Failed to attach to "
				       "hostapd.\n");
			}
		}
	}
	if (ctrl_conn)
		hostapd_cli_recv_pending(ctrl_conn, 1, 0);
	eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	int interactive;
	int warning_displayed = 0;
	int c;

	for (;;) {
		c = getopt(argc, argv, "hi:p:v");
		if (c < 0)
			break;
		switch (c) {
		case 'h':
			usage();
			return 0;
		case 'v':
			printf("%s\n", hostapd_cli_version);
			return 0;
		case 'i':
			ctrl_ifname = strdup(optarg);
			break;
		case 'p':
			ctrl_iface_dir = optarg;
			break;
		default:
			usage();
			return -1;
		}
	}

	interactive = argc == optind;

	if (interactive) {
		printf("%s\n\n%s\n\n", hostapd_cli_version,
		       hostapd_cli_license);
	}

	for (;;) {
		if (ctrl_ifname == NULL) {
			struct dirent *dent;
			DIR *dir = opendir(ctrl_iface_dir);
			if (dir) {
				while ((dent = readdir(dir))) {
					if (strcmp(dent->d_name, ".") == 0 ||
					    strcmp(dent->d_name, "..") == 0)
						continue;
					printf("Selected interface '%s'\n",
					       dent->d_name);
					ctrl_ifname = strdup(dent->d_name);
					break;
				}
				closedir(dir);
			}
		}
		ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			if (warning_displayed)
				printf("Connection established.\n");
			break;
		}

		if (!interactive) {
			perror("Failed to connect to hostapd - "
			       "hostapd_ctrl_open");
			return -1;
		}

		if (!warning_displayed) {
			printf("Could not connect to hostapd - re-trying\n");
			warning_displayed = 1;
		}
		sleep(1);
		continue;
	}

	signal(SIGINT, hostapd_cli_terminate);
	signal(SIGTERM, hostapd_cli_terminate);
	signal(SIGALRM, hostapd_cli_alarm);

	if (interactive) {
		if (hostapd_ctrl_attach(ctrl_conn) == 0) {
			hostapd_cli_attached = 1;
		} else {
			printf("Warning: Failed to attach to hostapd.\n");
		}
		hostapd_cli_interactive();
	} else
		wpa_request(ctrl_conn, argc - optind, &argv[optind]);

	free(ctrl_ifname);
	hostapd_cli_close_connection();
	return 0;
}
Exemplo n.º 8
0
static void hostapd_cli_terminate(int sig)
{
	hostapd_cli_close_connection();
	exit(0);
}
int HostapdCLI_RunCommand(const char *ctrl_interface, THostapdCLICmd *pCmd)
{
    int     argc = 1, i=0 ;
    char*   argv[MAX_PARAMS_IN_CMD];

    ctrl_ifname = strdup(ctrl_interface);

    printf(" ctrl_ifname = %s. cmd = %d \n", ctrl_ifname, pCmd->eCmdType);
    ctrl_conn = hostapd_cli_open_connection(ctrl_ifname);

    if (ctrl_conn)
    {
         printf("\n Connection with Hostapd established.\n");
    }
    else
    {
        perror("\n Error! Failed to connect to hostapd \n");
        return -1;
    }

    argv[0] = malloc(MAX_CMD_NAME_SIZE);
    memcpy(argv[0], tCmdsNames[pCmd->eCmdType].cmdName , MAX_CMD_NAME_SIZE);

	signal(SIGINT, hostapd_cli_terminate);
	signal(SIGTERM, hostapd_cli_terminate);
	signal(SIGALRM, hostapd_cli_alarm);

    switch (pCmd->eCmdType)
    {
#ifndef CONFIG_NO_TI
    case HOSTAPD_CLI_CMD_RELOAD_ACL:
#endif
    case HOSTAPD_CLI_CMD_PING:
    case HOSTAPD_CLI_CMD_MIB:
    case HOSTAPD_CLI_CMD_ALL_STA:
	case HOSTAPD_CLI_CMD_WPS_PBC:
	case HOSTAPD_CLI_CMD_RESET:
	case HOSTAPD_CLI_CMD_STOP:
        break;
	case HOSTAPD_CLI_CMD_START:
		argv[1] = malloc(MAX_FILENAME_SIZE);
		memcpy(argv[1], pCmd->u.tCmdStart.config_fname , MAX_FILENAME_SIZE);
		argc = 2;
        break;
    case HOSTAPD_CLI_CMD_STA:
    case HOSTAPD_CLI_CMD_NEW_STA:
	case HOSTAPD_CLI_CMD_SA_QUERY:

       argv[1] = malloc(MAX_ADDRESS_SIZE);
       memcpy(argv[1], pCmd->u.tCmdSta.address , MAX_ADDRESS_SIZE);
       argc = 2;
       break;
    case HOSTAPD_CLI_CMD_WPS_PIN:
        {
        char *temp ;
        argv[1] = malloc(pCmd->u.tCmdWPSPin.uuidLen +1);
        memcpy(argv[1], pCmd->u.tCmdWPSPin.uuid,pCmd->u.tCmdWPSPin.uuidLen);
        temp =  argv[1] + pCmd->u.tCmdWPSPin.uuidLen;
        *temp = '\0';
        argv[2] = malloc(pCmd->u.tCmdWPSPin.pinLen+1);
        memcpy(argv[2], pCmd->u.tCmdWPSPin.pin,pCmd->u.tCmdWPSPin.pinLen);
        temp = argv[2] + pCmd->u.tCmdWPSPin.pinLen;
        *temp = '\0';
        argc = 3;
        }
        break;
    default:
        printf("Error!, Command number %d is not legal!!!", pCmd->eCmdType);
    }

    printf("\n Sending Command: name=%s, argc=%d \n" ,argv[0], argc);
	wpa_request(ctrl_conn, argc, &argv[0]);

	free(ctrl_ifname);

    for (i = 0 ; i < argc ; i++)
    {
        free(argv[i]);
    }
	hostapd_cli_close_connection();

	return 0;
}