📄 wlancfg.c
字号:
** Returns: 0 - Success.** 1 - Failure.*/static int wlancfg_show(char *device, /* I: Device name. */int all) /* I: "all" flag. */{ int result; req_spec_t mibget; p80211ioctl_req_t req; UINT8 msg[MSG_BUFF_LEN]; int skt, i, j, k, ncats, ngrps, nitems, out; UINT32 did; grplistitem_t *grp; p80211meta_t *item; char value[MSG_BUFF_LEN]; /* ** All MIB values will be queried using the "dot11req_mibget" request. ** Do some initialization for this request. */ result = wlancfg_reqspec("dot11req_mibget", &mibget); if (result != 0) return(1); /* ** Get a socket to be used to talk to the device driver and then ** set up the invariant parts of the "ioctl" request. The variable ** parts (i.e. length and result code) will be set later when the ** actual requests are created. */ skt = socket(AF_INET, SOCK_STREAM, 0); if (skt == -1) { perror("wlancfg"); return(1); } strncpy(req.name, device, sizeof(req.name)); req.magic = P80211_IOCTL_MAGIC; /* Set the magic. */ req.data = msg; /* ** Scan through all the MIB's in all the groups in all the catagories. ** Output the MIB if it is writeable or if all MIB's are being output. ** However, DON'T output the MIB if it is not readable! */ ncats = GETMETASIZE(mib_catlist); for (i = 1; i < ncats; i++) { ngrps = GETMETASIZE(mib_catlist[i].grplist); for (j = 1; j < ngrps; j++) { did = P80211DID_MKSECTION(i) | P80211DID_MKGROUP(j); grp = p80211_did2grp(mib_catlist, did); if (grp == NULL) /* Should never happen. */ { fprintf(stderr, "wlancfg: DID %lx not found.\n", did); return(1); } item = grp->itemlist; nitems = GETMETASIZE(item); for (item++, k = 1; k < nitems; k++, item++) { out = all || ((item->did & P80211DID_ACCESS_WRITE) != 0); out = out && ((item->did & P80211DID_ACCESS_READ) != 0); if (out) { result = wlancfg_getvalue(device, item, &mibget, skt, &req, value); if (result != 0) return(1); /* ** Output the value only if a value was found (i.e. skip ** unsupported MIB's). */ if (value[0] != '\0') printf("%s\n", value); } } } } return(0);}/********************************************************************* wlancfg_set**** Set the wlan parameters.**** Returns: 0 - Success.** 1 - Failure.*/static int wlancfg_set(char *device) /* I: Device name. */{ int result; req_spec_t mibset; p80211ioctl_req_t req; UINT8 msg[MSG_BUFF_LEN]; int skt; char pair[500], *ch; /* ** All MIB values will be set using the "dot11req_mibset" request. ** Do some initialization for this request. */ result = wlancfg_reqspec("dot11req_mibset", &mibset); if (result != 0) return(1); /* ** Get a socket to be used to talk to the device driver and then ** set up the invariant parts of the "ioctl" request. The variable ** parts (i.e. length and result code) will be set later when the ** actual requests are created. */ skt = socket(AF_INET, SOCK_STREAM, 0); if (skt == -1) { perror("wlancfg"); return(1); } strncpy(req.name, device, sizeof(req.name)); req.magic = P80211_IOCTL_MAGIC; /* Set the magic. */ req.data = msg; /* ** Read MIB name/value pairs from "stdin" until there are no more. ** There should be one pair per line. The following things can happen ** with "fgets()": ** ** 1. Nothing is read (i.e. end of file). We are done. ** 2. The last character read is a '\n'. Strip the carriage return ** off and process the line. ** 3. No '\n' was read but the buffer was not filled. The last ** line in the file has been read. Process it. The next read ** should result in an end-of-file. ** 4. No '\n' was read and the buffer was filled. The line is ** too long. Abort things. */ while (1) { if (fgets(pair, sizeof(pair), stdin) == NULL) break; ch = strrchr(pair, '\n'); if (ch != NULL) *ch = '\0'; else if (strlen(pair) >= sizeof(pair)-1) { fprintf(stderr, "wlancfg: MIB name/value is too long.\n"); return(1); } /* ** Set the MIB value. */ result = wlancfg_setvalue(device, &mibset, skt, &req, pair); if (result != 0) return(1); } return(0);}/********************************************************************* wlancfg_list**** List all supported MIB's.*/static void wlancfg_list(void){ int i, j, k, l; int ncat, ngrp, nitm; int len, cnt, type; catlistitem_t *cat; grplistitem_t *grp; p80211meta_t *mib; p80211enum_t *enump; /* ** Go through every MIB in every group in every catagory and find the ** maximum MIB name length. */ len = 0; ncat = GETMETASIZE(mib_catlist); cat = mib_catlist + 1; for (i = 1; i < ncat; i++, cat++) { ngrp = GETMETASIZE(cat->grplist); grp = (cat->grplist) + 1; for (j = 1; j < ngrp; j++, grp++) { nitm = GETMETASIZE(grp->itemlist); mib = grp->itemlist + 1; for (k = 1; k < nitm; k++, mib++) { l = strlen(mib->name); if (len < l) len = l; } } } /* ** Go through each MIB catagory. */ ncat = GETMETASIZE(mib_catlist); cat = mib_catlist + 1; for (i = 1; i < ncat; i++, cat++) { cnt = printf("\nCatagory: %s\n", cat->name); for (j = 2; j < cnt; j++) printf("="); printf("\n"); /* ** Go through each MIB in this group. */ ngrp = GETMETASIZE(cat->grplist); grp = (cat->grplist) + 1; for (j = 1; j < ngrp; j++, grp++) { printf("\n%s\n", grp->name); nitm = GETMETASIZE(grp->itemlist); mib = grp->itemlist + 1; for (k = 1; k < nitm; k++, mib++) { cnt = printf(" %s", mib->name); for (l = cnt-6; l < len; l++) printf(" "); printf((mib->did & P80211DID_ACCESS_READ) ? "R" : " "); printf((mib->did & P80211DID_ACCESS_WRITE) ? "W " : " "); type = p80211item_gettype(mib); if (type == P80211_TYPE_OCTETSTR) printf("OCTETSTR{minlen=%ld,maxlen=%ld}\n", mib->minlen, mib->maxlen); else if (type == P80211_TYPE_DISPLAYSTR) printf("DISPLAYSTR{minlen=%ld,maxlen=%ld}\n", mib->minlen, mib->maxlen); else if (type == P80211_TYPE_INT) { if (mib->min || mib->max) printf("INT{min=%ld,max=%ld}\n", mib->min, mib->max); else printf("INT\n"); } else if (type == P80211_TYPE_ENUMINT) { printf("ENUMINT{"); enump = mib->enumptr; for (l = 0; l < enump->nitems; l++) { printf("%s", enump->list[l].name); if (l < enump->nitems - 1) printf("|"); } printf("}\n"); } else if (type == P80211_TYPE_UNKDATA) printf("UNKDATA{maxlen=%ld}\n", mib->maxlen); else if (type == P80211_TYPE_INTARRAY) printf("INTARRAY{len=%ld}\n", mib->maxlen); else if (type == P80211_TYPE_BITARRAY) printf("BITARRAY{range=%ld-%ld}\n", mib->min, mib->max); else if (type == P80211_TYPE_MACARRAY) printf("MACARRAY{maxlen=%ld}\n", mib->maxlen); else printf("Unknown type!\n"); } } } return;}/********************************************************************* wlancfg_reqspec**** Build the "request specification" structure for the "dot11req_mibget"** or "dot11req_mibset" request. As well, verify that the request is as we** expect it. Note that this verification shouldn't be necessary at all** if we are sure that there is no bug in the request definition!**** Returns: 0 - Success.** 1 - Failure.*/static int wlancfg_reqspec(char *request, /* I: "dot11req_mibget" or "dot11req_mibset". */req_spec_t *spec) /* O: Request specification. */{ int result; p80211meta_t *arglist; /* ** Find the request message code. */ result = wlancfg_getreq("dot11req", request, 2, &spec->msgcode, &arglist); if (result != 0) return(1); /* ** Make sure that the first argument is "mibattribute". If so, then ** fill in the specification for the "mibattribute" argument. Make ** sure that the offset and length values are valid. Also, make sure ** that the "mibattribute" argument is flagged as "request" and that ** there are conversion functions defined for it. */ if (strcmp(arglist[1].name, "mibattribute") != 0) { fprintf(stderr, "wlancfg: First argument is not MIBATTRIBUTE.\n"); return(1); } spec->attptr = &arglist[1]; spec->attdid = spec->msgcode | P80211DID_MKITEM(1) | arglist[1].did; spec->attoff = p80211item_getoffset(msg_catlist, spec->attdid); spec->attlen = p80211item_maxdatalen(msg_catlist, spec->attdid); if (spec->attoff == 0xffffffff || spec->attlen == 0xffffffffUL) { fprintf(stderr, "wlancfg: Invalid MIBATTRIBUTE offset or length.\n"); return(1); } if (!P80211ITEM_ISREQUEST(arglist[1].flags)) { fprintf(stderr, "wlancfg: MIBATTRIBUTE argument is non-request.\n"); return(1); } if (arglist[1].fromtextptr == NULL || arglist[1].totextptr == NULL) { fprintf(stderr, "wlancfg: Missing MIBATTRIBUTE conversion function.\n"); return(1); } /* ** Make sure that the second argument is "resultcode". If so, then ** fill in the specification for the "resultcode" argument. Make ** sure that the offset and length values are valid. Also, make sure ** that it is not a required argument. */ if (strcmp(arglist[2].name, "resultcode") != 0) { fprintf(stderr, "wlancfg: Second argument is not RESULTCODE.\n"); return(1); } spec->resptr = &arglist[2]; spec->resdid = spec->msgcode | P80211DID_MKITEM(2) | arglist[2].did; spec->resoff = p80211item_getoffset(msg_catlist, spec->resdid); spec->reslen = p80211item_maxdatalen(msg_catlist, spec->resdid); if (spec->resoff == 0xffffffff || spec->reslen == 0xffffffffUL) { fprintf(stderr, "wlancfg: Invalid RESULTCODE offset or length.\n"); return(1); } if ((P80211ITEM_ISREQUIRED(arglist[2].flags)) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -