actube/src/cw/cw_read_descriptor_subelems.c

101 lines
2.3 KiB
C
Raw Normal View History

/*
This file is part of actube.
actube is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cw.h"
2022-07-31 17:15:32 +02:00
#include "val.h"
#include "dbg.h"
#include "keys.h"
2022-08-22 01:59:23 +02:00
int cw_read_descriptor_subelems(cw_Cfg_t *cfg, const char *parent_key,
uint8_t * data, int len,
struct cw_DescriptorSubelemDef *elems)
{
uint32_t vendor_id;
2022-08-09 22:35:47 +02:00
int sublen, subtype;
int errors = 0;
int success = 0;
int sub = 0;
while (sub < len) {
int i;
2022-08-09 22:35:47 +02:00
if (len - sub < 8) {
return 0;
}
vendor_id = cw_get_dword(data + sub);
sublen = cw_get_word(data + sub + 6);
subtype = cw_get_word(data + sub + 4);
/* search sub-element */
for (i = 0; elems[i].maxlen; i++) {
2022-08-09 22:35:47 +02:00
if (elems[i].type == subtype)
break;
}
2022-08-09 22:35:47 +02:00
if (!elems[i].maxlen) {
2022-08-09 22:35:47 +02:00
/* cw_dbg_version_subelem(DBG_ELEM_ERR,
"Can't handle sub-elem, vendor or type unknown",
subtype, vendor_id,
data + sub + 8, sublen);*/
errors++;
} else {
int l = sublen;
char dbgstr[1048];
char key[1024];
2022-08-09 22:35:47 +02:00
if (elems[i].maxlen < sublen) {
cw_dbg(DBG_ELEM_ERR,
"SubType %d Too long (truncating), len = %d,max. len=%d",
subtype, sublen, elems[i].maxlen);
l = elems[i].maxlen;
}
/* vendor */
2022-08-09 22:35:47 +02:00
sprintf(key, "%s/%s/%s", parent_key, elems[i].key,
CW_SKEY_VENDOR);
cw_cfg_set_int(cfg, key, vendor_id);
/* version */
2022-08-09 22:35:47 +02:00
sprintf(key, "%s/%s/%s", parent_key, elems[i].key,
CW_SKEY_VERSION);
CW_TYPE_BSTR16->read(cfg,key,data+sub+8,l,NULL);
sprintf(dbgstr, "%s", key);
2022-08-09 22:35:47 +02:00
/* cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype,
vendor_id, data + sub + 8, l);*/
success++;
}
if (sub + sublen > len)
return -1;
sub += sublen + 8;
}
return success;
}