2015-04-10 17:14:55 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
2015-04-07 07:46:55 +02:00
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
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-04-07 07:46:55 +02:00
|
|
|
|
2015-10-18 09:07:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-12 23:28:55 +02:00
|
|
|
/**
|
2015-04-13 14:55:03 +02:00
|
|
|
* @file Debugging Functions
|
2015-04-12 23:28:55 +02:00
|
|
|
* @brief Various debug functions.
|
2015-10-18 09:07:30 +02:00
|
|
|
*/
|
2018-03-02 00:12:38 +01:00
|
|
|
#include <stdarg.h>
|
2018-03-18 21:48:34 +01:00
|
|
|
#include <stdint.h>
|
2015-04-12 23:28:55 +02:00
|
|
|
|
2015-04-07 07:46:55 +02:00
|
|
|
#include "dbg.h"
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "format.h"
|
2018-03-18 23:51:59 +01:00
|
|
|
#include "ansi_colors.h"
|
2018-03-02 00:12:38 +01:00
|
|
|
|
|
|
|
|
2015-10-18 09:07:30 +02:00
|
|
|
/**
|
|
|
|
*@addtogroup DBG
|
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2018-02-23 09:06:04 +01:00
|
|
|
* @defgroup DebugFunctions Debug Functions
|
|
|
|
* @{
|
|
|
|
*/
|
2015-10-18 09:07:30 +02:00
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
uint32_t cw_dbg_opt_display = DBG_DISP_COLORS;
|
2015-10-17 22:43:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Current debug level
|
2018-02-23 09:06:04 +01:00
|
|
|
*/
|
2015-04-11 19:00:51 +02:00
|
|
|
uint32_t cw_dbg_opt_level = 0;
|
|
|
|
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-09 18:39:57 +01:00
|
|
|
|
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem color_on[] = {
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_PKT_IN, ANSI_YELLOW},
|
|
|
|
{DBG_PKT_OUT, ANSI_YELLOW ANSI_ITALIC},
|
|
|
|
|
|
|
|
{DBG_PKT_DMP_IN, ANSI_BYELLOW},
|
|
|
|
{DBG_PKT_DMP_OUT, ANSI_BYELLOW ANSI_ITALIC},
|
|
|
|
|
|
|
|
{DBG_MSG_IN, ANSI_BLUE ANSI_BOLD},
|
|
|
|
{DBG_MSG_PARSING, ANSI_BLUE },
|
|
|
|
|
|
|
|
{DBG_MSG_OUT, ANSI_BLUE ANSI_BOLD ANSI_ITALIC},
|
|
|
|
{DBG_MSG_ASSEMBLY, ANSI_BLUE ANSI_ITALIC},
|
|
|
|
|
|
|
|
|
|
|
|
{DBG_MSG_IN_DMP, ANSI_BBLUE },
|
|
|
|
{DBG_MSG_OUT_DMP, ANSI_BBLUE ANSI_ITALIC},
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
{DBG_ELEM_IN, ANSI_DEFAULT},
|
|
|
|
{DBG_ELEM_OUT, ANSI_DEFAULT ANSI_ITALIC},
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_MSG_ERR, ANSI_RED},
|
|
|
|
{DBG_PKT_ERR, ANSI_RED},
|
|
|
|
{DBG_ELEM_ERR, ANSI_RED},
|
2018-03-18 21:48:34 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_SUBELEM, ANSI_BBLACK},
|
|
|
|
{DBG_DTLS, ANSI_MAGENTA ANSI_BOLD},
|
|
|
|
{DBG_DTLS_DETAIL, ANSI_MAGENTA},
|
|
|
|
{DBG_DTLS_BIO, ANSI_BMAGENTA},
|
2018-02-23 09:06:04 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_INFO, ANSI_DEFAULT},
|
2018-02-23 09:06:04 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_RFC, ANSI_BRED},
|
2018-02-23 09:06:04 +01:00
|
|
|
{DBG_X, "\x1b[31m"},
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_WARN, ANSI_CYAN},
|
|
|
|
{DBG_MOD, ANSI_WHITE},
|
2018-03-19 17:26:01 +01:00
|
|
|
{DBG_CFG_DMP, ANSI_BCYAN },
|
2018-03-18 23:51:59 +01:00
|
|
|
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
{CW_STR_STOP, ""}
|
2015-04-12 10:19:02 +02:00
|
|
|
};
|
2018-02-23 09:06:04 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
struct cw_StrListElem color_ontext[] = {
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
/* {DBG_ELEM_DMP, "\x1b[37m"},*/
|
2018-03-18 23:51:59 +01:00
|
|
|
{DBG_ELEM_DMP, ANSI_BBLACK ANSI_ITALIC},
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
{CW_STR_STOP, ""}
|
2015-04-12 10:19:02 +02:00
|
|
|
};
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
/*
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem color_off[] = {
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
{CW_STR_STOP, "\x1b[22;39m\x1b[23m"}
|
2015-04-12 10:19:02 +02:00
|
|
|
};
|
2018-03-18 23:51:59 +01:00
|
|
|
*/
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
static struct cw_StrListElem prefix[] = {
|
2018-02-23 09:06:04 +01:00
|
|
|
{DBG_INFO, " Info -"},
|
|
|
|
{DBG_PKT_IN, " Pkt IN -"},
|
|
|
|
{DBG_PKT_OUT, " Pkt Out -"},
|
|
|
|
{DBG_MSG_IN, " Msg IN -"},
|
|
|
|
{DBG_MSG_OUT, " Msg Out -"},
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
{DBG_ELEM_IN, " Msg Element -"},
|
|
|
|
{DBG_ELEM_OUT, " Msg Element -"},
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
{DBG_MSG_ERR, " Msg Error -"},
|
|
|
|
{DBG_PKT_ERR, " Pkt Error -"},
|
|
|
|
{DBG_ELEM_ERR, " Elem Error -"},
|
|
|
|
{DBG_RFC, " RFC -"},
|
|
|
|
{DBG_SUBELEM, " Sub-Element - "},
|
|
|
|
{DBG_DTLS, " DTLS - "},
|
|
|
|
{DBG_DTLS_DETAIL, " DTLS - "},
|
|
|
|
{DBG_WARN, " Warning - "},
|
|
|
|
{DBG_MOD, " Mod - "},
|
2018-03-19 17:26:01 +01:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
{DBG_X, "XXXXX - "},
|
|
|
|
|
|
|
|
{CW_STR_STOP, ""}
|
2015-04-12 10:19:02 +02:00
|
|
|
};
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
static const char *get_dbg_color_on(int level)
|
|
|
|
{
|
|
|
|
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
2015-04-12 10:19:02 +02:00
|
|
|
return "";
|
2018-02-23 09:06:04 +01:00
|
|
|
return cw_strlist_get_str(color_on, level);
|
2015-04-12 10:19:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
/*
|
2018-02-23 09:06:04 +01:00
|
|
|
static const char *get_dbg_color_off(int level)
|
|
|
|
{
|
|
|
|
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
2015-04-12 10:19:02 +02:00
|
|
|
return "";
|
2018-02-23 09:06:04 +01:00
|
|
|
return cw_strlist_get_str(color_off, level);
|
2015-04-12 10:19:02 +02:00
|
|
|
}
|
2018-03-18 23:51:59 +01:00
|
|
|
*/
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
static const char *get_dbg_prefix(int level)
|
|
|
|
{
|
|
|
|
return cw_strlist_get_str(prefix, level);
|
2015-04-12 10:19:02 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
const char *get_dbg_color_ontext(int level)
|
2018-02-23 09:06:04 +01:00
|
|
|
{
|
|
|
|
if (!(cw_dbg_opt_display & DBG_DISP_COLORS))
|
2015-04-12 10:19:02 +02:00
|
|
|
return "";
|
2018-02-23 09:06:04 +01:00
|
|
|
return cw_strlist_get_str(color_ontext, level);
|
2015-04-12 10:19:02 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
/**
|
|
|
|
* Check if a specific debug level is set.
|
|
|
|
* @param level Level to check
|
|
|
|
* @return 0 if leveln is not set, otherwise level is set
|
|
|
|
*/
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
int cw_dbg_is_level(int level)
|
|
|
|
{
|
|
|
|
if (level >= DBG_ALL ){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return (cw_dbg_opt_level & (1<<level));
|
|
|
|
}
|
2015-04-12 10:19:02 +02:00
|
|
|
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
static void cw_dbg_vlog_line(struct cw_LogWriter * writer,
|
|
|
|
const char * prefix, const char * prefix_color,
|
|
|
|
const char *textcolor,const char * format, va_list args)
|
|
|
|
{
|
|
|
|
char fbuf[512];
|
|
|
|
|
|
|
|
if ( writer->colored){
|
|
|
|
sprintf(fbuf,"DBG: %s%s %s%s%s",
|
|
|
|
prefix_color,prefix,textcolor,format,DBG_CLR_OFF);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sprintf(fbuf,"DBG: %s %s",
|
|
|
|
prefix,format);
|
|
|
|
|
|
|
|
}
|
|
|
|
writer->write(LOG_DEBUG,fbuf,args,writer);
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
}
|
2015-04-12 10:19:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
/**
|
|
|
|
* Put a list of missing mandatory message elements to debug output
|
|
|
|
*/
|
2018-03-17 17:29:09 +01:00
|
|
|
void cw_dbg_missing_mand(int level, struct conn *conn, int ** ml, int n,
|
|
|
|
int * a)
|
2015-04-07 07:46:55 +02:00
|
|
|
{
|
2018-03-05 20:39:15 +01:00
|
|
|
/*
|
2018-02-23 09:06:04 +01:00
|
|
|
// if (!cw_dbg_is_level(DBG_MSG_ERR) || n == 0)
|
|
|
|
// return;
|
2018-03-05 20:39:15 +01:00
|
|
|
*/
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-04-07 07:46:55 +02:00
|
|
|
|
|
|
|
char buffer[2000];
|
2018-03-05 20:39:15 +01:00
|
|
|
/* char *p = buffer; */
|
2015-04-07 07:46:55 +02:00
|
|
|
int i;
|
2018-03-05 20:39:15 +01:00
|
|
|
/* char *delim = "";*/
|
|
|
|
|
|
|
|
if (!cw_dbg_is_level(level) || n == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2018-02-26 18:28:12 +01:00
|
|
|
// TODO XXXX
|
2018-03-05 20:39:15 +01:00
|
|
|
*/
|
2015-04-11 19:00:51 +02:00
|
|
|
for (i = 0; i < n; i++) {
|
2018-02-26 18:28:12 +01:00
|
|
|
/* p += sprintf(p, "%s", delim);
|
2015-04-11 19:00:51 +02:00
|
|
|
delim = ", ";
|
|
|
|
p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id));
|
2018-02-26 18:28:12 +01:00
|
|
|
*/
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2015-04-12 19:19:29 +02:00
|
|
|
cw_dbg(level, "Missing mandatory elements: [%s]", buffer);
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-13 14:55:03 +02:00
|
|
|
/**
|
|
|
|
* Display a packet on for debugger
|
2018-02-23 09:06:04 +01:00
|
|
|
*/
|
|
|
|
void cw_dbg_pkt(int level, struct conn *conn, uint8_t * packet, int len,
|
|
|
|
struct sockaddr *from)
|
2015-04-11 19:00:51 +02:00
|
|
|
{
|
|
|
|
|
2018-03-25 10:35:53 +02:00
|
|
|
/* int hlen;*/
|
2015-04-11 19:00:51 +02:00
|
|
|
char buf[1024];
|
2015-04-12 15:15:40 +02:00
|
|
|
|
2018-03-05 20:39:15 +01:00
|
|
|
if (!cw_dbg_is_level(level))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (level == DBG_PKT_IN)
|
|
|
|
cw_format_pkt_hdr(buf, 1, packet, len, from);
|
|
|
|
else
|
|
|
|
cw_format_pkt_hdr(buf, 0, packet, len, from);
|
|
|
|
|
2018-03-25 10:35:53 +02:00
|
|
|
/* hlen = cw_get_hdr_msg_offset(packet);*/
|
2016-03-21 23:35:08 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
cw_dbg(level, "%s", buf);
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
if (cw_dbg_is_level(DBG_PKT_DMP)) {
|
|
|
|
int dlevel;
|
|
|
|
if (level == DBG_PKT_IN){
|
|
|
|
dlevel=DBG_PKT_DMP_IN;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dlevel=DBG_PKT_DMP_OUT;
|
|
|
|
}
|
|
|
|
cw_dbg_dmp(dlevel,packet,len,"");
|
|
|
|
}
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
|
|
|
|
void cw_dbg_dmp(int level, const uint8_t * data, int len, const char *format, ...)
|
2016-04-10 15:58:10 +02:00
|
|
|
{
|
2018-03-18 21:48:34 +01:00
|
|
|
char *dmp,*s,*c;
|
|
|
|
struct cw_FormatDumpSettings settings;
|
|
|
|
|
2016-04-10 15:58:10 +02:00
|
|
|
if (!cw_dbg_is_level(level))
|
|
|
|
return;
|
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
cw_format_get_dump_defaults(&settings);
|
|
|
|
|
|
|
|
settings.dump_prefix=" ";
|
|
|
|
settings.newline="\n ";
|
|
|
|
settings.dump_suffix="\n";
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
dmp = cw_format_dump(data, len, &settings);
|
2016-03-12 16:12:36 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
/* wrtie the dump line by line to the log file */
|
|
|
|
c=dmp;
|
|
|
|
while ((s=strchr(c,'\n'))!=NULL){
|
|
|
|
*s=0;
|
|
|
|
cw_dbg(level," %s",c);
|
|
|
|
c=s+1;
|
|
|
|
}
|
2016-03-12 16:12:36 +01:00
|
|
|
|
|
|
|
free(dmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
|
|
|
struct sockaddr *from)
|
2015-04-11 19:00:51 +02:00
|
|
|
{
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2015-04-11 19:00:51 +02:00
|
|
|
char buf[1024];
|
2018-03-05 20:39:15 +01:00
|
|
|
char *s;
|
|
|
|
struct cw_MsgData search;
|
|
|
|
struct cw_MsgData * message;
|
|
|
|
const char * msname;
|
|
|
|
uint8_t *msgptr;
|
|
|
|
int msg_id;
|
|
|
|
|
|
|
|
if (!cw_dbg_is_level(level))
|
|
|
|
return;
|
|
|
|
|
|
|
|
s = buf;
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-05 20:39:15 +01:00
|
|
|
msgptr = cw_get_hdr_msg_ptr(packet);
|
|
|
|
msg_id = cw_get_msg_id(msgptr);
|
|
|
|
|
2018-02-26 20:18:53 +01:00
|
|
|
search.type = msg_id;
|
2018-03-11 00:56:41 +01:00
|
|
|
message = mavl_get(conn->msgset->msgdata,&search);
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2018-02-26 23:14:32 +01:00
|
|
|
if (!message)
|
2018-03-18 21:48:34 +01:00
|
|
|
msname=cw_strmsg(msg_id);
|
2018-02-26 23:14:32 +01:00
|
|
|
else
|
|
|
|
msname = message->name;
|
2018-02-26 20:18:53 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
s += sprintf(s, "%s Message (type=%d) ", msname , msg_id);
|
2018-02-23 09:06:04 +01:00
|
|
|
if (level == DBG_MSG_IN)
|
2018-03-05 12:23:16 +01:00
|
|
|
s += sprintf(s, "from %s ", sock_addr2str(from,sock_buf));
|
2015-04-13 11:00:46 +02:00
|
|
|
else
|
2018-03-05 12:23:16 +01:00
|
|
|
s += sprintf(s, "to %s ", sock_addr2str(from,sock_buf));
|
2015-04-13 11:00:46 +02:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
s += sprintf(s, ", Seqnum: %d ElemLen: %d", cw_get_msg_seqnum(msgptr),
|
|
|
|
cw_get_msg_elems_len(msgptr));
|
2018-03-18 21:48:34 +01:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
cw_dbg(level, "%s", buf);
|
2018-03-18 23:51:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (cw_dbg_is_level(DBG_MSG_DMP)){
|
|
|
|
int dlevel;
|
|
|
|
if(level==DBG_MSG_IN){
|
|
|
|
dlevel = DBG_MSG_IN_DMP;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dlevel = DBG_MSG_OUT_DMP;
|
|
|
|
}
|
|
|
|
cw_dbg_dmp(dlevel,packet,len,"");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-07 07:46:55 +02:00
|
|
|
}
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2018-03-11 11:29:00 +01:00
|
|
|
/*
|
|
|
|
|
2015-04-12 15:15:40 +02:00
|
|
|
static int cw_format_vendor(char *dst, uint32_t vendor_id, int elem_id,
|
2018-02-23 09:06:04 +01:00
|
|
|
const uint8_t * elem_data)
|
2015-04-12 15:15:40 +02:00
|
|
|
{
|
2018-03-05 20:39:15 +01:00
|
|
|
uint32_t lw_elem_id;
|
2015-04-12 15:15:40 +02:00
|
|
|
switch (vendor_id) {
|
|
|
|
case CW_VENDOR_ID_CISCO:
|
2018-02-23 09:06:04 +01:00
|
|
|
{
|
|
|
|
if (elem_id != CW_CISCO_SPAM_VENDOR_SPECIFIC) {
|
|
|
|
return sprintf(dst, "%d - %s", elem_id,
|
|
|
|
cw_cisco_id_to_str(elem_id));
|
|
|
|
}
|
2015-04-12 15:15:40 +02:00
|
|
|
|
|
|
|
|
2018-03-11 11:29:00 +01:00
|
|
|
// dive into LWAPP vendor specific decoding
|
2018-03-05 20:39:15 +01:00
|
|
|
lw_elem_id = lw_get_word(elem_data + 4 + 6);
|
2018-02-23 09:06:04 +01:00
|
|
|
return sprintf(dst, "%d/LWAPP Vendor: %d - %s",
|
|
|
|
elem_id,
|
|
|
|
lw_elem_id, lw_cisco_id_to_str(lw_elem_id));
|
2015-04-12 15:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-04-12 15:15:40 +02:00
|
|
|
default:
|
2018-02-23 09:06:04 +01:00
|
|
|
{
|
|
|
|
return sprintf(dst, "%d", elem_id);
|
|
|
|
|
|
|
|
}
|
2015-04-12 15:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-11 11:29:00 +01:00
|
|
|
*/
|
2015-04-12 15:15:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
void cw_dbg_version_subelem(int level, const char *context, int subtype,
|
|
|
|
uint32_t vendor_id, const uint8_t * vstr, int len)
|
2015-04-11 19:00:51 +02:00
|
|
|
{
|
2018-03-09 07:44:17 +01:00
|
|
|
char v[2048];
|
|
|
|
int n;
|
2018-03-07 13:13:58 +01:00
|
|
|
|
2018-03-05 20:39:15 +01:00
|
|
|
if (!cw_dbg_is_level(level))
|
|
|
|
return;
|
2018-03-09 07:44:17 +01:00
|
|
|
if (!vstr)
|
2018-03-07 13:13:58 +01:00
|
|
|
return;
|
2018-03-09 07:44:17 +01:00
|
|
|
n = cw_format_version(v, vstr, len);
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
sprintf(v + n, ", Vendor Id: %d, %s", vendor_id, cw_strvendor(vendor_id));
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-09 07:44:17 +01:00
|
|
|
cw_dbg(level, "%s: SubType %d, %s", context, subtype, v);
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
/*
|
2018-03-18 21:48:34 +01:00
|
|
|
void cw_dbgv(struct cw_LogWriter *writer, int level, const char * format, va_list args)
|
2015-04-11 19:00:51 +02:00
|
|
|
{
|
2018-03-05 20:39:15 +01:00
|
|
|
char fbuf[1024];
|
2018-03-18 21:48:34 +01:00
|
|
|
|
|
|
|
if (writer->colored ){
|
|
|
|
sprintf(fbuf, "DBG:%s%s %s%s%s",
|
|
|
|
get_dbg_color_on(level),
|
|
|
|
get_dbg_prefix(level),
|
|
|
|
get_dbg_color_ontext(level), format, get_dbg_color_off(level)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sprintf(fbuf, "DBG:%s %s",
|
|
|
|
get_dbg_prefix(level), format);
|
|
|
|
}
|
|
|
|
|
|
|
|
writer->write(LOG_DEBUG,fbuf,args,&cw_log_console_writer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-03-18 23:51:59 +01:00
|
|
|
*/
|
2018-03-18 21:48:34 +01:00
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
/*
|
2018-03-18 21:48:34 +01:00
|
|
|
void cw_dbgv1(struct cw_LogWriter *writer, int level, const char * format, ...){
|
2018-03-05 20:39:15 +01:00
|
|
|
va_list args;
|
2018-03-18 21:48:34 +01:00
|
|
|
va_start(args, format);
|
|
|
|
cw_dbgv(writer,level,format,args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
2018-03-18 23:51:59 +01:00
|
|
|
*/
|
2018-03-18 21:48:34 +01:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
void cw_dbg(int level, const char *format, ...){
|
|
|
|
int i;
|
|
|
|
va_list args;
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
if (!(cw_dbg_is_level(level)))
|
2015-04-11 19:00:51 +02:00
|
|
|
return;
|
2018-03-18 21:48:34 +01:00
|
|
|
|
|
|
|
for (i=0; cw_log_writers[i]; i++){
|
|
|
|
va_start(args, format);
|
|
|
|
cw_dbg_vlog_line(cw_log_writers[i],
|
|
|
|
get_dbg_prefix(level),get_dbg_color_on(level),
|
|
|
|
get_dbg_color_ontext(level),
|
|
|
|
format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
}
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-02-23 09:06:04 +01:00
|
|
|
|
2018-03-17 19:32:44 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
void cw_dbg_elem(int level, struct conn *conn, int msg,
|
2018-03-19 17:26:01 +01:00
|
|
|
struct cw_ElemHandler * handler, const uint8_t * msgbuf, int len)
|
2018-03-18 21:48:34 +01:00
|
|
|
{
|
|
|
|
char vendorname[256];
|
|
|
|
char vendor_details[265];
|
2018-03-18 23:51:59 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
|
|
|
|
if (!cw_dbg_is_level(level))
|
|
|
|
return;
|
|
|
|
|
|
|
|
*vendor_details = 0;
|
2018-03-17 19:32:44 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
if (handler->vendor){
|
|
|
|
sprintf(vendorname,"Vendor %s",cw_strvendor(handler->vendor));
|
|
|
|
}
|
|
|
|
else{
|
2018-03-25 10:35:53 +02:00
|
|
|
sprintf(vendorname,"%s","");
|
2018-03-18 21:48:34 +01:00
|
|
|
}
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2018-03-19 17:26:01 +01:00
|
|
|
|
|
|
|
cw_dbg(level,"%s %d (%s), len=%d ",vendorname,handler->id,
|
2018-03-18 21:48:34 +01:00
|
|
|
handler->name,len);
|
2018-03-19 08:31:50 +01:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
if (cw_dbg_is_level(DBG_ELEM_DMP)) {
|
|
|
|
/*dmp = cw_format_dump(msgbuf,len,NULL);*/
|
|
|
|
|
2018-03-18 23:51:59 +01:00
|
|
|
cw_dbg_dmp(DBG_ELEM_DMP,msgbuf,len,"");
|
2018-03-18 21:48:34 +01:00
|
|
|
}
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
return;
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2018-03-18 21:48:34 +01:00
|
|
|
}
|
2018-03-03 17:42:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-19 17:26:01 +01:00
|
|
|
void cw_dbg_ktv_dump(mavl_t ktv, uint32_t dbglevel,
|
|
|
|
const char *header, const char *prefix, const char *footer )
|
|
|
|
{
|
|
|
|
char value[500];
|
|
|
|
struct cw_KTV * data;
|
|
|
|
mavliter_t it;
|
|
|
|
const struct cw_Type * type;
|
|
|
|
|
|
|
|
if (header != NULL)
|
|
|
|
cw_dbg (dbglevel, header);
|
|
|
|
|
|
|
|
mavliter_init(&it,ktv);
|
|
|
|
|
|
|
|
mavliter_foreach(&it){
|
|
|
|
|
|
|
|
data = mavliter_get(&it);
|
|
|
|
type = data->type;
|
|
|
|
type->to_str(data,value,0);
|
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
cw_dbg(dbglevel,"%s%s :%s: %s",prefix,data->key,type->name, value);
|
2018-03-19 17:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (footer != NULL)
|
|
|
|
cw_dbg (dbglevel, footer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
/*
|
|
|
|
void dbg_istore_dmp(mbag_t s)
|
2015-04-19 16:44:20 +02:00
|
|
|
{
|
|
|
|
DEFINE_AVLITER(it,s);
|
|
|
|
avliter_foreach(&it) {
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_item_t *i = avliter_get(&it);
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
char buffer[1000];
|
|
|
|
|
|
|
|
struct cw_str * strings = cw_item_strings;
|
|
|
|
|
|
|
|
const char * in = cw_strlist_get_str(strings,i->id);
|
|
|
|
|
|
|
|
cw_format_item(buffer,i);
|
|
|
|
printf("Item ID %d-%s: %s\n",i->id,in,buffer);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2015-04-19 23:27:44 +02:00
|
|
|
*/
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
|
2015-04-13 14:55:03 +02:00
|
|
|
/**@}*/
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2015-10-18 09:07:30 +02:00
|
|
|
|
|
|
|
/**@}*/
|