Ejemplo n.º 1
0
/*
 * Function called for  'local' execution and for 'remote' non-interactive session
 * (shell cmd, wl cmd) .The code is mostly from wlu_linux.c. This code can be
 * common to wlu_linux.c and dhdu_linux.c
 */
static int
process_args(struct ifreq* ifr, char **argv)
{
	char *ifname = NULL;
	int help = 0;
	int status = 0;
	int err = BCME_OK;
	cmd_t *cmd = NULL;
	while (*argv) {
#ifdef RWL_ENABLE
		if ((strcmp (*argv, "sh") == 0) && (remote_type != NO_REMOTE)) {
			argv++; /* Get the shell command */
			if (*argv) {
				/* Register handler in case of shell command only */
				signal(SIGINT, ctrlc_handler);
				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 = BCME_ERROR;
			}
			return err;
		}
#endif /* RWL_ENABLE */
		if ((status = dhd_option(&argv, &ifname, &help)) == CMD_OPT) {
			if (help)
				break;
			if (ifname)
				strncpy(ifr->ifr_name, ifname, IFNAMSIZ);
			continue;
		}
		/* parse error */
		else if (status == CMD_ERR)
		    break;

		if (remote_type == NO_REMOTE) {
		/* use default interface */
			if (!ifr->ifr_name[0])
				dhd_find(ifr, "dhd");
			/* validate the interface */
			if (!ifr->ifr_name[0] || dhd_check((void *)ifr)) {
			if (strcmp("dldn", *argv) != 0) {
				fprintf(stderr, "%s: dhd driver adapter not found\n", av0);
				exit(BCME_ERROR);
				}
			}

		}
		/* search for command */
		cmd = dhd_find_cmd(*argv);
		/* if not found, use default set_var and get_var commands */
		if (!cmd) {
			cmd = &dhd_varcmd;
		}

		/* do command */
		err = (*cmd->func)((void *) ifr, cmd, argv);
		break;
	} /* while loop end */

	/* provide for help on a particular command */
	if (help && *argv) {
		cmd = dhd_find_cmd(*argv);
		if (cmd) {
			dhd_cmd_usage(cmd);
		} else {
			DPRINT_ERR(ERR, "%s: Unrecognized command \"%s\", type -h for help\n",
			           av0, *argv);
		}
	} else if (!cmd)
		dhd_usage(NULL);
	else if (err == USAGE_ERROR)
		dhd_cmd_usage(cmd);
	else if (err == IOCTL_ERROR)
		dhd_printlasterror((void *) ifr);

	return err;
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
	struct ifreq ifr;
	cmd_t *cmd = NULL;
	int err = 0;
	char *ifname = NULL;
	int help = 0;
	int status = CMD_DHD;

	UNUSED_PARAMETER(argc);

	dhdu_av0 = argv[0];

	memset(&ifr, 0, sizeof(ifr));

	for (++argv; *argv;) {

		/* command option */
		if ((status = dhd_option(&argv, &ifname, &help)) == CMD_OPT) {
			if (help)
				break;
			if (ifname) {
				if (strlen(ifname) > IFNAMSIZ) {
					fprintf(stderr, "%s: interface name too long\n", dhdu_av0);
					break;
				}
				strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
			}
			continue;
		}

		/* parse error */
		else if (status == CMD_ERR)
			break;

		/* use default if no interface specified */
		if (!*ifr.ifr_name)
			dhd_find(&ifr);
		/* validate the interface */
		if (!*ifr.ifr_name || dhd_check((void *)&ifr)) {
			fprintf(stderr, "%s: dhd driver adapter not found\n", dhdu_av0);
			exit(1);
		}

		/* search for command */
		for (cmd = dhd_cmds; cmd->name && strcmp(cmd->name, *argv); cmd++);

		/* defaults to using the set_var and get_var commands */
		if (cmd->name == NULL)
			cmd = &dhd_varcmd;

		/* do command */
		if (cmd->name)
			err = (*cmd->func)((void *)&ifr, cmd, argv);
		break;
	}

	/* In case of COMMAND_ERROR, command has already printed an error message */
	if (!cmd)
		dhd_usage(NULL);
	else if (err == USAGE_ERROR)
		dhd_cmd_usage(cmd);
	else if (err == IOCTL_ERROR)
		dhd_printlasterror((void *)&ifr);

	return err;
}