2015-04-04 23:50:18 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap 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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-03-31 19:54:13 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 22:23:00 +01:00
|
|
|
#include "cw.h"
|
2015-03-31 19:26:25 +02:00
|
|
|
#include "capwap_items.h"
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
#include "mbag.h"
|
2015-03-31 19:54:13 +02:00
|
|
|
|
|
|
|
#include "cw_util.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-03-31 19:54:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
static void readsubelems_wtp_board_data(mbag_t itemstore, uint8_t * msgelem,
|
2015-04-12 23:28:55 +02:00
|
|
|
int len)
|
2015-03-31 19:54:13 +02:00
|
|
|
{
|
2015-04-18 11:20:24 +02:00
|
|
|
if (len<4)
|
|
|
|
return;
|
2015-03-31 19:26:25 +02:00
|
|
|
|
|
|
|
int i = 0;
|
2016-03-13 18:50:56 +01:00
|
|
|
// uint32_t val;
|
2015-03-31 19:54:13 +02:00
|
|
|
do {
|
2016-03-13 18:50:56 +01:00
|
|
|
// val = ntohl(*((uint32_t *) (msgelem + i)));
|
|
|
|
// int subtype = (val >> 16) & 0xffff;
|
|
|
|
// int sublen = val & 0xffff;
|
|
|
|
//
|
|
|
|
int subtype = cw_get_word(msgelem+i);
|
|
|
|
int sublen = cw_get_word(msgelem+i+2);
|
2015-03-31 19:26:25 +02:00
|
|
|
i += 4;
|
|
|
|
if (sublen + i > len) {
|
2015-04-12 23:28:55 +02:00
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"WTP Board data sub-element too long, type=%d,len=%d",
|
2015-03-31 19:26:25 +02:00
|
|
|
subtype, sublen);
|
2015-03-31 19:54:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-13 18:50:56 +01:00
|
|
|
cw_dbg(DBG_SUBELEM, "board data sub-element, type=%d (%s), len=%d",
|
|
|
|
subtype, cw_strboardelem(subtype),sublen);
|
|
|
|
|
|
|
|
cw_dbg_dmp(DBG_SUBELEM,msgelem+i,sublen,"Dump...");
|
2015-03-31 19:26:25 +02:00
|
|
|
|
|
|
|
switch (subtype) {
|
2015-04-07 07:42:36 +02:00
|
|
|
case CW_BOARDDATA_MODELNO:
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_bstrn(itemstore,
|
2015-04-12 23:28:55 +02:00
|
|
|
CW_ITEM_WTP_BOARD_MODELNO,
|
2015-03-31 19:26:25 +02:00
|
|
|
msgelem + i, sublen);
|
2015-03-31 19:54:13 +02:00
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
case CW_BOARDDATA_SERIALNO:
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_bstrn(itemstore,
|
2015-04-12 23:28:55 +02:00
|
|
|
CW_ITEM_WTP_BOARD_SERIALNO,
|
2015-03-31 19:26:25 +02:00
|
|
|
msgelem + i, sublen);
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-03-31 19:54:13 +02:00
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
case CW_BOARDDATA_MACADDRESS:
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_bstrn(itemstore,
|
2015-04-12 23:28:55 +02:00
|
|
|
CW_ITEM_WTP_BOARD_MACADDRESS,
|
2015-03-31 19:26:25 +02:00
|
|
|
msgelem + i, sublen);
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-03-31 19:54:13 +02:00
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
case CW_BOARDDATA_BOARDID:
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID,
|
2015-03-31 19:26:25 +02:00
|
|
|
msgelem + i, sublen);
|
2015-03-31 19:54:13 +02:00
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
case CW_BOARDDATA_REVISION:
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_set_bstrn(itemstore,
|
2015-04-12 23:28:55 +02:00
|
|
|
CW_ITEM_WTP_BOARD_REVISION,
|
2015-03-31 19:26:25 +02:00
|
|
|
msgelem + i, sublen);
|
2015-03-31 19:54:13 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-03-31 19:26:25 +02:00
|
|
|
i += sublen;
|
2015-03-31 19:54:13 +02:00
|
|
|
|
2015-03-31 19:26:25 +02:00
|
|
|
} while (i < len);
|
2015-03-31 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-31 20:06:37 +02:00
|
|
|
/**
|
2015-04-04 23:50:18 +02:00
|
|
|
* Parse a WTP Board Data messag element and put results to itemstore.
|
2015-04-12 23:28:55 +02:00
|
|
|
*/
|
|
|
|
int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
|
|
|
int len, struct sockaddr *from)
|
2015-03-31 19:54:13 +02:00
|
|
|
{
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-03-31 19:26:25 +02:00
|
|
|
if (len < 4) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
2015-04-12 23:28:55 +02:00
|
|
|
"Discarding WTP_BOARD_DATA msgelem, wrong size, type=%d, len=%d",
|
|
|
|
a->elem_id, len);
|
2015-04-12 19:19:29 +02:00
|
|
|
return 0;
|
2015-03-31 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_t itemstore = conn->incomming;
|
|
|
|
mbag_set_dword(itemstore, CW_ITEM_WTP_BOARD_VENDOR, cw_get_dword(data));
|
2015-03-31 19:26:25 +02:00
|
|
|
|
2015-04-12 23:28:55 +02:00
|
|
|
readsubelems_wtp_board_data(itemstore, data + 4, len - 4);
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-03-31 19:54:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|