2014-07-11 22:12:11 +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-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
*@file
|
|
|
|
*@brief Debug helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2014-08-14 11:25:33 +02:00
|
|
|
#include <string.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include "cw_log.h"
|
2014-08-21 21:16:55 +02:00
|
|
|
#include "capwap.h"
|
2015-03-29 01:55:06 +01:00
|
|
|
#include "capwap_cisco.h"
|
|
|
|
#include "lwapp_cisco.h"
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
#include "cw_util.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
int cw_dbg_opt_detail = 0;
|
|
|
|
int cw_dbg_opt_level = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cw_log_debug_level = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
static void cw_log_debug0_(const char *format, ...)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_log_debug_level < 0)
|
2014-07-11 22:12:11 +02:00
|
|
|
return;
|
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
cw_vlog_(LOG_DEBUG, format, args);
|
2014-07-11 22:12:11 +02:00
|
|
|
va_end(args);
|
2014-08-25 23:39:26 +02:00
|
|
|
closelog();
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
static void cw_log_debug1_(const char *format, ...)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_log_debug_level < 1)
|
2014-07-11 22:12:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
cw_vlog_(LOG_DEBUG, format, args);
|
2014-07-11 22:12:11 +02:00
|
|
|
va_end(args);
|
2014-08-25 23:39:26 +02:00
|
|
|
closelog();
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
static void cw_log_debug2_(const char *format, ...)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_log_debug_level < 2)
|
2014-07-11 22:12:11 +02:00
|
|
|
return;
|
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
cw_vlog_(LOG_DEBUG, format, args);
|
2014-07-11 22:12:11 +02:00
|
|
|
va_end(args);
|
2014-08-25 23:39:26 +02:00
|
|
|
closelog();
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2015-02-07 10:57:58 +01:00
|
|
|
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2015-03-29 01:55:06 +01:00
|
|
|
int cw_log_debug_dump_(int level, const uint8_t * data, int len, const char *format, ...)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2014-08-25 23:39:26 +02:00
|
|
|
int maxtlen = 2048;
|
2014-07-11 22:12:11 +02:00
|
|
|
int i;
|
|
|
|
int rowlen = CW_LOG_DUMP_ROW_LEN;
|
2014-08-25 23:39:26 +02:00
|
|
|
int rows = len / rowlen;
|
|
|
|
int tlen = 0;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
char *dst = malloc(len * 3 + (rows * 2) + 8 + maxtlen);
|
|
|
|
if (!dst)
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (format != NULL) {
|
2014-07-11 22:12:11 +02:00
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
tlen = vsnprintf(dst, maxtlen, format, args);
|
2014-07-11 22:12:11 +02:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (len % CW_LOG_DUMP_ROW_LEN)
|
2014-07-11 22:12:11 +02:00
|
|
|
rows++;
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
char *pdst = dst + tlen;
|
|
|
|
sprintf(pdst, "\n\t");
|
|
|
|
pdst += 2;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
sprintf(pdst, "%02X ", data[i] & 0xff);
|
|
|
|
pdst += 3;
|
|
|
|
if ((i + 1) % rowlen == 0) {
|
|
|
|
sprintf(pdst, "\n\t");
|
|
|
|
pdst += 2;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
cw_log_debug_cbs[level] ("%s", dst);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
free(dst);
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-14 10:04:07 +02:00
|
|
|
|
2015-03-29 01:55:06 +01:00
|
|
|
void cw_log_dbg_(int level, const char *file, int line, const char *format, ...)
|
2014-08-14 10:04:07 +02:00
|
|
|
{
|
2015-02-08 11:42:01 +01:00
|
|
|
|
2014-08-17 11:38:56 +02:00
|
|
|
if (!(level & cw_dbg_opt_level))
|
2014-08-14 10:04:07 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
char buf[2048];
|
|
|
|
|
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
vsprintf(buf, format, args);
|
2014-08-14 10:04:07 +02:00
|
|
|
va_end(args);
|
|
|
|
|
2014-08-14 11:25:33 +02:00
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
|
2014-08-25 23:39:26 +02:00
|
|
|
cw_log(LOG_DEBUG, "%s:%d: %s", file, line, buf);
|
2014-08-14 10:04:07 +02:00
|
|
|
else
|
2014-08-25 23:39:26 +02:00
|
|
|
cw_log(LOG_DEBUG, buf);
|
2014-08-14 10:04:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
void cw_log_dbg_dmp_(int level, const char *file, int line,
|
2015-03-29 01:55:06 +01:00
|
|
|
const uint8_t * data, int len, const char *format, ...)
|
2014-08-14 11:25:33 +02:00
|
|
|
{
|
|
|
|
|
2014-08-17 11:38:56 +02:00
|
|
|
if (!(level & cw_dbg_opt_level))
|
2014-08-14 11:25:33 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
int maxtlen = 2048;
|
2014-08-14 11:25:33 +02:00
|
|
|
int i;
|
|
|
|
int rowlen = CW_LOG_DUMP_ROW_LEN;
|
2014-08-25 23:39:26 +02:00
|
|
|
int rows = len / rowlen;
|
|
|
|
int tlen = 0;
|
2014-08-14 11:25:33 +02:00
|
|
|
|
|
|
|
int md;
|
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP)
|
2014-08-25 23:39:26 +02:00
|
|
|
md = 2;
|
2014-08-14 11:25:33 +02:00
|
|
|
else
|
2014-08-25 23:39:26 +02:00
|
|
|
md = 1;
|
|
|
|
|
2014-08-14 11:25:33 +02:00
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
char *dst = malloc(md * (len * 3 + (rows * 2) + 8 + maxtlen));
|
|
|
|
if (!dst)
|
2014-08-14 11:25:33 +02:00
|
|
|
return;
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (format != NULL) {
|
2014-08-14 11:25:33 +02:00
|
|
|
va_list args;
|
2014-08-25 23:39:26 +02:00
|
|
|
va_start(args, format);
|
|
|
|
tlen = vsnprintf(dst, maxtlen, format, args);
|
2014-08-14 11:25:33 +02:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (len % CW_LOG_DUMP_ROW_LEN)
|
2014-08-14 11:25:33 +02:00
|
|
|
rows++;
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
|
|
|
|
char *pdst = dst + tlen;
|
|
|
|
sprintf(pdst, "\n\t");
|
|
|
|
pdst += 2;
|
2014-08-14 11:25:33 +02:00
|
|
|
|
|
|
|
char asc_buffer[128];
|
2014-08-25 23:39:26 +02:00
|
|
|
char *ascdst = asc_buffer;
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
sprintf(pdst, "%02X ", data[i] & 0xff);
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
|
|
|
|
int c = data[i] & 0xff;
|
|
|
|
if (c < 0x20 || c > 0x80)
|
|
|
|
c = '.';
|
|
|
|
*ascdst = c;
|
2014-08-14 11:25:33 +02:00
|
|
|
ascdst++;
|
|
|
|
}
|
2014-08-25 23:39:26 +02:00
|
|
|
|
|
|
|
pdst += 3;
|
|
|
|
if ((i + 1) % rowlen == 0) {
|
2014-08-14 11:25:33 +02:00
|
|
|
int l;
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
|
|
|
|
*ascdst = 0;
|
|
|
|
l = sprintf(pdst, " | %s\n\t", asc_buffer);
|
|
|
|
ascdst = asc_buffer;
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
} else {
|
|
|
|
l = sprintf(pdst, "\n\t");
|
2014-08-14 11:25:33 +02:00
|
|
|
}
|
2014-08-25 23:39:26 +02:00
|
|
|
pdst += l;
|
2014-08-14 11:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_ASC_DMP) {
|
|
|
|
*ascdst = 0;
|
2014-08-14 11:25:33 +02:00
|
|
|
if (strlen(asc_buffer))
|
2014-08-25 23:39:26 +02:00
|
|
|
pdst += sprintf(pdst, " | %s", asc_buffer);
|
2014-08-14 11:25:33 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cw_dbg_opt_detail & DBG_DETAIL_LINE_NUMBERS)
|
2014-08-25 23:39:26 +02:00
|
|
|
cw_log(LOG_DEBUG, "%s:%d: %s", file, line, dst);
|
2014-08-14 11:25:33 +02:00
|
|
|
else
|
2014-08-25 23:39:26 +02:00
|
|
|
cw_log(LOG_DEBUG, dst);
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
free(dst);
|
2014-08-14 11:25:33 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
void (*cw_log_debug_cbs[]) (const char *fromat, ...) = {
|
|
|
|
cw_log_debug0_, cw_log_debug1_, cw_log_debug2_};
|
2014-08-14 11:25:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2015-03-29 01:55:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cw_format_vendor(char *dst, uint32_t vendor_id, int elem_id, const uint8_t * elem_data)
|
|
|
|
{
|
|
|
|
switch (vendor_id) {
|
|
|
|
case CW_VENDOR_ID_CISCO:
|
|
|
|
{
|
|
|
|
sprintf(dst, "\n\t Cisco Vendor Specific: %d - %s", elem_id,
|
|
|
|
cw_cisco_id_to_str(elem_id));
|
|
|
|
|
|
|
|
/* dive into LWAPP vendor specific decoding */
|
|
|
|
if (elem_id == CW_CISCO_SPAM_VENDOR_SPECIFIC) {
|
|
|
|
uint32_t lw_elem_id = lw_get_word(elem_data + 4 + 6);
|
|
|
|
char b[256];
|
|
|
|
sprintf(b, "\n\t LWAPP Cisco Specific: %d - %s",
|
|
|
|
lw_elem_id, lw_cisco_id_to_str(lw_elem_id));
|
|
|
|
strcat(dst, b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-24 15:06:35 +02:00
|
|
|
/**
|
2014-08-25 23:39:26 +02:00
|
|
|
* print debug info for message elements
|
|
|
|
*/
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
void cw_dbg_msgelem_(int msg, int msgelem, const uint8_t * msgbuf, int len)
|
2014-08-21 21:16:55 +02:00
|
|
|
{
|
2015-03-28 12:51:34 +01:00
|
|
|
if (!cw_dbg_is_level(DBG_ELEM))
|
2014-08-21 21:16:55 +02:00
|
|
|
return;
|
2014-08-24 15:06:35 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
const char *elemname;
|
2014-08-24 15:06:35 +02:00
|
|
|
char vendorname[256];
|
2015-03-29 01:55:06 +01:00
|
|
|
char vendor_details[265];
|
|
|
|
*vendor_details = 0;
|
|
|
|
|
2015-03-23 07:48:27 +01:00
|
|
|
if (msgelem == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
|
2015-03-29 01:55:06 +01:00
|
|
|
uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf));
|
2014-08-25 23:39:26 +02:00
|
|
|
int type = ntohs(*((uint16_t *) (msgbuf + 4)));
|
|
|
|
sprintf(vendorname, "%s/%s/%d",
|
|
|
|
(char *) cw_msgelemtostr(msgelem),
|
2015-03-29 01:55:06 +01:00
|
|
|
(char *) lw_vendor_id_to_str(vendor_id), type);
|
2014-08-25 23:39:26 +02:00
|
|
|
elemname = vendorname;
|
2015-03-29 01:55:06 +01:00
|
|
|
cw_format_vendor(vendor_details, vendor_id, type, msgbuf);
|
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
} else {
|
|
|
|
elemname = cw_msgelemtostr(msgelem);
|
2014-08-24 15:06:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-28 12:51:34 +01:00
|
|
|
if (!cw_dbg_is_level(DBG_ELEM_DMP))
|
|
|
|
cw_dbg(DBG_ELEM,
|
2015-03-29 01:55:06 +01:00
|
|
|
"%s, CAWPAP element: type=%d (%s), len=%d%s",
|
|
|
|
cw_msgtostr(msg), msgelem, elemname, len, vendor_details);
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-21 21:16:55 +02:00
|
|
|
else
|
2015-03-28 12:51:34 +01:00
|
|
|
cw_dbg_dmp(DBG_ELEM, msgbuf, len,
|
2015-03-29 01:55:06 +01:00
|
|
|
"%s, CAPWAP element: type=%d (%s), len=%d%s\n\tDump ...",
|
|
|
|
cw_msgtostr(msg), msgelem, elemname, len, vendor_details);
|
2014-08-25 23:39:26 +02:00
|
|
|
}
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2015-03-29 01:55:06 +01:00
|
|
|
void lw_dbg_elem_(int msg_id, int elem_id, const uint8_t * elem_data, int elem_len)
|
|
|
|
{
|
|
|
|
if (!cw_dbg_is_level(DBG_ELEM))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *elem_name;
|
|
|
|
char vendorname[256];
|
|
|
|
|
|
|
|
if (elem_id == LW_ELEM_VENDOR_SPECIFIC) {
|
|
|
|
uint32_t vendor = lw_get_dword(elem_data);
|
|
|
|
int type = lw_get_word(elem_data + 4);
|
|
|
|
sprintf(vendorname, "%s/%s/%d",
|
|
|
|
(char *) lw_elem_id_to_str(elem_id),
|
|
|
|
(char *) lw_vendor_id_to_str(vendor), type);
|
|
|
|
elem_name = vendorname;
|
|
|
|
} else
|
|
|
|
elem_name = lw_elem_id_to_str(msg_id);
|
|
|
|
|
|
|
|
|
|
|
|
if (!cw_dbg_is_level(DBG_ELEM_DMP))
|
|
|
|
cw_dbg(DBG_ELEM,
|
|
|
|
"%s, LWAPP element: type=%d (%s), len=%d",
|
|
|
|
lw_msg_id_to_str(msg_id), elem_id, elem_name, elem_len);
|
|
|
|
|
|
|
|
else
|
|
|
|
cw_dbg_dmp(DBG_ELEM, elem_data, elem_len,
|
|
|
|
"%s, LWAPP element: type=%d (%s), len=%d\n\tDump ...",
|
|
|
|
lw_msg_id_to_str(msg_id), elem_id, elem_name, elem_len);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand)
|
|
|
|
{
|
|
|
|
if (!cw_dbg_is_level(DBG_CW_RFC))
|
|
|
|
return;
|
2014-08-14 11:25:33 +02:00
|
|
|
|
2014-08-25 23:39:26 +02:00
|
|
|
if (cw_is_missing_mand_elems(mand)) {
|
|
|
|
char str[512];
|
|
|
|
cw_get_missing_mand_elems(str, mand);
|
2015-03-29 01:55:06 +01:00
|
|
|
cw_dbg(DBG_CW_RFC, "Missing msgelems in %s: %s", cw_msgtostr(msgtype), str);
|
2014-08-25 23:39:26 +02:00
|
|
|
}
|
2014-08-21 21:16:55 +02:00
|
|
|
}
|