new debug functions - work on hex dump
FossilOrigin-Name: c76afdd26f14000b912fea5a052abf0338c8515871ae526fef727a828924d2e7
This commit is contained in:
@ -32,6 +32,8 @@
|
||||
#include "fragman.h"
|
||||
#include "cwmsg.h"
|
||||
|
||||
#include "mbag.h"
|
||||
|
||||
/*#include "action.h"*/
|
||||
|
||||
/*#include "mbag.h"*/
|
||||
|
@ -273,8 +273,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
/* Search message */
|
||||
struct cw_MsgData * message;
|
||||
message = mavl_get(conn->msgset->messages,&search);
|
||||
|
||||
message = mavl_find_ptr(conn->msgset->messages,&search);
|
||||
|
||||
int result_code = 0;
|
||||
|
||||
if (!message){
|
||||
@ -475,8 +475,6 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
|
135
src/cw/cw_format_dump.c
Normal file
135
src/cw/cw_format_dump.c
Normal file
@ -0,0 +1,135 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "format.h"
|
||||
|
||||
|
||||
static struct cw_FormatDumpSettings CW_FORMAT_DUMP_SETTINGS = {
|
||||
32/*CW_FORMAT_DUMP_ROW_LEN*/, /* rowlen */
|
||||
1, /* ascii */
|
||||
0, /* settings->invlen */
|
||||
"\n\t", /* dump_prefix */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static int cw_format_dump_row(char *dst, const uint8_t * data, int len){
|
||||
char *pdst = dst;
|
||||
int i;
|
||||
char *sp;
|
||||
for (i = 0; i < len; i++) {
|
||||
sp = ((i+1)%4==0 && i<len-1) ? "|" : " ";
|
||||
pdst += sprintf(pdst, "%02X%s", data[i] & 0xff, sp);
|
||||
}
|
||||
|
||||
pdst+=sprintf(pdst," ");
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
int c = data[i] & 0xff;
|
||||
if (c < 0x20 || c > 0x7f)
|
||||
c = '.';
|
||||
pdst+=sprintf(pdst,"%c",c);
|
||||
}
|
||||
|
||||
pdst+=sprintf(pdst,"%s","\n");
|
||||
return pdst-dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an ASCII hex dump of binary data
|
||||
*
|
||||
* @param data data to dump
|
||||
* @param len number of bytes to dump (size of data)
|
||||
* @return a character string with the created data ASCII
|
||||
* dump (must be released with free).If memory cannot be allocated
|
||||
* the return value is NULL.
|
||||
*/
|
||||
char *cw_format_dump(const uint8_t * data, int len,
|
||||
struct cw_FormatDumpSettings *settings)
|
||||
{
|
||||
int i;
|
||||
|
||||
int row,rows;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!settings)
|
||||
settings = &CW_FORMAT_DUMP_SETTINGS;
|
||||
|
||||
rows = len / settings->rowlen;
|
||||
|
||||
printf("Number fo rows: %d\n",rows);
|
||||
|
||||
int md;
|
||||
if (settings->ascii)
|
||||
md = 2;
|
||||
else
|
||||
md = 1;
|
||||
|
||||
char *dst = malloc(2 * (md * (len * 3 + (rows * 2) + 8 )));
|
||||
if (!dst)
|
||||
return NULL;
|
||||
|
||||
if (len % settings->rowlen)
|
||||
rows++;
|
||||
|
||||
char *pdst = dst;
|
||||
|
||||
pdst += sprintf(pdst, "%s",settings->dump_prefix);
|
||||
/* pdst += 2; */
|
||||
|
||||
char asc_buffer[128];
|
||||
char *ascdst = asc_buffer;
|
||||
|
||||
pdst = dst;
|
||||
for (row; row<rows; row++){
|
||||
int n;
|
||||
pdst += cw_format_dump_row(pdst,data+row*settings->rowlen,settings->rowlen);
|
||||
}
|
||||
return dst;
|
||||
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
char *sp = " ";
|
||||
if (i == settings->invlen - 1)
|
||||
sp = "|";
|
||||
|
||||
pdst += sprintf(pdst, "%02X%s", data[i] & 0xff, sp);
|
||||
if (settings->ascii) {
|
||||
int c = data[i] & 0xff;
|
||||
if (c < 0x20 || c > 0x7f)
|
||||
c = '.';
|
||||
*ascdst = c;
|
||||
ascdst++;
|
||||
}
|
||||
|
||||
if ((i + 1) % settings->rowlen == 0) {
|
||||
int l;
|
||||
if (settings->ascii) {
|
||||
*ascdst = 0;
|
||||
l = sprintf(pdst, " | %s\n\t", asc_buffer);
|
||||
ascdst = asc_buffer;
|
||||
|
||||
} else {
|
||||
l = sprintf(pdst, "\n\t");
|
||||
}
|
||||
pdst += l;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (settings->ascii) {
|
||||
*ascdst = 0;
|
||||
if (strlen(asc_buffer))
|
||||
pdst += sprintf(pdst, " | %s", asc_buffer);
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
@ -473,8 +473,6 @@ void cw_dbg_dmp_(int level, const char *file, int line,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct sockaddr *from)
|
||||
{
|
||||
@ -494,7 +492,7 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
|
||||
struct cw_MsgData search;
|
||||
search.type = msg_id;
|
||||
struct cw_MsgData * message;
|
||||
message = mavl_get(conn->msgset->messages,&search);
|
||||
message = mavl_get_ptr(conn->msgset->messages,&search);
|
||||
|
||||
char * msname;
|
||||
if (!message)
|
||||
|
@ -65,7 +65,6 @@ void cw_dbg_packet(struct conn *conn, uint8_t * packet, int len);
|
||||
*/
|
||||
#include "debug.h"
|
||||
|
||||
#define DBG_LN(level) level,__FILE__,__LINE__
|
||||
|
||||
|
||||
/* driver specific debugs */
|
||||
|
@ -25,10 +25,10 @@
|
||||
#ifndef __FORMAT_H
|
||||
#define __FORMAT_H
|
||||
|
||||
#include "cw.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern int format_hex_bytes(char *dst, const char *format, const char *delim,
|
||||
int format_hex_bytes(char *dst, const char *format, const char *delim,
|
||||
const uint8_t * src, int len);
|
||||
|
||||
char *format_s_hex_bytes(char *dst, const char *format, const char *delim,
|
||||
@ -84,6 +84,22 @@ int format_dot11_fc(char *dst, uint16_t fc);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef CW_FORMAT_DUMP_ROW_LEN
|
||||
#define CW_FORMAT_DUMP_ROW_LEN 16
|
||||
#endif
|
||||
|
||||
struct cw_FormatDumpSettings {
|
||||
int rowlen;
|
||||
int ascii;
|
||||
int invlen;
|
||||
|
||||
const char * dump_prefix;
|
||||
};
|
||||
|
||||
char *cw_format_dump(const uint8_t * data, int len,
|
||||
struct cw_FormatDumpSettings *settings);
|
||||
|
||||
/**@}*/
|
||||
|
||||
#endif
|
||||
|
@ -58,7 +58,7 @@ union mavldata {
|
||||
uint32_t dword;
|
||||
uint16_t word;
|
||||
uint8_t byte;
|
||||
const char *str;
|
||||
char *str;
|
||||
};
|
||||
typedef union mavldata mavldata_t;
|
||||
|
||||
@ -112,6 +112,8 @@ union mavldata *mavl_add(struct mavl *t, union mavldata *data);
|
||||
union mavldata * mavl_get(struct mavl *t ,union mavldata *data);
|
||||
struct mavlnode *mavl_get_node(struct mavl *t, union mavldata *data);
|
||||
void * mavl_get_ptr(mavl_t tree, void * search);
|
||||
void *mavl_add_ptr(mavl_t tree, void *ptr);
|
||||
|
||||
void mavl_merge(mavl_t m, mavl_t t);
|
||||
|
||||
|
||||
@ -221,7 +223,10 @@ typedef mavl_t mavl_conststr_t;
|
||||
extern mavl_conststr_t mavl_create_conststr();
|
||||
|
||||
int mavl_cmp_dword(const union mavldata *e1, const union mavldata *e2);
|
||||
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2);
|
||||
|
||||
void mavl_free_bin(union mavldata *data);
|
||||
void mavl_free_str(union mavldata *data);
|
||||
|
||||
|
||||
/*
|
||||
|
10
src/cw/mavl_add_ptr.c
Normal file
10
src/cw/mavl_add_ptr.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include "mavl.h"
|
||||
|
||||
void *mavl_add_ptr(mavl_t tree, void *ptr){
|
||||
mavldata_t data, *result;
|
||||
data.ptr = ptr;
|
||||
result = mavl_add(tree,&data);
|
||||
if (result)
|
||||
return result->ptr;
|
||||
return NULL;
|
||||
}
|
17
src/cw/mavl_add_strdup.c
Normal file
17
src/cw/mavl_add_strdup.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "mavl.h"
|
||||
|
||||
const char * mavl_add_strdup(mavl_t t, const char * str)
|
||||
{
|
||||
mavldata_t s, *result;
|
||||
s.str = strdup(str);
|
||||
if (!s.str)
|
||||
return NULL;
|
||||
|
||||
result = mavl_add(t,&s);
|
||||
if (!result){
|
||||
free(s.str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return result->str;
|
||||
}
|
6
src/cw/mavl_cmp_str.c
Normal file
6
src/cw/mavl_cmp_str.c
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
#include "mavl.h"
|
||||
|
||||
int mavl_cmp_str(const union mavldata *e1, const union mavldata *e2){
|
||||
return strcmp (e1->str,e2->str);
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include "mbag.h"
|
||||
|
||||
#include "mavl.h"
|
||||
#include "cw/debug.h"
|
||||
#include "cw/log.h"
|
||||
#include "debug.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "message_set.h"
|
||||
|
||||
@ -65,7 +65,7 @@ static void msgdata_destroy(struct cw_MsgData *data){
|
||||
free(data);
|
||||
}
|
||||
|
||||
static struct cw_MsgData * msgdata_create(){
|
||||
static struct cw_MsgData * msgdata_create(int type){
|
||||
struct cw_MsgData * msg;
|
||||
|
||||
msg = malloc( sizeof(struct cw_MsgData));
|
||||
@ -78,7 +78,7 @@ static struct cw_MsgData * msgdata_create(){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
msg->type=type;
|
||||
return msg;
|
||||
}
|
||||
|
||||
@ -179,7 +179,6 @@ static int update_msgdata(struct cw_MsgSet * set, struct cw_MsgData * msgdata,
|
||||
elemdef->id,
|
||||
elemdef->vendor,
|
||||
handler->name
|
||||
|
||||
DBG_END
|
||||
}
|
||||
|
||||
@ -226,13 +225,18 @@ int cw_msgset_add(struct cw_MsgSet * set,
|
||||
msg = mavl_find_ptr(set->messages,&search);
|
||||
|
||||
if (!msg){
|
||||
msg = msgdata_create();
|
||||
msg = msgdata_create(msgdef->type);
|
||||
|
||||
if (!msg){
|
||||
cw_log(LOG_ERR,"Can't create messae");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
mavl_add_ptr(set->messages,msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Overwrite the found message */
|
||||
if (msgdef->name)
|
||||
msg->name=msgdef->name;
|
||||
@ -243,36 +247,21 @@ int cw_msgset_add(struct cw_MsgSet * set,
|
||||
DBG_START(NULL,DBG_INFO)
|
||||
"Add message Type:%d - %s ",msgdef->type,msgdef->name
|
||||
DBG_END
|
||||
|
||||
|
||||
|
||||
update_msgdata(set,msg,msgdef);
|
||||
}
|
||||
|
||||
DBG_START(NULL,DBG_INFO) "Hello world" DBG_END
|
||||
exit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
struct cw_ElemHandler * cw_message_set_find_element(
|
||||
struct cw_MsgSet * set,
|
||||
struct cw_ElemHandler * element){
|
||||
return mavl_find(set->all_elems_by_id,element);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
mlist_t cw_msgset_get_msg(struct cw_MsgSet * set, int type){
|
||||
/**
|
||||
* @brief Find message data to a specific message
|
||||
* @param set message set
|
||||
* @param type message type to search for
|
||||
* @return message data or NULL if not found
|
||||
*/
|
||||
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type){
|
||||
struct cw_MsgData search;
|
||||
search.type = type;
|
||||
struct cw_MsgData * result = mavl_find(set->messages,&search);
|
||||
if (!result){
|
||||
printf ("no result\n");
|
||||
return NULL;
|
||||
|
||||
}
|
||||
return result->elements_list;
|
||||
search.type=type;
|
||||
return mavl_find_ptr(set->messages,&search);
|
||||
}
|
||||
*/
|
||||
|
@ -68,8 +68,7 @@ extern void cw_msgset_destroy(struct cw_MsgSet * set);
|
||||
extern int cw_msgset_add(struct cw_MsgSet * set,
|
||||
struct cw_MsgDef messages[], struct cw_ElemHandler handlers[]);
|
||||
mlist_t cw_msgset_get_msg(struct cw_MsgSet * set, int type);
|
||||
|
||||
|
||||
struct cw_MsgData * cw_msgset_get_msgdata(struct cw_MsgSet *set,int type);
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user