void dhd_find(struct ifreq *ifr) { char proc_net_dev[] = "/proc/net/dev"; FILE *fp; char buf[1000], *c, *name; char dev_type[DEV_TYPE_LEN]; ifr->ifr_name[0] = '\0'; /* eat first two lines */ if (!(fp = fopen(proc_net_dev, "r")) || !fgets(buf, sizeof(buf), fp) || !fgets(buf, sizeof(buf), fp)) return; while (fgets(buf, sizeof(buf), fp)) { c = buf; while (isspace(*c)) c++; if (!(name = strsep(&c, ":"))) continue; strncpy(ifr->ifr_name, name, IFNAMSIZ); if (dhd_get_dev_type(name, dev_type, DEV_TYPE_LEN) >= 0 && !strncmp(dev_type, "dhd", 3)) if (dhd_check((void *)ifr) == 0) break; ifr->ifr_name[0] = '\0'; } fclose(fp); }
/* Verify the wl adapter found. * This is called by dhd_find to check if it supports wl * The reason for checking wl adapter is that we can still send remote dhd commands over * wifi transport. The function is copied from wlu.c. */ int wl_check(void *wl) { int ret; int val = 0; if (!dhd_check (wl)) return 0; /* * If dhd_check() fails then go for a regular wl driver verification */ if ((ret = wl_get(wl, WLC_GET_MAGIC, &val, sizeof(int))) < 0) return ret; if (val != WLC_IOCTL_MAGIC) return BCME_ERROR; if ((ret = wl_get(wl, WLC_GET_VERSION, &val, sizeof(int))) < 0) return ret; if (val > WLC_IOCTL_VERSION) { fprintf(stderr, "Version mismatch, please upgrade\n"); return BCME_ERROR; } return 0; }
int main(int argc, char **argv) { HANDLE irh; WINERR err = ERROR_SUCCESS; int ap_mode = 0; cmd_t *cmd = NULL; int init_err = TRUE; char *ifname = NULL; int help = 0; int status; /* initialize irelay and select default adapter */ irh = INVALID_HANDLE_VALUE; if ((err = ir_init(&irh)) != ERROR_SUCCESS) goto done; ndevs = ARRAYSIZE(devlist); if (((err = ir_adapter_list(irh, &devlist[0], &ndevs)) != ERROR_SUCCESS) || ((err = select_adapter(irh, -1)) != ERROR_SUCCESS)) goto done; init_err = FALSE; for (++argv; *argv;) { /* command line option */ if ((status = dhd_option(&argv, &ifname, &help)) == CMD_OPT) { /* print usage */ if (help) break; /* select different adapter */ if (ifname) { ir_unbind(irh); if ((err = select_adapter(irh, atoi(ifname))) != ERROR_SUCCESS) break; if (dhd_check((void *)irh)) break; } continue; } if (dhd_check((void *)irh)) break; /* 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 = (WINERR) (*cmd->func)((void *) irh, cmd, argv); break; } done: /* 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) display_err("main:", err); if (irh != INVALID_HANDLE_VALUE) { ir_unbind(irh); ir_exit(irh); } return err; }
/* * 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; }
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; }