2016-02-26 18:55:40 +01: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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2018-03-06 03:08:14 +01:00
|
|
|
#include "mod_capwap.h"
|
2016-02-26 18:55:40 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dbg.h"
|
2018-03-06 03:08:14 +01:00
|
|
|
#include "cw/cw.h"
|
2016-02-26 18:55:40 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "cw/ktv.h"
|
2018-03-11 00:56:41 +01:00
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
#include "cw/keys.h"
|
2016-02-26 18:55:40 +01:00
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
|
|
|
|
static void readsubelems_wtp_board_data(mavl_t cfg, uint8_t * msgelem,
|
2016-02-26 18:55:40 +01:00
|
|
|
int len)
|
|
|
|
{
|
2018-03-09 07:44:17 +01:00
|
|
|
int i = 0;
|
|
|
|
uint32_t val;
|
|
|
|
const char * key;
|
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
if (len<4)
|
|
|
|
return;
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
do {
|
2018-03-17 12:32:40 +01:00
|
|
|
int subtype;
|
|
|
|
int sublen;
|
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
val = ntohl(*((uint32_t *) (msgelem + i)));
|
2018-03-17 12:32:40 +01:00
|
|
|
subtype = (val >> 16) & 0xffff;
|
|
|
|
sublen = val & 0xffff;
|
2016-02-26 18:55:40 +01:00
|
|
|
i += 4;
|
|
|
|
if (sublen + i > len) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"WTP Board data sub-element too long, type=%d,len=%d",
|
|
|
|
subtype, sublen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-19 17:26:01 +01:00
|
|
|
cw_dbg(DBG_SUBELEM, "WTP board data sub-element, type=%d, len=%d",
|
2016-02-26 18:55:40 +01:00
|
|
|
subtype, sublen);
|
|
|
|
|
|
|
|
switch (subtype) {
|
2018-03-09 07:44:17 +01:00
|
|
|
|
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
case CW_BOARDDATA_MODELNO:
|
2018-03-09 07:44:17 +01:00
|
|
|
/* mbag_set_bstrn(itemstore,
|
2016-02-26 18:55:40 +01:00
|
|
|
CW_ITEM_WTP_BOARD_MODELNO,
|
|
|
|
msgelem + i, sublen);
|
2018-03-09 07:44:17 +01:00
|
|
|
*/
|
|
|
|
key = "model_no";
|
2016-02-26 18:55:40 +01:00
|
|
|
break;
|
|
|
|
case CW_BOARDDATA_SERIALNO:
|
2018-03-09 07:44:17 +01:00
|
|
|
/* mbag_set_bstrn(itemstore,
|
2016-02-26 18:55:40 +01:00
|
|
|
CW_ITEM_WTP_BOARD_SERIALNO,
|
|
|
|
msgelem + i, sublen);
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
*/
|
|
|
|
key = "serial_no";
|
2016-02-26 18:55:40 +01:00
|
|
|
break;
|
|
|
|
case CW_BOARDDATA_MACADDRESS:
|
2018-03-09 07:44:17 +01:00
|
|
|
/* mbag_set_bstrn(itemstore,
|
2016-02-26 18:55:40 +01:00
|
|
|
CW_ITEM_WTP_BOARD_MACADDRESS,
|
|
|
|
msgelem + i, sublen);
|
2018-03-09 07:44:17 +01:00
|
|
|
*/
|
|
|
|
key = "mac_address";
|
2016-02-26 18:55:40 +01:00
|
|
|
break;
|
|
|
|
case CW_BOARDDATA_BOARDID:
|
2018-03-09 07:44:17 +01:00
|
|
|
/* mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID,
|
2016-02-26 18:55:40 +01:00
|
|
|
msgelem + i, sublen);
|
2018-03-09 07:44:17 +01:00
|
|
|
*/
|
|
|
|
key = "board_id";
|
2016-02-26 18:55:40 +01:00
|
|
|
break;
|
|
|
|
case CW_BOARDDATA_REVISION:
|
2018-03-09 07:44:17 +01:00
|
|
|
/* mbag_set_bstrn(itemstore,
|
2016-02-26 18:55:40 +01:00
|
|
|
CW_ITEM_WTP_BOARD_REVISION,
|
|
|
|
msgelem + i, sublen);
|
2018-03-09 07:44:17 +01:00
|
|
|
*/
|
|
|
|
key = "revision";
|
2016-02-26 18:55:40 +01:00
|
|
|
default:
|
2018-03-09 07:44:17 +01:00
|
|
|
key = NULL;
|
2016-02-26 18:55:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-03-17 12:32:40 +01:00
|
|
|
if (key != NULL){
|
2018-03-09 07:44:17 +01:00
|
|
|
char add_key[256];
|
2018-04-07 19:28:22 +02:00
|
|
|
sprintf(add_key,"wtp-board-data/%s",key);
|
2018-04-25 10:43:27 +02:00
|
|
|
cw_ktv_add(cfg,add_key,CW_TYPE_BSTR16,NULL,msgelem+i,sublen);
|
2018-03-09 07:44:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
i += sublen;
|
|
|
|
|
|
|
|
} while (i < len);
|
|
|
|
}
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a WTP Board Data messag element and put results to itemstore.
|
|
|
|
*/
|
2018-03-09 07:44:17 +01:00
|
|
|
int capwap_in_wtp_board_data(struct cw_ElemHandler *eh, struct cw_ElemHandlerParams *params,
|
|
|
|
uint8_t * data, int len)
|
2016-02-26 18:55:40 +01:00
|
|
|
{
|
|
|
|
|
2018-03-06 03:08:14 +01:00
|
|
|
/*
|
2016-02-26 18:55:40 +01:00
|
|
|
if (len < 4) {
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"Discarding WTP_BOARD_DATA msgelem, wrong size, type=%d, len=%d",
|
|
|
|
a->elem_id, len);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-06 03:08:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
char vendor_key[128];
|
|
|
|
mavl_t cfg = params->conn->remote_cfg;
|
|
|
|
|
|
|
|
|
2018-03-15 20:07:17 +01:00
|
|
|
sprintf(vendor_key,"%s/%s",eh->key,CW_SKEY_VENDOR);
|
2018-03-09 07:44:17 +01:00
|
|
|
|
2018-04-25 10:43:27 +02:00
|
|
|
cw_ktv_add(cfg,vendor_key,CW_TYPE_DWORD,NULL,data,len);
|
2016-02-26 18:55:40 +01:00
|
|
|
|
2018-03-06 03:08:14 +01:00
|
|
|
/*
|
2016-02-26 18:55:40 +01:00
|
|
|
mbag_t itemstore = conn->incomming;
|
|
|
|
mbag_set_dword(itemstore, CW_ITEM_WTP_BOARD_VENDOR, cw_get_dword(data));
|
2018-03-06 03:08:14 +01:00
|
|
|
*/
|
2016-02-26 18:55:40 +01:00
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
readsubelems_wtp_board_data(cfg, data + 4, len - 4);
|
|
|
|
|
2016-02-26 18:55:40 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|