📄 wlancfg.c
字号:
/* src/wlancfg/wlancfg.c** User utility for setting, saving, and querying the wlan card configuration.** Copyright (C) 2001 Rebel.com Inc. All Rights Reserved.* --------------------------------------------------------------------** linux-wlan** The contents of this file are subject to the Mozilla Public* License Version 1.1 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.mozilla.org/MPL/** Software distributed under the License is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** Alternatively, the contents of this file may be used under the* terms of the GNU Public License version 2 (the "GPL"), in which* case the provisions of the GPL are applicable instead of the* above. If you wish to allow the use of your version of this file* only under the terms of the GPL and not to allow others to use* your version of this file under the MPL, indicate your decision* by deleting the provisions above and replace them with the notice* and other provisions required by the GPL. If you do not delete* the provisions above, a recipient may use your version of this* file under either the MPL or the GPL.** --------------------------------------------------------------------** Inquiries regarding the linux-wlan Open Source project can be* made directly to:** AbsoluteValue Systems Inc.* info@linux-wlan.com* http://www.linux-wlan.com** --------------------------------------------------------------------** Originally written 2001 by Robert James.** The author may be reached as bob.james@rebel.com, or* Robert James* Rebel.com Inc.* 150 Isabella St., Suite 1000* Ottawa, Ontario* Canada K1S 5R3** --------------------------------------------------------------------*//*** The "wlancfg" utility program provides an alternative method to** "wlanctl", for manipulating MIB values. It was designed to provide** an easier mechanism for saving and restoring the complete wireless** configuration (i.e. when re-starting the device driver) and to provide** a more efficient mechanism for GUI's to query multiple MIB's.**** Usage: wlancfg query dev** wlancfg show dev [all]** wlancfg set dev** wlancfg list** wlancfg version**** where: dev - Name of device (e.g. wlan0).**** The functions are as follows:**** query - Read MIB names (separated by whitespace) from "stdin"** and output their values (separated by carriage returns)** to "stdout". The MIB's may be either read/write or** read-only.** show - Query the values of all supported read/write MIB's and** output their values (separated by carriage returns) to** "stdout". The syntax of the output will be:**** name=value**** If the "all" parameter is specified, then all supported** MIB's (i.e. read-only MIB's as well) are output.** set - Read MIB name/value pairs (separated by carriage returns)** from "stdin" and set the values of the specified MIB's. The** pairs must have the same syntax as above. The MIB's must** be read/write.** list - Display a list of all supported MIB's.** version - Display the compiled version of "wlancfg".*//*================================================================*//* System Includes */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <ctype.h>/* Ugly hack for LinuxPPC R4, don't have time to figure it out right now */#if defined(__WLAN_PPC__)#undef __GLIBC__#endif#include <sys/types.h>#include <sys/ioctl.h>#include <sys/socket.h>/*================================================================*//* Project Includes */#include <wlan/wlan_compat.h>#include <wlan/version.h>#include <wlan/p80211types.h>#include <wlan/p80211msg.h>#include <wlan/p80211meta.h>#include <wlan/p80211metamsg.h>#include <wlan/p80211metamib.h>#include <wlan/p80211metastruct.h>#include <wlan/p80211ioctl.h>/*================================================================*//* Local Types *//*** The request specification (req_spec) structure is used to record** frequently used information about the "dot11req_mibget" and** "dot11req_mibset" request messages. It is used to prevent the** necessity of recalculating this information when executing these** requests repeatedly.*/typedef struct req_spec{ UINT32 msgcode; /* Request message code. */ UINT32 msglen; /* Length of message. */ p80211meta_t *attptr; /* "mibattribute" argument. */ UINT32 attdid; /* "mibattribute" DID. */ UINT32 attoff; /* Request message offset. */ UINT32 attlen; /* Request message data length. */ p80211meta_t *resptr; /* "resultcode" argument. */ UINT32 resdid; /* "resultcode" DID. */ UINT32 resoff; /* Request message offset. */ UINT32 reslen; /* Request message data length. */} req_spec_t;/*================================================================*//* Local Function Declarations */static void wlancfg_usage(void);static int wlancfg_query(char *device);static int wlancfg_show(char *device, int all);static int wlancfg_set(char *device);static void wlancfg_list(void);static int wlancfg_reqspec(char *request, req_spec_t *mibget);static int wlancfg_getvalue(char *device, p80211meta_t *item, req_spec_t *mibget, int skt, p80211ioctl_req_t *req, char *value);static int wlancfg_setvalue(char *device, req_spec_t *mibset, int skt, p80211ioctl_req_t *req, char *value);static int wlancfg_build(char *device, req_spec_t *spec, char *value, p80211msgd_t *msg);static void wlancfg_totext(p80211meta_t *item, req_spec_t *mibget, p80211msgd_t *msg, char *value);static int wlancfg_getreq(char *cat, char *name, int argcnt, UINT32 *msgcode, p80211meta_t **arglist);/********************************************************************* main**** "wlancfg" main entry point.**** Arguments: argc - Number of command line arguments.** argv - Array of argument strings.**** Returns: 0 - Success.** 1 - Failure.*/int main(int argc, char **argv){ int result, all; if (argc < 2) goto usage; if (strcmp(argv[1], "query") == 0) { if (argc != 3) goto usage; result = wlancfg_query(argv[2]); goto done; } if (strcmp(argv[1], "show") == 0) { all = 0; if (argc != 3) { if (argc != 4) goto usage; if (strcmp(argv[3], "all") != 0) goto usage; all = 1; } result = wlancfg_show(argv[2], all); goto done; } if (strcmp(argv[1], "set") == 0) { if (argc != 3) goto usage; result = wlancfg_set(argv[2]); goto done; } if (strcmp(argv[1], "list") == 0) { if (argc != 2) goto usage; wlancfg_list(); result = 0; goto done; } if (strcmp(argv[1], "version") == 0) { if (argc != 2) goto usage; printf("%s\n", WLAN_RELEASE); result = 0; goto done; }usage: wlancfg_usage(); result = 0;done: return(result);}/********************************************************************* wlancfg_usage**** Output the command syntax.*/static void wlancfg_usage(void){ printf("\nQuery, show, or set configuration settings.\n\n"); printf("Usage: wlancfg query dev\n"); printf(" wlancfg show dev [all]\n"); printf(" wlancfg set dev\n"); printf(" wlancfg list\n"); printf(" wlancfg version\n\n"); printf(" where: dev - Name of device (e.g. wlan0).\n"); return;}/********************************************************************* wlancfg_query**** Query specific MIB's and output their values.**** Returns: 0 - Success.** 1 - Failure.*/static int wlancfg_query(char *device) /* I: Device name. */{ int result; req_spec_t mibget; p80211ioctl_req_t req; UINT8 msg[MSG_BUFF_LEN]; int skt, cnt; char name[100], value[MSG_BUFF_LEN]; UINT32 did; p80211meta_t *item; /* ** 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; /* ** Read MIB names from "stdin" until there are no more. Make sure ** that the user hasn't had an "accident" and entered a name which ** is too long. ** ** Note: The "scanf()" documentation is not clear on how strings ** which are too long are handled. Possibilities are: ** ** 1. "n" characters read and no null-termination added. ** 2. "n" characters read and '\0' added at "name[n]". ** 3. "n-1" characters read and '\0' added at "name[n-1]". ** ** The following code will work in all 3 cases and not overflow ** the "name" array. */ name[sizeof(name)-2] = '\0'; name[sizeof(name)-1] = '\0'; while (1) { cnt = scanf("%99s", name); /* sizeof(name)-1 = 99 */ if (cnt == 0 || cnt == EOF) break; if (name[sizeof(name)-2] != '\0' || name[sizeof(name)-1] != '\0') { fprintf(stderr, "wlancfg: MIB name is too long.\n"); return(1); } /* ** Find the MIB. */ did = p80211_text2did(mib_catlist, NULL, NULL, name); if (did == P80211DID_INVALID) { fprintf(stderr, "wlancfg: Unknown MIB: %s\n", name); return(1); } item = p80211_did2item(mib_catlist, did); if (item == NULL) /* Should never happen. */ { fprintf(stderr, "wlancfg: Internal MIB search error: %s\n", name); return(1); } /* ** Query the MIB value and output it. If no value was found ** (i.e. the MIB is unsupported), then output an empty line so ** that the input names and output values don't get out of sync. ** Otherwise, output the actual value...which follows the "=". ** The "=" will always exist so we don't need to deal with the ** case where it is not found. */ result = wlancfg_getvalue(device, item, &mibget, skt, &req, value); if (result != 0) return(1); if (value[0] == '\0') printf("\n"); else printf("%s\n", strchr(value, '=')+1); } return(0);}/********************************************************************* wlancfg_show**** Query all the current writeable MIB's and output them. If the "all"** flag is set, then all MIB's (including read-only MIB's) are output.**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -