Пример #1
0
int wlmRxPacketStart(const char* srcMac, int withAck,
	int syncMode, unsigned int numPackets, unsigned int timeout)
{
	wl_pkteng_t pkteng;

	if (!wl_ether_atoe(srcMac, (struct ether_addr *)&pkteng.dest)) {
		printf("wlmRxPacketStart: srcMac invalid\n");
		return FALSE;
	}

	pkteng.flags = withAck ? WL_PKTENG_PER_RX_WITH_ACK_START : WL_PKTENG_PER_RX_START;

	if (syncMode) {
		pkteng.flags |= WL_PKTENG_SYNCHRONOUS;
		pkteng.nframes = numPackets;
		pkteng.delay = timeout;
	}
	else
		pkteng.flags &= ~WL_PKTENG_SYNCHRONOUS;

	if (wlu_var_setbuf(irh, "pkteng", &pkteng, sizeof(pkteng))) {
		printf("wlmRxPacketStart: %s\n", wlmLastError());
		return FALSE;
	}

	return TRUE;
}
Пример #2
0
int wlmTxPacketStart(unsigned int interPacketDelay,
	unsigned int numPackets, unsigned int packetLength,
	const char* destMac, int withAck, int syncMode)
{
	wl_pkteng_t pkteng;

	if (!wl_ether_atoe(destMac, (struct ether_addr *)&pkteng.dest)) {
		printf("wlmTxPacketStart: destMac invalid\n");
		return FALSE;
	}

	pkteng.flags = withAck ? WL_PKTENG_PER_TX_WITH_ACK_START : WL_PKTENG_PER_TX_START;

	if (syncMode)
		pkteng.flags |= WL_PKTENG_SYNCHRONOUS;
	else
		pkteng.flags &= ~WL_PKTENG_SYNCHRONOUS;

	pkteng.delay = interPacketDelay;
	pkteng.length = packetLength;
	pkteng.nframes = numPackets;

	pkteng.seqno = 0;			/* not used */
	pkteng.src = ether_null;	/* implies current ether addr */

	if (wlu_var_setbuf(irh, "pkteng", &pkteng, sizeof(pkteng))) {
		printf("wlmTxPacketStart: %s\n", wlmLastError());
		return FALSE;
	}

	return TRUE;
}
static int
lua_set_acllist(lua_State *L, void *wl, lua_cmd_t *cmd, char *buf)
{
	struct maclist *maclist = (struct maclist *) buf;
	struct ether_addr *ea;
	uint max = (WLC_IOCTL_MAXLEN - sizeof(int)) / ETHER_ADDR_LEN;
	char *nargv[128];
	char **argv;
	uint len;

	cmd_split(buf, (char **)nargv, 128);
	argv = (char **)nargv;

	/* Clear list */
	maclist->count = htod32(0);
	ea = maclist->ea;
	while (*argv && maclist->count < max)
	{
		if (!wl_ether_atoe(*argv, ea))
		{
			return -1;
		}
		maclist->count++;
		ea++;
		argv++;
	}

	/* Set new list */
	len = sizeof(maclist->count) + maclist->count * sizeof(maclist->ea);
	maclist->count = htod32(maclist->count);
	return wlu_set(wl, WLC_SET_MACLIST, maclist, len);
}
Пример #4
0
int wlmMacAddrSet(const char* macAddr)
{
	struct ether_addr ea;

	if (!wl_ether_atoe(macAddr, &ea)) {
		printf("wlmMacAddrSet: MAC address invalid: %s\n", macAddr);
		return FALSE;
	}

	/*  Set 'cur_etheraddr' to set MAC address */
	if (wlu_iovar_set(irh, "cur_etheraddr", (void *)&ea, ETHER_ADDR_LEN)) {
		printf("wlmMacAddrSet: %s\n", wlmLastError());
		return FALSE;
	}

	return TRUE;
}
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;
    char *tmp_argv[LINUX_NUM_ARGS];
    char **argv = tmp_argv;
    int argc;

    /* buf_to_args return 0 if no args or string too long
     * or return NDIS_NUM_ARGS if too many args
     */
    if (((argc = buf_to_args(input_str, argv)) == 0) || (argc == LINUX_NUM_ARGS)) {
        printf("wl:error: 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;
#if defined(RWL_DONGLE) || RWL_SERIAL
    void* serialHandle = NULL;
#endif

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

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

    if ((status = wl_option(&argv, &ifname, &help)) == CMD_OPT) {
        if (ifname)
        {
            if (strcmp(ifname, "eth1") == 0)
            {
                strncpy(ifr.ifr_name, "wl0", IFNAMSIZ);
            }
            else if (strcmp(ifname, "eth2") == 0)
            {
                strncpy(ifr.ifr_name, "wl1", IFNAMSIZ);
            }
            else
            {
                strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
            }
        }
        /* Bug fix: If -h is used as an option, the above function call
         * will notice it and raise the flag but it won't be processed
         * in this function so we undo the argv increment so that the -h
         * can be spotted by the next call of wl_option. This will ensure
         * that wl -h [cmd] will function as desired.
         */
        else if (help)
            (void)*argv--;
    }

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

    /* Provide option for disabling remote DUT autodetect */
    if (*argv && strncmp(*argv, "--nodetect", strlen(*argv)) == 0) {
        rwl_dut_autodetect = FALSE;
        argv++;
    }

    if (*argv && strncmp (*argv, "--debug", strlen(*argv)) == 0) {
        debug = TRUE;
        argv++;
    }

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

        remote_type = REMOTE_SOCKET;

        if (!(*argv)) {
            rwl_usage(remote_type);
            return err;
        }
        /* IP address validation is done in client_shared file */
        g_rwl_servIP = *argv;
        (void)*argv++;

        g_rwl_servport = DEFAULT_SERVER_PORT;
        if ((*argv) && isdigit(**argv)) {
            g_rwl_servport = atoi(*argv);
            (void)*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) {
        (void)*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) {
        (void)*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;
        (void)*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) {
        (void)*argv++;
        /* use default interface */
        if (!*ifr.ifr_name)
            wl_find(&ifr);
        /* validate the interface */
        if (!*ifr.ifr_name) {
            errno = ENXIO;
            syserr("interface");
        }
        if ((err = wl_check((void *)&ifr)) < 0) {
            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;
        }
        (void)*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)
            (void)*argv--;
        err = process_args(&ifr, argv);
        return err;
    } else {
#ifndef OLYMPIC_RWL
        /* Autodetect remote DUT */
        if (rwl_dut_autodetect == TRUE)
            rwl_detect((void*)&ifr, debug, &rwl_os_type);
#endif /* OLYMPIC_RWL */
    }

    /* RWL client needs to initialize ioctl_version */
    if (wl_check((void *)&ifr) != 0) {
        fprintf(stderr, "%s: wl driver adapter not found\n", wlu_av0);
        exit(1);
    }

    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)) {
            (void)*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)) {
            (void)*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) {
                errno = ENXIO;
                syserr("interface");
            }
            if ((err = wl_check((void *)ifr)) < 0) {
                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;
}
Пример #6
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;
}