⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wlancfg.c

📁 对于无线网卡采用prism芯片的linux的开源驱动.
💻 C
📖 第 1 页 / 共 3 页
字号:
        (P80211ITEM_ISREQUEST(arglist[2].flags)))        {        fprintf(stderr, "wlancfg: RESULTCODE argument is required.\n");        return(1);        }    /*    ** Set the message length.  This should correspond to the "resultcode"    ** argument.  However, make the check general just in case the arguments    ** were not defined as expected.    */    spec->msglen = sizeof(p80211msg_t) + sizeof(p80211item_t);    if (spec->resoff > spec->attoff)        spec->msglen += spec->resoff + spec->reslen;    else        spec->msglen += spec->attoff + spec->attlen;    return(0);}/********************************************************************* wlancfg_getvalue****    Get the value of the specified MIB.  The value is returned as** a name/value pair in the following syntax:****      name=value**** If the MIB is unsupported, then a 0-length string is returned.**** Returns:    0 - Success.**             1 - Failure.*/static int wlancfg_getvalue(char               *device,    /* I:   Device name. */p80211meta_t       *item,      /* I:   Pointer to MIB item. */req_spec_t         *mibget,    /* I:   "dot11req_mibget" request spec. */int                skt,        /* I:   ioctl() socket. */p80211ioctl_req_t  *req,       /* I:   ioctl() request structure. */char               *value)     /* O:   MIB value. */{    int           result;    p80211msgd_t  *msg;    /*    ** Build the "dot11req_mibget" message.    */    msg = (p80211msgd_t *) (req->data);    result = wlancfg_build(device, mibget, item->name, msg);    if (result != 0) return(1);    /*    ** Set up the ioctl request.    */    req->len    = msg->msglen;    req->result = 0;    result = ioctl(skt, P80211_IFREQ, req);    if (result == -1)        {        perror("wlancfg");        return(1);        }    /*    ** Convert the MIB value to a string.    */    wlancfg_totext(item, mibget, msg, value);    return(0);}/********************************************************************* wlancfg_setvalue****    Set the value of the specified MIB.  The MIB must be specified as** a name/value pair in the following syntax:****      name=value**** Returns:    0 - Success.**             1 - Failure.*/static int wlancfg_setvalue(char               *device,    /* I:   Device name. */req_spec_t         *mibset,    /* I:   "dot11req_mibset" request spec. */int                skt,        /* I:   ioctl() socket. */p80211ioctl_req_t  *req,       /* I:   ioctl() request structure. */char               *value)     /* I:   MIB name/value. */{    int            result;    p80211msgd_t   *msg;    p80211itemd_t  *itmhdr;    UINT8          tmpitem[MSG_BUFF_LEN];    UINT32         resultcode;    /*    ** Build the "dot11req_mibset" message.    */    msg = (p80211msgd_t *) (req->data);    result = wlancfg_build(device, mibset, value, msg);    if (result != 0) return(1);    /*    ** Set up the ioctl request.    */    req->len    = msg->msglen;    req->result = 0;    result = ioctl(skt, P80211_IFREQ, req);    if (result == -1)        {        perror("wlancfg");        return(1);        }    /*    ** Get the result code and make sure that it has a value.    */    itmhdr = (p80211itemd_t *) (msg->args + mibset->resoff);    if (itmhdr->status != P80211ENUM_msgitem_status_data_ok)        {        p80211_error2text(itmhdr->status, tmpitem);        fprintf(stderr, "wlancfg: %s resultcode=%s\n", value, tmpitem);        return(1);        }    /*    ** Make sure that the request worked.    */    resultcode = *((UINT32 *) (itmhdr->data));    if (resultcode != P80211ENUM_resultcode_success)        {        p80211_error2text(resultcode, tmpitem);        fprintf(stderr, "wlancfg: %s=%s\n", value, tmpitem);        return(1);        }    return(0);}/********************************************************************* wlancfg_build****    Build the request message buffer for either "dot11req_mibget"** or "dot11req_mibset".  For "dot11req_mibget", "value" should be the** name of the MIB.  For "dot11req_mibset", "value" should be the** MIB name/value pair (i.e. name=value).**** Returns:    0 - Success.**             1 - Failure.*/static int wlancfg_build(char          *device,    /* I:   Device name. */req_spec_t    *spec,      /* I:   Request specification. */char          *value,     /* I:   "mibattribute" argument value. */p80211msgd_t  *msg)       /* O:   Message buffer. */{    p80211meta_t   *arg;    char           tmpstr[MSG_BUFF_LEN];    p80211itemd_t  *itmhdr;    /*    ** Initialize the message buffer.    */    msg->msgcode = spec->msgcode;    msg->msglen  = spec->msglen;    strncpy(msg->devname, device, WLAN_DEVNAMELEN_MAX - 1);    /*    ** Add the "mibattribute" argument to the request buffer.  Note that    ** the "fromtextptr" conversion function looks for an "=" so we will    ** need to create a value string that will keep it happy.  Actually,    ** what is expected is "mibattribute=....." but only the "=" is    ** necessary.    */    arg    = spec->attptr;    itmhdr = (p80211itemd_t *) (msg->args + spec->attoff);    tmpstr[0] = '=';    strcpy(tmpstr+1, value);    memset(itmhdr, 0, sizeof(p80211item_t) + spec->attlen);    (*(arg->fromtextptr))(msg_catlist, spec->attdid, (UINT8 *) itmhdr, tmpstr);    if (itmhdr->status != (UINT16) P80211ENUM_msgitem_status_data_ok)        {        p80211_error2text(itmhdr->status, tmpstr);        fprintf(stderr, "wlancfg: %s=%s\n", value, tmpstr);        return(1);        }    /*    ** Set the "resultcode" argument to "no value".    */    itmhdr = (p80211itemd_t *) (msg->args + spec->resoff);    itmhdr->did    = spec->resdid;    itmhdr->status = (UINT16) P80211ENUM_msgitem_status_no_value;    itmhdr->len    = (UINT16) (spec->reslen);    memset(itmhdr->data, 0, spec->reslen);    return(0);}/********************************************************************* wlancfg_totext****    Convert the MIB to a string.  The value is returned as a name/value** pair in the following syntax:****      name=value**** If the MIB cannot be converted for any reason, then a 0-length string is** returned.*/static void wlancfg_totext(p80211meta_t   *item,      /* I:   Pointer to MIB item. */req_spec_t     *mibget,    /* I:   "dot11req_mibget" request specification. */p80211msgd_t   *msg,       /* I:   Message buffer. */char           *value)     /* O:   Value string. */{    p80211itemd_t  *itmhdr;    UINT8          tmpitem[MSG_BUFF_LEN];    UINT32         resultcode;    p80211meta_t   *arg;    char           *eq;    /*    ** Initialize the string to a 0-length string just in case there    ** is an error.    */    value[0] = '\0';    /*    ** Get the result code and make sure that it has a value.    */    itmhdr = (p80211itemd_t *) (msg->args + mibget->resoff);    if (itmhdr->status != P80211ENUM_msgitem_status_data_ok)        {        p80211_error2text(itmhdr->status, tmpitem);        fprintf(stderr, "wlancfg: %s resultcode=%s\n", item->name, tmpitem);        return;        }    /*    ** If the result code is "not supported", then return the empty string    ** with no error.  Otherwise, there is an error.    */    resultcode = *((UINT32 *) (itmhdr->data));    if (resultcode != P80211ENUM_resultcode_success)        {        if (resultcode != P80211ENUM_resultcode_not_supported)            {            p80211_error2text(resultcode, tmpitem);            fprintf(stderr, "wlancfg: %s=%s\n", item->name, tmpitem);            }        return;        }    /*    ** Get the MIB value and make sure that it has a value.    */    arg = mibget->attptr;    itmhdr = (p80211itemd_t *) (msg->args + mibget->attoff);    if (itmhdr->status != P80211ENUM_msgitem_status_data_ok)        {        p80211_error2text(itmhdr->status, tmpitem);        fprintf(stderr, "wlancfg: %s mibattribute=%s\n", item->name, tmpitem);        return;        }    /*    ** Convert the MIB to a string.  This will have the form:    **    **     mibattribute=name=value    **    ** Extract everthing after the first '='.  Something went wrong if    ** there is no "="...just return the empty string.  Also, in some    ** cases where the value does not exist, "totextptr" appears to    ** neglect to add the "=" after the MIB name.  If this happens, then    ** add the "=" ourselves.    */    (*(arg->totextptr))(msg_catlist, mibget->attdid, (UINT8 *) itmhdr, tmpitem);    eq = strchr(tmpitem, '=');    if (eq != NULL)        {        strcpy(value, eq+1);        if (strchr(value, '=') == NULL) strcat(value, "=");        }    return;}/********************************************************************* wlancfg_getreq****    Find a request and verify its arguments.**** Returns:    0 - Success.**             1 - Failure.*/static int wlancfg_getreq(char           *cat,       /* I:   Request catagory. */char           *name,      /* I:   Request name. */int            argcnt,     /* I:   Expected number of arguments. */UINT32         *msgcode,   /* O:   Message code for request. */p80211meta_t   **arglist)  /* O:   Pointer to argument list. */{    grplistitem_t  *grp;    /*    ** Find the request message code.    */    *msgcode = p80211_text2did(msg_catlist, cat, name, NULL);    if (*msgcode == P80211DID_INVALID)        {        fprintf(stderr, "wlancfg: Could not find \"%s\" request.\n", name);        return(1);        }    /*    ** Find find the argument metadata list for the request.    */    grp = p80211_did2grp(msg_catlist, *msgcode);    if (grp == NULL)        {        fprintf(stderr, "wlancfg: Could not find \"%s\" arguments.\n", name);        return(1);        }    *arglist = grp->itemlist;    /*    ** Make sure that the number of arguments is correct.  Note that the list    ** size is 1 more than the argument count!    */    if (GETMETASIZE(*arglist) != argcnt+1)        {        fprintf(stderr, "wlancfg: \"%s\" argument count is wrong.\n", name);        return(1);        }    return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -