/* to validate hostname/ip given by the client */
int validate_server_address()
{
    struct hostent *he;
    struct ipv4_addr temp;
    if (!wl_atoip(g_rwl_servIP, &temp)) {
        /* Wrong IP address format check for hostname */
        if ((he = gethostbyname(g_rwl_servIP)) != NULL) {
            if (!wl_atoip(*he->h_addr_list, &temp)) {
                g_rwl_servIP =
                    inet_ntoa(*(struct in_addr *)*he->h_addr_list);
                if (g_rwl_servIP == NULL) {
                    DPRINT_ERR(ERR, "Error at inet_ntoa \n");
                    return FAIL;
                }
            } else {
                DPRINT_ERR(ERR, "Error in IP address \n");
                return FAIL;
            }
        } else {
            DPRINT_ERR(ERR, "Enter correct IP address/hostname format\n");
            return FAIL;
        }
    }
    return SUCCESS;
}
Пример #2
0
/* This function initializes the socket library binds and listens on the port
 *
 */
int
rwl_init_server_socket_setup(int argc, char** argv, uint remote_type)
{
	int err, SockDes, val;
	struct sockaddr_in ServerAddress;
	char ip_addres[MAX_IP_ADDR_LENGTH];
	unsigned short servPort;
	struct ipv4_addr temp;


	/* Default option */
	servPort = DEFAULT_SERVER_PORT;
	if (rwl_get_local_nic_ip() == NULL) {
		DPRINT_ERR(ERR, "\nunable to get the local ip\n");
		return FAIL;
	}
	strcpy(ip_addres, rwl_get_local_nic_ip());

	/* User option can override default arguments */
	if (argc == 3) {
		*argv++;

		if (!wl_atoip(*argv, &temp)) {
			DPRINT_ERR(ERR, "\n USAGE ERROR:Incorrect IPaddress\n");
			return FAIL;
		}

		strcpy(ip_addres, *argv);
		*argv++;

		if (isdigit(**argv) == FALSE) {
			DPRINT_ERR(ERR, "USAGE ERROR:Incorrect port\n");
			return FAIL;
		}
		servPort = atoi(*argv);
	}


	if (argc == 2) {

		*argv++;
		if (!wl_atoip(*argv, &temp)) {
			if (isdigit(**argv) == FALSE) {
				DPRINT_ERR(ERR, "USAGE ERROR\n");
				return FAIL;
			}
			else
				servPort = atoi(*argv);
		}
		else
			strcpy(ip_addres, *argv);
	}

	DPRINT_INFO(OUTPUT, "INFO: IP: %s, Port:%d\n",
		ip_addres, servPort);


	rwl_init_ws2_32dll();

	if ((SockDes = (*(int *)rwl_open_transport(remote_type, NULL, 0, 0))) == FAIL)
	   return FAIL;

	val = 1;
	if ((rwl_set_socket_option(SockDes, SOL_SOCKET, SO_REUSEADDR, val)) == -1)
		return FAIL;

	memset(&ServerAddress, 0, sizeof(ServerAddress));
	ServerAddress.sin_family = AF_INET; /* host byte order */
	ServerAddress.sin_port = htons(servPort); /* short, network byte order */
	ServerAddress.sin_addr.s_addr = inet_addr(ip_addres);

	if (((err = rwl_bindsocket(SockDes, (struct sockaddr *)&ServerAddress,
	                                    sizeof(ServerAddress))) != 1))
		return err;
	if ((err = rwl_listensocket(SockDes, BACKLOG)) != 1)
		return err;

	DPRINT_DBG(OUTPUT, "Waiting for client to connect...\n");

	return SockDes;
}
Пример #3
0
int wlmSelectInterface(WLM_DUT_INTERFACE ifType, char *ifName,
	WLM_DUT_SERVER_PORT dutServerPort, WLM_DUT_OS dutOs)
{
	/* close previous handle */
	if (irh != NULL) {
		wlmApiCleanup();
	}

	switch (ifType) {
		case WLM_DUT_LOCAL:
			rwl_set_remote_type(NO_REMOTE);
			break;
		case WLM_DUT_SERIAL:
			rwl_set_remote_type(REMOTE_SERIAL);
			break;
		case WLM_DUT_SOCKET:
			rwl_set_remote_type(REMOTE_SOCKET);
			break;
		case WLM_DUT_WIFI:
			rwl_set_remote_type(REMOTE_WIFI);
			break;
		case WLM_DUT_DONGLE:
			rwl_set_remote_type(REMOTE_DONGLE);
			break;
		default:
			/* ERROR! Unknown interface! */
			return FALSE;
	}

	if (ifName) {
		strncpy(interfaceName, ifName, MAX_INTERFACE_NAME_LENGTH);
		interfaceName[MAX_INTERFACE_NAME_LENGTH] = 0;
	}

	switch (dutOs) {
		case WLM_DUT_OS_LINUX:
			wl_os_type_set_rwl(LINUX_OS);
			break;
		case WLM_DUT_OS_WIN32:
			wl_os_type_set_rwl(WIN32_OS);
			break;
		default:
			/* ERROR! Unknown OS! */
			return FALSE;
	}

	switch (rwl_get_remote_type()) {
		struct ipv4_addr temp;
		case REMOTE_SOCKET:
			if (!wl_atoip(interfaceName, &temp)) {
				printf("wlmSelectInterface: IP address invalid\n");
				return FALSE;
			}
			rwl_set_server_ip(interfaceName);
			rwl_set_server_port(dutServerPort);
			rwl_init_socket();
			break;
		case REMOTE_SERIAL:
			rwl_set_serial_port_name(interfaceName); /* x (port number) or /dev/ttySx */
			if ((irh = rwl_open_pipe(rwl_get_remote_type(),
				rwl_get_serial_port_name(), 0, 0)) == NULL) {
				printf("wlmSelectInterface: rwl_open_pipe failed\n");
				return FALSE;
			}
			break;
		case REMOTE_DONGLE:
			rwl_set_serial_port_name(interfaceName); /* COMx or /dev/ttySx */
			if ((irh = rwl_open_pipe(rwl_get_remote_type(), "\0", 0, 0)) == NULL) {
				printf("wlmSelectInterface: rwl_open_pipe failed\n");
				return FALSE;
			}
			break;
		case REMOTE_WIFI:
			if (!wl_ether_atoe(interfaceName,
				(struct ether_addr *)rwl_get_wifi_mac())) {
				printf("wlmSelectInterface: ethernet MAC address invalid\n");
				return FALSE;
			}
			/* intentionally no break here to pass through to NO_REMOTE case */
		case NO_REMOTE:
			if (wl_ir_init_rwl(&irh) != 0) {
				printf("wlmSelectInterface: initialize failed\n");
				return FALSE;
			}
			break;
		default:
			/* ERROR! Invalid interface!
			 * NOTE: API should not allow code to come here.
			 */
			return FALSE;
	}

	return TRUE;
}
Пример #4
0
int
wl_lib(char *input_str)
{
	struct ifreq ifr;
	char *ifname = NULL;
	int err = 0;
	int help = 0;
	int status = CMD_WL;
	void* serialHandle = NULL;
	struct ipv4_addr temp;
	char *tmp_argv[LINUX_NUM_ARGS];
	char **argv = tmp_argv;
	int argc;

	if ((argc = buf_to_args(input_str, argv)) <= 0) {
		printf("wl: can't convert input string\n");
		return (-1);
	}
#else
/* Main client function */
int
main(int argc, char **argv)
{
	struct ifreq ifr;
	char *ifname = NULL;
	int err = 0;
	int help = 0;
	int status = CMD_WL;
	struct ipv4_addr temp;
#if defined (RWL_DONGLE) || (RWL_SERIAL)
	void* serialHandle = NULL;
#endif

#endif /* WLMSO */
	wlu_av0 = argv[0];

	wlu_init();
	memset(&ifr, 0, sizeof(ifr));
	argv++;

	if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
		if (ifname)
			strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
	}

	/* Linux client looking for a WinCE server */
	if (*argv && strncmp (*argv, "--wince", strlen(*argv)) == 0) {
		rwl_os_type = WIN32_OS;
		argv++;
	}

	/* Linux client looking for a indongle reflector */
	if (*argv && strncmp (*argv, "--indongle", strlen(*argv)) == 0) {
		argv++;
	}
	/* Linux client looking for a WinVista server */
	if (*argv && strncmp (*argv, "--vista", strlen(*argv)) == 0) {
		rwl_os_type = WINVISTA_OS;
		argv++;
	}

	/* RWL socket transport Usage: --socket ipaddr [port num] */
	if (*argv && strncmp (*argv, "--socket", strlen(*argv)) == 0) {
		argv++;

		remote_type = REMOTE_SOCKET;

		if (!(*argv)) {
			rwl_usage(remote_type);
			return err;
		}

		if (!wl_atoip(*argv, &temp)) {
			rwl_usage(remote_type);
			return err;
		}
		g_rwl_servIP = *argv;
		argv++;

		g_rwl_servport = DEFAULT_SERVER_PORT;
		if ((*argv) && isdigit(**argv)) {
			g_rwl_servport = atoi(*argv);
			argv++;
		}
	}

	/* RWL from system serial port on client to uart serial port on server */
	/* Usage: --serial /dev/ttyS0 */
	if (*argv && strncmp (*argv, "--serial", strlen(*argv)) == 0) {
		argv++;
		remote_type = REMOTE_SERIAL;
	}

	/* RWL from system serial port on client to uart dongle port on server */
	/* Usage: --dongle /dev/ttyS0 */
	if (*argv && strncmp (*argv, "--dongle", strlen(*argv)) == 0) {
		argv++;
		remote_type = REMOTE_DONGLE;
	}

#if defined (RWL_SERIAL) || defined (RWL_DONGLE)
	if (remote_type == REMOTE_SERIAL || remote_type == REMOTE_DONGLE) {
		if (!(*argv)) {
			rwl_usage(remote_type);
			return err;
		}
		g_rwl_device_name_serial = *argv;
		argv++;
		if ((serialHandle = rwl_open_pipe(remote_type, g_rwl_device_name_serial, 0, 0))
			 == NULL) {
			DPRINT_ERR(ERR, "serial device open error\r\n");
			return -1;
		}
		ifr = (*(struct ifreq *)serialHandle);
	}
#endif /*  RWL_SERIAL */

	/* RWL over wifi.  Usage: --wifi mac_address */
	if (*argv && strncmp (*argv, "--wifi", strlen(*argv)) == 0) {
		argv++;
		/* use default interface */
		if (!*ifr.ifr_name)
			wl_find(&ifr);
		/* validate the interface */
		if (!*ifr.ifr_name || wl_check((void*)&ifr)) {
			fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
			exit(1);
		}
		remote_type = REMOTE_WIFI;

		if (argc < 4) {
			rwl_usage(remote_type);
			return err;
		}
		/* copy server mac address to local buffer for later use by findserver cmd */
		if (!wl_ether_atoe(*argv, (struct ether_addr *)g_rwl_buf_mac)) {
			fprintf(stderr,
			"could not parse as an ethternet MAC address\n");
			return FAIL;
		}
		argv++;
	}

	if ((*argv) && (strlen(*argv) > 2) &&
		(strncmp(*argv, "--interactive", strlen(*argv)) == 0)) {
		interactive_flag = 1;
	}

	/* Process for local wl */
	if (remote_type == NO_REMOTE) {
		if (interactive_flag == 1)
			argv--;
		err = process_args(&ifr, argv);
		return err;
	}

	if (interactive_flag == 1) {
		err = do_interactive(&ifr);
		return err;
	}

	if ((*argv) && (interactive_flag == 0)) {
		err = process_args(&ifr, argv);
		if ((err == SERIAL_PORT_ERR) && (remote_type == REMOTE_DONGLE)) {
			DPRINT_ERR(ERR, "\n Retry again\n");
			err = process_args((struct ifreq*)&ifr, argv);
		}
		return err;
	}
	rwl_usage(remote_type);
#if defined (RWL_DONGLE) || (RWL_SERIAL)
	if (remote_type == REMOTE_DONGLE || remote_type == REMOTE_SERIAL)
		rwl_close_pipe(remote_type, (void*)&ifr);
#endif /* RWL_DONGLE || RWL_SERIAL */
	return err;
}

/*
 * Function called for  'local' execution and for 'remote' non-interactive session
 * (shell cmd, wl cmd)
 */
int
process_args(struct ifreq* ifr, char **argv)
{
	char *ifname = NULL;
	int help = 0;
	int status = 0;
	int vista_cmd_index;
	int err = 0;
	cmd_t *cmd = NULL;
#ifdef RWL_WIFI
	int retry;
#endif

	while (*argv) {
		if ((strcmp (*argv, "sh") == 0) && (remote_type != NO_REMOTE)) {
			argv++; /* Get the shell command */
			if (*argv) {
				/* Register handler in case of shell command only */
				err = rwl_shell_cmd_proc((void*)ifr, argv, SHELL_CMD);
			} else {
				DPRINT_ERR(ERR, "Enter the shell "
				           "command, e.g. ls(Linux) or dir(Win CE)\n");
				err = -1;
			}
			return err;
		}

#ifdef RWLASD
		if ((strcmp (*argv, "asd") == 0) && (remote_type != NO_REMOTE)) {
			argv++; /* Get the asd command */
			if (*argv) {
				err = rwl_shell_cmd_proc((void*)ifr, argv, ASD_CMD);
			} else {
				DPRINT_ERR(ERR, "Enter the ASD command, e.g. ca_get_version\n");
				err = -1;
			}
			return err;
		}
#endif
		if (rwl_os_type == WINVISTA_OS) {
			for (vista_cmd_index = 0; remote_vista_cmds[vista_cmd_index] &&
				strcmp(remote_vista_cmds[vista_cmd_index], *argv);
				vista_cmd_index++);
			if (remote_vista_cmds[vista_cmd_index] != NULL) {
				err = rwl_shell_cmd_proc((void *)ifr, argv, VISTA_CMD);
				if ((remote_type == REMOTE_WIFI) && ((!strcmp(*argv, "join")))) {
#ifdef RWL_WIFI
					DPRINT_INFO(OUTPUT,
						"\nChannel will be synchronized by Findserver\n\n");
					sleep(RWL_WIFI_JOIN_DELAY);
					for (retry = 0; retry < RWL_WIFI_RETRY; retry++) {
						if ((rwl_find_remote_wifi_server(ifr,
							&g_rwl_buf_mac[0]) == 0)) {
						break;
					}
				}
#endif /* RWL_WIFI */
			}
			return err;
			}
		}

		if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
			if (help)
				break;
			if (ifname) {
				if (remote_type == NO_REMOTE) {
					strncpy((*ifr).ifr_name, ifname, IFNAMSIZ);
				}
				else {
					strncpy(g_rem_ifname, ifname, IFNAMSIZ);
				}
			}
			continue;
		}
		/* parse error */
		else if (status == CMD_ERR)
			break;

		if (remote_type == NO_REMOTE) {
			/* use default interface */
			if (!*(*ifr).ifr_name)
				wl_find(ifr);
			/* validate the interface */
			if (!*(*ifr).ifr_name || wl_check((void *)ifr)) {
				fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
				exit(1);
			}

			if ((strcmp (*argv, "--interactive") == 0) || (interactive_flag == 1)) {
				err = do_interactive(ifr);
				return err;
			}
		 }
		/* search for command */
		cmd = wl_find_cmd(*argv);
		/* if not found, use default set_var and get_var commands */
		if (!cmd) {
			cmd = &wl_varcmd;
		}
#ifdef RWL_WIFI
		if (!strcmp(cmd->name, "findserver")) {
			remote_wifi_ser_init_cmds((void *) ifr);
		}
#endif /* RWL_WIFI */

		/* RWL over Wifi supports 'lchannel' command which lets client
		 * (ie *this* machine) change channels since normal 'channel' command
		 * applies to the server (ie target machine)
		 */
		if (remote_type == REMOTE_WIFI)	{
#ifdef RWL_WIFI
			if (!strcmp(argv[0], "lchannel")) {
				strcpy(argv[0], "channel");
				rwl_wifi_swap_remote_type(remote_type);
				err = (*cmd->func)((void *) ifr, cmd, argv);
				rwl_wifi_swap_remote_type(remote_type);
			} else {
				err = (*cmd->func)((void *) ifr, cmd, argv);
			}
			/* After join cmd's gets exeuted on the server side , client needs to know
			* the channel on which the server is associated with AP , after delay of
			* few seconds client will intiate the scan on diffrent channels by calling
			* rwl_find_remote_wifi_server fucntion
			*/
			if ((!strcmp(cmd->name, "join") || ((!strcmp(cmd->name, "ssid") &&
				(*(++argv) != NULL))))) {
				DPRINT_INFO(OUTPUT, "\n Findserver is called to synchronize the"
				"channel\n\n");
				sleep(RWL_WIFI_JOIN_DELAY);
				for (retry = 0; retry < RWL_WIFI_RETRY; retry++) {
					if ((rwl_find_remote_wifi_server(ifr,
					&g_rwl_buf_mac[0]) == 0)) {
						break;
					}
				}
			}
#endif /* RWL_WIFI */
		} else {
			/* do command */
			err = (*cmd->func)((void *) ifr, cmd, argv);
		}
		break;
	} /* while loop end */

/* provide for help on a particular command */
	if (help && *argv) {
		cmd = wl_find_cmd(*argv);
		if (cmd) {
			wl_cmd_usage(stdout, cmd);
		} else {
			DPRINT_ERR(ERR, "%s: Unrecognized command \"%s\", type -h for help\n",
			                                                          wlu_av0, *argv);
		}
	} else if (!cmd)
		wl_usage(stdout, NULL);
	else if (err == USAGE_ERROR)
		wl_cmd_usage(stderr, cmd);
	else if (err == IOCTL_ERROR)
		wl_printlasterror((void *) ifr);
	else if (err == BCME_NODEVICE)
		DPRINT_ERR(ERR, "%s : wl driver adapter not found\n", g_rem_ifname);

	return err;
}