p80211types.c
来自「Linux的无线局域网方案是一个Linux设备驱动程序和子系统 一揽子方案的用」· C语言 代码 · 共 2,432 行 · 第 1/5 页
C
2,432 行
buf = textbuf + sprintf(textbuf, "%s=", meta->name); found = 0; for (i = meta->min; i <= meta->max; i++) if (array & (0x1 << i)) { found = 1; buf += sprintf(buf, "%lu,", (UINT32) i); } if (found != 0) *(buf-1) = '\0'; return;}/*----------------------------------------------------------------* p80211_fromtext_bitarray** %d,%d,%d,... ==> UINT32** Converts a C string containing the "<item name>=<value>,<value>,..." format* to a wlan data item triple. Bit numbers must be less than "maxlen".** The C string format is always "<item name>=<value>,<value>,<value>,...".** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf (out) item triple {DID, len, value}.* textbuf character buffer containing textual representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* itembuf.----------------------------------------------------------------*/void p80211_fromtext_bitarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; UINT32 array, value; item = (p80211itemd_t *) itembuf; meta = p80211_did2item(metalist, did); if (meta == NULL) { item->did = did; item->len = sizeof(int); item->status = P80211ENUM_msgitem_status_invalid_itemname; return; } /* ** Set the DID and OR in the partial DID for safety. */ item->did = did | meta->did; item->len = p80211item_maxdatalen(metalist, item->did); /* ** Skip past the item name to its value before converting. */ textbuf = strchr(textbuf, '='); if (textbuf == NULL) { *((UINT32 *) item->data) = 0; item->status = P80211ENUM_msgitem_status_missing_itemdata; return; } array = 0; while (textbuf != NULL) { /* OK, got the '=' or ',', bump to the next char */ textbuf++; if (textbuf[0] == '\0') break; if (sscanf(textbuf, "%lu", &value) != 1) { *((UINT32 *) item->data) = 0; item->status = P80211ENUM_msgitem_status_invalid_itemdata; return; } if (value < meta->min || value > meta->max) { *((UINT32 *) item->data) = 0; item->status = P80211ENUM_msgitem_status_invalid_itemdata; return; } array |= 0x1 << value; textbuf = strchr(textbuf, ','); } *((UINT32 *) item->data) = array; item->status = P80211ENUM_msgitem_status_data_ok; return;}/*----------------------------------------------------------------* p80211_isvalid_bitarray** Tests an item triple for valid range. Uses the validation* information in the metadata.** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.** Returns: * 0 - data in itembuf is invalid* ~0 - data in itembuf is valid----------------------------------------------------------------*/UINT32 p80211_isvalid_bitarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *meta; p80211itemd_t *item = (p80211itemd_t*)itembuf; UINT32 i, value, mask; if ( item->status == P80211ENUM_msgitem_status_data_ok ) { /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { mask = 0; for (i = meta->min; i <= meta->max; i++) mask |= 1 << i; value = *((UINT32 *)(item->data)); if ( value == (value & mask) ) { result = 1; } else { item->status = P80211ENUM_msgitem_status_invalid_itemdata; } } else { item->status = P80211ENUM_msgitem_status_invalid_did; } } return result;}/*----------------------------------------------------------------* p80211_totext_macarray** Converts an array of MAC addresses to a comma-separated list.** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.* textbuf (out) character buffer to receive textual* representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* textbuf.----------------------------------------------------------------*/void p80211_totext_macarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; p80211macarray_t *macarray; int i, cnt; char error_msg[MSG_BUFF_LEN]; *textbuf = '\0'; item = (p80211itemd_t *) itembuf; meta = p80211_did2item(metalist, did); if (meta == NULL) { p80211_error2text(P80211ENUM_msgitem_status_invalid_msg_did, error_msg); sprintf(textbuf, "0x%08lx=\"%s\"", did, error_msg); return; } if (item->status != P80211ENUM_msgitem_status_data_ok) { p80211_error2text(item->status, error_msg); sprintf(textbuf, "%s=\"%s\"", meta->name, error_msg); return; } if (item->did == 0UL) { sprintf(textbuf, "%s=%s", meta->name, NOT_SUPPORTED); return; } macarray = (p80211macarray_t *) item->data; cnt = sprintf(textbuf, "%s=", meta->name); for (i = 0; i < macarray->cnt; i++) cnt += sprintf(textbuf+cnt, (i==0) ? "%02x:%02x:%02x:%02x:%02x:%02x" : ",%02x:%02x:%02x:%02x:%02x:%02x", (UINT) macarray->data[i][0], (UINT) macarray->data[i][1], (UINT) macarray->data[i][2], (UINT) macarray->data[i][3], (UINT) macarray->data[i][4], (UINT) macarray->data[i][5]); return;}/*----------------------------------------------------------------* p80211_fromtext_macarray** Converts a C string containing the "<item name>=<value>,<value>,..." format* to a wlan data item triple.** The C string format is always "<item name>=<value>,<value>,<value>,...".** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf (out) item triple {DID, len, value}.* textbuf character buffer containing textual representation.** Returns: * nothing** Side effects:* Writes the converted value to the buffer pointed at by* itembuf.----------------------------------------------------------------*/void p80211_fromtext_macarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf, char *textbuf ){ p80211meta_t *meta; p80211itemd_t *item; p80211macarray_t *macarray; int cnt, x1, x2, x3, x4, x5, x6; item = (p80211itemd_t *) itembuf; meta = p80211_did2item(metalist, did); if (meta == NULL) { item->did = did; item->len = sizeof(int); item->status = P80211ENUM_msgitem_status_invalid_itemname; return; } /* ** Set the DID and OR in the partial DID for safety. */ item->did = did | meta->did; item->len = p80211item_maxdatalen(metalist, item->did); /* ** Skip past the item name to its value before converting. */ macarray = (p80211macarray_t *) item->data; macarray->cnt = 0; textbuf = strchr(textbuf, '='); if (textbuf == NULL) { item->status = P80211ENUM_msgitem_status_missing_itemdata; return; } cnt = 0; while (textbuf != NULL) { /* OK, got the '=' or ',', bump to the next char */ textbuf++; if (textbuf[0] == '\0') break; if (cnt >= meta->maxlen) { item->status = P80211ENUM_msgitem_status_invalid_itemdata; return; } if (sscanf(textbuf, "%x:%x:%x:%x:%x:%x", &x1, &x2, &x3, &x4, &x5, &x6) != 6) { item->status = P80211ENUM_msgitem_status_invalid_itemdata; return; } macarray->data[cnt][0] = (UINT8) x1; macarray->data[cnt][1] = (UINT8) x2; macarray->data[cnt][2] = (UINT8) x3; macarray->data[cnt][3] = (UINT8) x4; macarray->data[cnt][4] = (UINT8) x5; macarray->data[cnt][5] = (UINT8) x6; cnt++; textbuf = strchr(textbuf, ','); } macarray->cnt = cnt; item->status = P80211ENUM_msgitem_status_data_ok; return;}/*----------------------------------------------------------------* p80211_isvalid_macarray** Tests an item triple for valid range. Uses the validation* information in the metadata. All values are valid, so this * function always returns success.** Arguments:* metalist pointer to a category metadata list* did complete, validated, DID.* itembuf item triple {DID, len, value}.** Returns: * 0 - data in itembuf is invalid* ~0 - data in itembuf is valid----------------------------------------------------------------*/UINT32 p80211_isvalid_macarray( catlistitem_t *metalist, UINT32 did, UINT8 *itembuf ){ UINT32 result = 0; p80211meta_t *meta; p80211itemd_t *item = (p80211itemd_t*)itembuf; if ( item->status == P80211ENUM_msgitem_status_data_ok ) { /* collect the metadata item */ if ( (meta = p80211_did2item(metalist, did)) != NULL ) { /* since integers aren't bounded, there's nothing to check */ result = 1; } else { item->status = P80211ENUM_msgitem_status_invalid_did; } } return result;}/*----------------------------------------------------------------* p80211_error2text** This function converts an error code into an appropriate error* string.** Arguments:* err_code error code reflecting index into * the error enumerated list.* err_str (out) will contain the appropriate* error string.** Returns: * Nothing----------------------------------------------------------------*/void p80211_error2text( int err_code, char *err_str ){ p80211enum_int2text(&MKENUMNAME(msgitem_status), err_code, err_str);}/*--------------------------------------------------------------------*//* Item enumerations *//* The following arrays list the numbers and names for each of the *//* enumerations present in the 802.11 MIB and MLME. */MKENUMPAIRLIST(truth){ MKENUMPAIR( 0, "false" ), MKENUMPAIR( 1, "true")};MKENUM(truth);MKENUMPAIRLIST(ifstate){ MKENUMPAIR( 0, "disable" ), MKENUMPAIR( 1, "fwload"), MKENUMPAIR( 2, "enable")};MKENUM(ifstate);MKENUMPAIRLIST(powermgmt){ MKENUMPAIR( 1, "active" ), MKENUMPAIR( 2, "powersave" )};MKENUM(powermgmt);MKENUMPAIRLIST(bsstype){ MKENUMPAIR( 1, "infrastructure" ), MKENUMPAIR( 2, "independent" ), MKENUMPAIR( 3, "any" )};MKENUM(bsstype);MKENUMPAIRLIST(authalg){ MKENUMPAIR( 1, "opensystem" ), MKENUMPAIR( 2, "sharedkey" ), MKENUMPAIR( 3, "not_set" )};MKENUM(authalg);MKENUMPAIRLIST(phytype){ MKENUMPAIR( 1, "fhss" ), MKENUMPAIR( 2, "dsss" ), MKENUMPAIR( 3, "irbaseband" )};MKENUM(phytype);MKENUMPAIRLIST(temptype){ MKENUMPAIR( 1, "commercial" ), MKENUMPAIR( 2, "industrial" )};MKENUM(temptype);MKENUMPAIRLIST(regdomain){ MKENUMPAIR( 0x10, "fcc" ), MKENUMPAIR( 0x20, "doc" ), MKENUMPAIR( 0x30, "etsi" ), MKENUMPAIR( 0x31, "spain" ), MKENUMPAIR( 0x32, "france" ), MKENUMPAIR( 0x40, "mkk" )};MKENUM(regdomain);MKENUMPAIRLIST(ccamode){ MKENUMPAIR( 0x01, "edonly" ), MKENUMPAIR( 0x02, "csonly" ), MKENUMPAIR( 0x04, "edandcs" ), MKENUMPAIR( 0x08, "cswithtimer" ), MKENUMPAIR( 0x0f, "hrcsanded" )};MKENUM(ccamode);MKENUMPAIRLIST(diversity){ MKENUMPAIR( 1, "fixedlist" ), MKENUMPAIR( 2, "notsupported" ), MKENUMPAIR( 3, "dynamic" )};MKENUM(diversity);MKENUMPAIRLIST(scantype){ MKENUMPAIR( 1, "active" ), MKENUMPAIR( 2, "passive" ),};MKENUM(scantype);MKENUMPAIRLIST(resultcode){ MKENUMPAIR( P80211ENUM_resultcode_success, "success" ), MKENUMPAIR( P80211ENUM_resultcode_invalid_parameters, "invalid_parameters" ), MKENUMPAIR( P80211ENUM_resultcode_not_supported, "not_supported" ), MKENUMPAIR( P80211ENUM_resultcode_timeout, "timeout" ), MKENUMPAIR( P80211ENUM_resultcode_too_many_req, "too_many_req" ), MKENUMPAIR( P80211ENUM_resultcode_refused, "refused" ), MKENUMPAIR( P80211ENUM_resultcode_bss_already, "bss_already" ), MKENUMPAIR( P80211ENUM_resultcode_invalid_access, "invalid_access" ), MKENUMPAIR( P80211ENUM_resultcode_invalid_mibattribute, "invalid_mibattribute" ), MKENUMPAIR( P80211ENUM_resultcode_cant_set_readonly_mib, "cant_set_readonly_mib" ), MKENUMPAIR( P80211ENUM_resultcode_implementation_failure, "implementation_failure" ), MKENUMPAIR( P80211ENUM_resultcode_cant_get_writeonly_mib, "cant_get_writeonl
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?