2015-04-05 02:10:37 +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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "capwap.h"
|
|
|
|
#include "capwap_items.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "cw_util.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
#include "sock.h"
|
2015-04-05 02:10:37 +02:00
|
|
|
|
|
|
|
|
2016-03-04 21:01:38 +01:00
|
|
|
static int _cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data,
|
2015-04-13 11:00:46 +02:00
|
|
|
int len, int silent)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2015-04-13 11:00:46 +02:00
|
|
|
int i = 0;
|
2015-04-18 11:20:24 +02:00
|
|
|
while (i<len) {
|
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
if (i + 8 > len) {
|
2015-04-13 11:00:46 +02:00
|
|
|
if (!silent)
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"WTP descriptor subelement to long, length=%d>%d",
|
|
|
|
i + 8, len);
|
2015-04-12 19:19:29 +02:00
|
|
|
return 0;
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
uint32_t vendor_id = cw_get_dword(data + i);
|
2015-04-12 19:19:29 +02:00
|
|
|
uint32_t val = cw_get_dword(data + i + 4);
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
int subtype = (val >> 16) & 0xffff;
|
|
|
|
int sublen = val & 0xffff;
|
|
|
|
i += 8;
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
if (sublen + i > len) {
|
2015-04-13 11:00:46 +02:00
|
|
|
if (!silent)
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
2015-04-18 11:20:24 +02:00
|
|
|
"WTP Descriptor sub-element too long, length = %d",
|
2015-04-13 11:00:46 +02:00
|
|
|
sublen);
|
2015-04-12 19:19:29 +02:00
|
|
|
return 0;
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
if (!silent) {
|
|
|
|
char *dmp;
|
|
|
|
char *dmpmem = NULL;
|
|
|
|
if (cw_dbg_is_level(DBG_SUBELEM_DMP)) {
|
|
|
|
dmpmem = cw_dbg_mkdmp(data + i, sublen);
|
|
|
|
dmp = dmpmem;
|
|
|
|
} else
|
|
|
|
dmp = "";
|
|
|
|
cw_dbg(DBG_SUBELEM, "WTP Descriptor subtype=%d,len=%d%s", subtype,
|
|
|
|
sublen, dmp);
|
|
|
|
|
|
|
|
if (dmpmem)
|
|
|
|
free(dmpmem);
|
2015-04-12 23:28:55 +02:00
|
|
|
}
|
2015-04-12 19:19:29 +02:00
|
|
|
|
|
|
|
switch (subtype) {
|
2015-04-05 02:10:37 +02:00
|
|
|
case CW_SUBELEM_WTP_HARDWARE_VERSION:
|
2015-05-01 00:16:54 +02:00
|
|
|
/*
|
|
|
|
mbag_set_dword(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_HARDWARE_VENDOR,
|
|
|
|
vendor_id);
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_bstrn(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_HARDWARE_VERSION,
|
|
|
|
data + i, sublen);
|
2015-05-01 00:16:54 +02:00
|
|
|
*/
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
mbag_set_bstrv(mbag,
|
2015-05-01 00:16:54 +02:00
|
|
|
CW_ITEM_WTP_HARDWARE_VERSION,
|
|
|
|
vendor_id, data + i, sublen);
|
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
break;
|
|
|
|
case CW_SUBELEM_WTP_SOFTWARE_VERSION:
|
2015-04-13 11:00:46 +02:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
mbag_set_bstrv(mbag,
|
2015-04-18 11:20:24 +02:00
|
|
|
CW_ITEM_WTP_SOFTWARE_VERSION,
|
|
|
|
vendor_id, data + i, sublen);
|
2015-04-13 11:00:46 +02:00
|
|
|
/*
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_dword(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_SOFTWARE_VENDOR,
|
|
|
|
vendor_id);
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_bstrn(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_SOFTWARE_VERSION,
|
|
|
|
data + i, sublen);
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
*/
|
2015-04-05 02:10:37 +02:00
|
|
|
break;
|
|
|
|
case CW_SUBELEM_WTP_BOOTLOADER_VERSION:
|
2015-05-01 00:16:54 +02:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
mbag_set_bstrv(mbag,
|
2015-05-01 00:16:54 +02:00
|
|
|
CW_ITEM_WTP_BOOTLOADER_VERSION,
|
|
|
|
vendor_id, data + i, sublen);
|
|
|
|
|
|
|
|
/*
|
|
|
|
mbag_set_dword(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_BOOTLOADER_VENDOR,
|
|
|
|
vendor_id);
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_bstrn(mbag,
|
2015-04-12 19:19:29 +02:00
|
|
|
CW_ITEM_WTP_BOOTLOADER_VERSION,
|
|
|
|
data + i, sublen);
|
2015-05-01 00:16:54 +02:00
|
|
|
*/
|
2015-04-05 02:10:37 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-04-13 11:00:46 +02:00
|
|
|
if (!silent)
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"Unknown WTP descriptor subelement, type = %d",
|
|
|
|
subtype);
|
2015-04-05 02:10:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-04-12 19:19:29 +02:00
|
|
|
i += sublen;
|
2015-04-05 02:10:37 +02:00
|
|
|
|
2015-04-18 11:20:24 +02:00
|
|
|
} //while (i < len);
|
2015-04-05 02:10:37 +02:00
|
|
|
|
|
|
|
return 1;
|
2015-04-12 23:28:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
static int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn,
|
2015-04-13 11:00:46 +02:00
|
|
|
struct cw_action_in *a, uint8_t * data, int len,
|
|
|
|
int silent)
|
2015-04-12 23:28:55 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
|
|
|
|
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE,
|
2015-04-12 23:28:55 +02:00
|
|
|
cw_get_byte(data + 1));
|
|
|
|
|
|
|
|
|
|
|
|
/* Get number of encryption elements */
|
|
|
|
int ncrypt = cw_get_byte(data + 2);
|
|
|
|
if (ncrypt == 0) {
|
2015-04-13 11:00:46 +02:00
|
|
|
if (conn->strict_capwap) {
|
|
|
|
if (!silent)
|
|
|
|
cw_dbg(DBG_ELEM_ERR,
|
|
|
|
"Bad WTP Descriptor, number of encryption elements is 0.");
|
2015-04-12 23:28:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-13 11:00:46 +02:00
|
|
|
if (!silent)
|
|
|
|
cw_dbg(DBG_RFC,
|
|
|
|
"Non standard conform WTP Descriptor, number of encryptoin elements is 0.");
|
2015-04-12 23:28:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int pos = 3;
|
|
|
|
int i;
|
2015-04-13 11:00:46 +02:00
|
|
|
for (i = 0; i < ncrypt; i++) {
|
|
|
|
// It's a dummy for now
|
|
|
|
pos += 3;
|
2015-04-12 23:28:55 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 21:01:38 +01:00
|
|
|
return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent);
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read WTP Descriptor in Cisco-Style (Draft 7)
|
|
|
|
*/
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
static int cw_read_cisco_wtp_descriptor(mbag_t mbag, struct conn *conn,
|
2015-04-13 11:00:46 +02:00
|
|
|
struct cw_action_in *a, uint8_t * data, int len,
|
|
|
|
int silent)
|
|
|
|
{
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
|
|
|
|
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE,
|
2015-04-13 11:00:46 +02:00
|
|
|
cw_get_byte(data + 1));
|
|
|
|
|
|
|
|
|
|
|
|
int pos = 2;
|
|
|
|
|
|
|
|
/* Encryption element, for now dumy XXX */
|
|
|
|
cw_get_word(data + pos + 2);
|
|
|
|
pos += 2;
|
|
|
|
|
2016-03-04 21:01:38 +01:00
|
|
|
return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent);
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
2015-04-13 11:00:46 +02:00
|
|
|
int len, struct sockaddr *from)
|
2015-04-05 02:10:37 +02:00
|
|
|
{
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_t mbag = conn->incomming;
|
2015-04-13 11:00:46 +02:00
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0);
|
2015-04-13 11:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cw_in_cipwap_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
|
|
|
int len, struct sockaddr *from)
|
|
|
|
{
|
2015-05-01 00:16:54 +02:00
|
|
|
mbag_t mbag = conn->incomming;
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
switch (conn->capwap_mode) {
|
2015-04-13 11:00:46 +02:00
|
|
|
case CW_MODE_CISCO:
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_cisco_wtp_descriptor(mbag, conn, a, data, len,
|
2015-04-13 11:00:46 +02:00
|
|
|
0);
|
|
|
|
case CW_MODE_CIPWAP:
|
2015-04-12 19:19:29 +02:00
|
|
|
{
|
2015-04-13 11:00:46 +02:00
|
|
|
/* try to get the right WTP Descriptor */
|
|
|
|
int rc;
|
2015-05-01 00:16:54 +02:00
|
|
|
rc = cw_read_wtp_descriptor(mbag, conn, a, data, len,
|
2015-04-13 11:00:46 +02:00
|
|
|
1);
|
|
|
|
|
|
|
|
if (rc) {
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_wtp_descriptor(mbag, conn, a,
|
2015-04-13 11:00:46 +02:00
|
|
|
data, len, 0);
|
2015-04-12 19:19:29 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
rc = cw_read_cisco_wtp_descriptor(mbag, conn, a,
|
2015-04-13 11:00:46 +02:00
|
|
|
data, len, 0);
|
|
|
|
if (rc) {
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_cisco_wtp_descriptor(mbag,
|
2015-04-13 11:00:46 +02:00
|
|
|
conn, a, data,
|
|
|
|
len, 0);
|
|
|
|
}
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_wtp_descriptor(mbag, conn, a, data,
|
2015-04-13 11:00:46 +02:00
|
|
|
len, 0);
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
}
|
|
|
|
default:
|
2015-05-01 00:16:54 +02:00
|
|
|
return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0);
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-04-05 02:10:37 +02:00
|
|
|
}
|