/* * Configures local channel for finding server. * Server call this fucntion for getting its current channel, * client uses this fucntion for setting its channel to new channel. */ static int rwl_wifi_config_channel(void *wl, int cmd, int *channel) { int error; channel_info_t ci; /* Get functionality is used only by server */ if (cmd == WLC_GET_CHANNEL) { memset((char*)&ci, 0, sizeof(ci)); if ((error = wl_get(wl, cmd, &ci, sizeof(channel_info_t)))) return error; ci.hw_channel = dtoh32(ci.hw_channel); ci.scan_channel = dtoh32(ci.scan_channel); ci.target_channel = dtoh32(ci.target_channel); if (ci.scan_channel) printf("Scan in progress.\n"); *channel = ci.hw_channel; } if (cmd == WLC_SET_CHANNEL) { /* Set functionality is used by the client */ ci.target_channel = *channel; /* When user wants to execute local CMD being in remote wifi mode, * rwl_wifi_swap_remote_type fucntion is used to change the remote types. */ rwl_wifi_swap_remote_type(remote_type); error = wl_set(wl, cmd, &ci.target_channel, sizeof(int)); /* rever it back to same old remote type */ rwl_wifi_swap_remote_type(remote_type); } return error; }
int rwl_var_getbuf(void *wl, const char *iovar, void *param, int param_len, void **bufptr) { int len, error; memset((char*)g_rwl_aligned_buf, 0, WLC_IOCTL_MAXLEN); strcpy(g_rwl_aligned_buf, iovar); /* include the null */ len = strlen(iovar) + 1; if (param_len) memcpy(&g_rwl_aligned_buf[len], param, param_len); *bufptr = g_rwl_aligned_buf; /* When user wants to execute local CMD being in remote wifi mode, * rwl_wifi_swap_remote_type fucntion is used to change the remote types. */ rwl_wifi_swap_remote_type(remote_type); error = wl_get(wl, WLC_GET_VAR, &g_rwl_aligned_buf[0], WLC_IOCTL_MAXLEN); /* revert back to the old remote type */ rwl_wifi_swap_remote_type(remote_type); return error; }
/* This function will send the buffer to the dongle driver */ int rwl_var_send_vs_actionframe(void* wl, const char* iovar, void* param, int param_len) { int len, error; memset(g_rwl_aligned_buf, 0, WLC_IOCTL_MAXLEN); strcpy(g_rwl_aligned_buf, iovar); /* include the null */ len = strlen(iovar) + 1; if (param_len) memcpy((void*)&g_rwl_aligned_buf[len+ OFFSETOF(wl_action_frame_t, data)], param, param_len); /* Set the PacketID (not used by remote WL */ memset((void*)&g_rwl_aligned_buf[len + OFFSETOF(wl_action_frame_t, packetId)], 0, 4); /* Set the dest addr */ memcpy((void*)&g_rwl_aligned_buf[len + OFFSETOF(wl_action_frame_t, da)], (void*)g_rwl_buf_mac, ETHER_ADDR_LEN); /* set the length */ memcpy((void*)&g_rwl_aligned_buf[len + OFFSETOF(wl_action_frame_t, len)], (void*) ¶m_len, 2); len += param_len + ETHER_ADDR_LEN + 2 + 4; /* When user wants to execute local CMD being in remote wifi mode, * rwl_wifi_swap_remote_type fucntion is used to change the remote types. */ rwl_wifi_swap_remote_type(remote_type); error = wl_set(wl, WLC_SET_VAR, &g_rwl_aligned_buf[0], len); /* revert back to the old type */ rwl_wifi_swap_remote_type(remote_type); return error; }
/* Function called for 'local' interactive session and for 'remote' interactive session */ static int do_interactive(struct ifreq *ifr) { int err = 0; #ifdef RWL_WIFI int retry; #endif while (1) { char *fgsret; char line[INTERACTIVE_MAX_INPUT_LENGTH]; fprintf(stdout, "> "); fgsret = fgets(line, sizeof(line), stdin); /* end of file */ if (fgsret == NULL) break; if (line[0] == '\n') continue; if (strlen (line) > 0) { /* skip past first arg if it's "wl" and parse up arguments */ char *argv[INTERACTIVE_NUM_ARGS]; int argc; char *token; argc = 0; while (argc < (INTERACTIVE_NUM_ARGS - 1) && (token = strtok(argc ? NULL : line, " \t\n")) != NULL) { /* Specifically make sure empty arguments (like SSID) are empty */ if (token[0] == '"' && token[1] == '"') { token[0] = '\0'; } argv[argc++] = token; } argv[argc] = NULL; if (argc == (INTERACTIVE_NUM_ARGS - 1) && (token = strtok(NULL, " \t")) != NULL) { printf("wl:error: too many args; argc must be < %d\n", (INTERACTIVE_NUM_ARGS - 1)); continue; } #ifdef RWL_WIFI if (!strcmp(argv[0], "findserver")) { remote_wifi_ser_init_cmds((void *) ifr); } #endif /* RWL_WIFI */ if (strcmp(argv[0], "q") == 0 || strcmp(argv[0], "exit") == 0) { break; } if ((strcmp(argv[0], "sh") == 0) && (remote_type != NO_REMOTE)) { if (argv[1]) { process_args(ifr, argv); } else { DPRINT_ERR(ERR, "Give shell command"); continue; } } else { /* end shell */ /* check for lchannel support,applicable only for wifi transport. * when lchannel is called remote type is swapped by calling swap_ * remote_type.This is done to change, the remote type to local, * so that local machine's channel can be executed and * returned to the user. * To get back the original remote type, swap is recalled. */ 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 = wl_do_cmd(ifr, argv); rwl_wifi_swap_remote_type(remote_type); } else { err = wl_do_cmd(ifr, 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 function */ if ((!strcmp(argv[0], "join")) || (!strcmp(argv[0], "ssid"))) { DPRINT_INFO(OUTPUT, "\n Findserver is called" "after the join issued to remote \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 { err = wl_do_cmd(ifr, argv); } } /* end of wl */ } /* end of strlen (line) > 0 */ } /* while (1) */ return err; }
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; }