2016-03-15 00:33:17 +01:00
|
|
|
/*
|
|
|
|
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"
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "ktv.h"
|
2016-03-15 00:33:17 +01:00
|
|
|
#include "dbg.h"
|
2018-03-07 08:57:04 +01:00
|
|
|
#include "keys.h"
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2016-03-15 00:33:17 +01:00
|
|
|
|
2018-03-07 08:57:04 +01:00
|
|
|
int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
|
|
|
|
uint8_t * data, int len,
|
2018-03-06 03:08:14 +01:00
|
|
|
struct cw_DescriptorSubelemDef *elems)
|
2016-03-15 00:33:17 +01:00
|
|
|
{
|
2018-03-07 08:57:04 +01:00
|
|
|
uint32_t vendor_id;
|
|
|
|
int sublen,subtype;
|
2016-03-15 00:33:17 +01:00
|
|
|
int errors = 0;
|
|
|
|
int success = 0;
|
|
|
|
int sub = 0;
|
|
|
|
while (sub < len) {
|
2018-03-07 08:57:04 +01:00
|
|
|
int i;
|
|
|
|
|
2016-03-15 00:33:17 +01:00
|
|
|
if (len - sub < 8) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-07 08:57:04 +01:00
|
|
|
vendor_id = cw_get_dword(data + sub);
|
|
|
|
sublen = cw_get_word(data + sub + 6);
|
|
|
|
subtype = cw_get_word(data + sub + 4);
|
2016-03-15 00:33:17 +01:00
|
|
|
|
2018-03-06 03:08:14 +01:00
|
|
|
|
|
|
|
/* search sub-element */
|
2016-03-15 00:33:17 +01:00
|
|
|
for (i = 0; elems[i].maxlen; i++) {
|
2018-03-25 08:34:32 +02:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
if (elems[i].type == subtype /* && elems[i].vendor_id==vendor_id*/)
|
2016-03-15 00:33:17 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-03-06 03:08:14 +01:00
|
|
|
|
|
|
|
|
2016-03-15 00:33:17 +01:00
|
|
|
if (!elems[i].maxlen) {
|
2018-03-17 12:32:40 +01:00
|
|
|
cw_dbg_version_subelem(DBG_ELEM_ERR, "Can't handle sub-elem, vendor or type unknown",
|
2018-03-07 08:57:04 +01:00
|
|
|
subtype, vendor_id, data+sub+8, sublen);
|
2016-03-15 00:33:17 +01:00
|
|
|
errors++;
|
|
|
|
} else {
|
|
|
|
int l = sublen;
|
2018-03-07 10:30:40 +01:00
|
|
|
|
2018-03-07 08:57:04 +01:00
|
|
|
char dbgstr[1048];
|
|
|
|
char key[1024];
|
|
|
|
|
2016-03-15 00:33:17 +01: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-07 08:57:04 +01:00
|
|
|
/* vendor */
|
2018-03-15 20:07:17 +01:00
|
|
|
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_SKEY_VENDOR);
|
2018-03-12 11:22:06 +01:00
|
|
|
cw_ktv_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
|
2018-03-07 10:30:40 +01:00
|
|
|
|
2018-03-07 08:57:04 +01:00
|
|
|
/* version */
|
2018-03-15 20:07:17 +01:00
|
|
|
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_SKEY_VERSION);
|
2018-03-12 11:22:06 +01:00
|
|
|
cw_ktv_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
|
2018-03-07 10:30:40 +01:00
|
|
|
|
|
|
|
sprintf(dbgstr, "%s", key);
|
2018-03-07 08:57:04 +01:00
|
|
|
cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype, vendor_id, data+sub+8,l);
|
2016-03-15 00:33:17 +01:00
|
|
|
success++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sub + sublen > len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
sub += sublen + 8;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|