Added lots of RPC cmds added. send is possible.

This commit is contained in:
2022-08-28 09:06:15 +02:00
parent 62616b5e7b
commit a77023165b
22 changed files with 452 additions and 168 deletions

View File

@ -59,6 +59,7 @@ CWSRC=\
cw_type_ipaddress.c\
cw_type_word.c\
cw_type_sysptr.c\
cw_type_array.c\
cw_write_descriptor_subelem.c\
cw_write_radio_element.c\
cw_detect_nat.c\

View File

@ -86,12 +86,12 @@ enum radioelems {
};
/** IEEE 802.11 Radio Information Message Element */
#define CAPWAP80211_ELEM_WTP_RADIO_INFORMATION 1048
/** IEEE 802.11 Antenna Message element */
#define CAPWAP80211_ELEM_ANTENNA 1025
/** IEEE 802.11 WTP Radio Configuration */
#define CAPWAP80211_ELEM_WTP_RADIO_CONFIGURATION 1046
/** IEEE 802.11 Radio Information Message Element */
#define CAPWAP80211_ELEM_WTP_RADIO_INFORMATION 1048
/**

View File

@ -129,6 +129,16 @@ int cw_cfg_set(cw_Cfg_t * cfg, const char *key, const char *val)
return -1;
}
void cw_cfg_del(cw_Cfg_t * cfg, const char *key)
{
struct cw_Cfg_entry e;
e.key = key;
e.val=NULL;
mavl_del(cfg->cfg,&e);
}
const char *cw_cfg_get(cw_Cfg_t * cfg, const char *key, const char *def)
{
struct cw_Cfg_entry e, *r;
@ -193,7 +203,7 @@ void cw_cfg_dump(cw_Cfg_t * cfg)
}
}
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg)
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg, const char *filter)
{
mavliter_t it;
struct cw_Cfg_entry *e;
@ -201,6 +211,13 @@ void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg)
mavliter_foreach(&it) {
e = mavliter_get(&it);
if (filter != NULL){
if (strlen(filter)){
if (strstr(e->key,filter)==NULL){
continue;
}
}
}
fprintf(f,"%s: '%s'\n", e->key, e->val);
}
}
@ -814,22 +831,43 @@ void cw_cfg_clear(cw_Cfg_t *cfg)
int cw_cfg_base_exists(cw_Cfg_t * cfg, const char *key)
{
struct cw_Cfg_entry e, *result;
//cw_dbg(DBG_X,"LOOX FOR: %s",key);
e.key=key;
result = mavl_get_first(cfg->cfg,&e);
if (result == NULL)
return 0;
//cw_dbg(DBG_X,"BASEXXX: %s",result->key);
int rl,kl;
char skey[CW_CFG_MAX_KEY_LEN];
char * delimiters = "/.";
char * d;
if (strlen(result->key)<strlen(key))
return 0;
//cw_dbg(DBG_X,"BASEXXX1: %d",strlen(key));
if (result->key[strlen(key)]!='/' && result->key[strlen(key)]!='.')
return 0;
//cw_dbg(DBG_X,"BASEXXX2: ");
if (strncmp(result->key,key,strlen(key))==0)
/* can we find the base exactly ?*/
if (cw_cfg_get(cfg,key,NULL)!=NULL)
return 1;
cw_dbg(DBG_X,"BASEXXX3: ");
for(d=delimiters; *d!=0; d++){
sprintf(skey,"%s%c",key,*d);
e.key=skey;
result = mavl_get_first(cfg->cfg,&e);
/* if we've found nothing, we can't check more */
if (result == NULL)
continue;
rl = strlen(result->key);
kl = strlen(skey);
/* if result key is shorter than key */
if (rl<kl)
continue;
/* both keys are identical in length */
if (rl==kl){
if (strcmp(result->key,key)==0)
return 1;
}
if (strncmp(result->key,skey,kl)==0)
return 1;
}
return 0;
}

View File

@ -81,8 +81,10 @@ int cw_cfg_base_exists_l(cw_Cfg_t ** cfgs, const char *key);
int cw_cfg_save(const char *filename, cw_Cfg_t *cfg, const char *format, ...);
uint16_t cw_cfg_get_word_l(cw_Cfg_t ** cfg, const char *key, uint16_t def);
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg);
void cw_cfg_fdump(FILE *f, cw_Cfg_t * cfg, const char *filter);
int cw_cfg_read_from_string(const char *str, cw_Cfg_t *cfg);
void cw_cfg_del(cw_Cfg_t * cfg, const char *key);

View File

@ -34,7 +34,7 @@ cw_dbg(DBG_X,"Her is the Key: %s %s\n",key,e[i].name);
b = cw_cfg_base_exists_l(params->cfg_list,handler->key);
if (!b){
stop();
//stop();
continue;
}
start = params->msgset->header_len(handler);

View File

@ -20,6 +20,7 @@
#include "cw.h"
#include "val.h"
#include "dbg.h"
static cw_Val_t *get(cw_Val_t * data, const uint8_t * src, int len)
{
@ -126,38 +127,47 @@ static int cast(cw_Val_t * data)
static int bread(cw_Cfg_t *cfg, const char * key, const uint8_t *src, int len, const void *param)
{
uint8_t n,l;
char skey[MAX_KEY_LEN];
uint8_t n,i;
int l;
char skey[CW_CFG_MAX_KEY_LEN];
const struct cw_ValArrayDef * def = param;
n = cw_get_byte(src);
l=1;
for (i=0; i<n; i++){
// struct cw_Type *type=(struct cw_Type*)param;
const int (*fun)(cw_Cfg_t*,const char *k,const uint8_t *s,int len,const void *p,int *l) = def->get_count;
n = fun(cfg,key,src,len,param,&l);
for (i=0; i<n && l<len; i++){
sprintf(skey,"%s.%d",key,i);
l+=CW_TYPE_STRUCT->read(cfg,skey,src,len,param);
// printf("SKEY: %s\n",skey);
l+=def->type->read(cfg,skey,src,len,def->param);
}
return l;
/*
uint8_t val;
cw_ValValRange_t * valrange = (cw_ValValRange_t *) param;
const char *str;
val = cw_get_byte(src);
str = get_guardstr(val, valrange);
if (str != NULL)
cw_cfg_set(cfg,key,str);
else
cw_cfg_set_int(cfg,key,val);
return 1;
*/
}
static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void * param)
{
return cw_generic_write_l(cfgs,CW_TYPE_BYTE,key,dst,param);
int i,l;
char skey[CW_CFG_MAX_KEY_LEN];
const struct cw_ValArrayDef * def = param;
const int (*fun)(cw_Cfg_t**,const char *k, uint8_t *s,const void *p,int l) = def->put_count;
i=0,l=0;
do {
sprintf(skey,"%s.%d",key,i);
i++;
if (cw_cfg_get_l(cfgs,skey,NULL)==NULL){
break;
}
l+=def->type->write(cfgs,skey,dst,def->param);
}while(1);
// printf("LEN: %d pl: %d\n",l,n);
fun(cfgs,key,dst,param,l);
return l;
}
const struct cw_Type cw_type_array = {

View File

@ -81,6 +81,7 @@ static int write_struct(cw_Cfg_t ** cfgs, const cw_ValStruct_t * stru, const ch
int pos, i;
const char * result;
int wrlen;
int rc;
cw_Val_t val;
memset(&val,0,sizeof(cw_Val_t));
@ -100,7 +101,9 @@ static int write_struct(cw_Cfg_t ** cfgs, const cw_ValStruct_t * stru, const ch
else
sprintf(key,"%s",pkey);
result = cw_cfg_get_l(cfgs,key,NULL);
// result = cw_cfg_get_l(cfgs,key,NULL);
rc = cw_cfg_base_exists_l(cfgs,key);
// printf("Base? :%s, %d\n",key,rc);
if(result) {
// char s[2048];
// result->type->to_str(result,s,2048);
@ -108,9 +111,14 @@ static int write_struct(cw_Cfg_t ** cfgs, const cw_ValStruct_t * stru, const ch
}
if (result == NULL){
if (!rc){
int l;
cw_log(LOG_ERR,"Can't put %s, no value found, filling wth zeros.",key);
memset(dst+pos,0,stru[i].len);
l = stru[i].len;
if (l==-1)
l = 0;
memset(dst+pos,0,l);
}
else{
struct cw_Type * type;

View File

@ -90,7 +90,8 @@ static struct cw_StrListElem theme0[] = {
{DBG_RFC, ANSI_BRED},
{DBG_X, "\x1b[31m"},
{DBG_WARN, ANSI_CYAN},
{DBG_MOD, ANSI_WHITE},
{DBG_MOD_DETAIL, ANSI_WHITE},
{DBG_MOD, ANSI_BBLACK ANSI_BOLD },
// {DBG_CFG_DMP, ANSI_BCYAN },
{DBG_CFG_UPDATES,ANSI_GREEN},
@ -117,23 +118,24 @@ static struct cw_StrListElem color_off[] = {
*/
static struct cw_StrListElem prefix[] = {
{DBG_INFO, "Info -"},
{DBG_PKT_IN, "Pkt In -"},
{DBG_PKT_OUT, "Pkt Out -"},
{DBG_INFO, "Info - "},
{DBG_PKT_IN, "Pkt In - "},
{DBG_PKT_OUT, "Pkt Out - "},
{DBG_MSG_IN, "Msg In - "},
{DBG_MSG_OUT, "Msg Out - "},
{DBG_ELEM_IN, " Msg Element -"},
{DBG_ELEM_OUT, " Msg Element -"},
{DBG_ELEM_IN, " Msg Element - "},
{DBG_ELEM_OUT, " Msg Element - "},
{DBG_MSG_ERR, " Msg Error -"},
{DBG_PKT_ERR, " Pkt Error -"},
{DBG_ELEM_ERR, " Elem Error -"},
{DBG_RFC, " RFC -"},
{DBG_MSG_ERR, " Msg Error - "},
{DBG_PKT_ERR, " Pkt Error - "},
{DBG_ELEM_ERR, " Elem Error - "},
{DBG_RFC, " RFC - "},
{DBG_DTLS, "DTLS - "},
{DBG_DTLS_DETAIL, "DTLS - "},
{DBG_WARN, " Warning - "},
{DBG_MOD, "Mod - "},
{DBG_MOD_DETAIL, "Mod - "},
{DBG_STATE, "STATEMACHINE - "},
{DBG_CFG_UPDATES, "Cfg - "},

View File

@ -125,6 +125,9 @@ enum cw_dbg_levels{
DBG_X = (1<<30),
DBG_MOD_DETAIL = (1<<31),
DBG_ALL = (0x7fffffff),

View File

@ -65,6 +65,7 @@ struct cw_StrListElem cw_dbg_strings[] = {
{ DBG_DTLS_DETAIL, "dtls_detail"},
{ DBG_CFG_UPDATES, "cfg_updates" },
{ DBG_X, "x" },
// {DBG_CFG_DMP, "cfg_dmp" },

View File

@ -41,8 +41,8 @@ int cw_encode_elements(struct cw_ElemHandlerParams *params, mlist_t elements_lis
if (!data->mand){
if (!cw_cfg_base_exists(params->cfg_list[0],handler->key)){
cw_dbg(DBG_MSG_COMPOSE," Add Elem: %d %d %d %s - (skip)",
data->proto, data->vendor, data->id, handler->name);
cw_dbg(DBG_MSG_COMPOSE," Add Elem: %d %d %d %s %s - (skip)",
data->proto, data->vendor, data->id, handler->name, handler->key);
continue;
}

View File

@ -139,14 +139,14 @@ struct cw_Mod *cw_mod_load(const char *mod_name, cw_Cfg_t * global_cfg, int role
/* Search for the module in mods_loaded, to see if it is
* already loaded or was statically linked */
cw_dbg(DBG_MOD, "MOD: Load module '%s'", mod_name);
cw_dbg(DBG_MOD, "Loading module '%s'.", mod_name);
memset(&search, 0, sizeof(search));
search.name = mod_name;
mod = mavl_get_ptr(mods_loaded, &search);
if (mod) {
cw_dbg(DBG_MOD, "MOD: Module already loaded '%s'", mod_name);
cw_dbg(DBG_MOD, "Module already loaded: '%s'.", mod_name);
return mod;
}
@ -165,7 +165,7 @@ struct cw_Mod *cw_mod_load(const char *mod_name, cw_Cfg_t * global_cfg, int role
if (filename == NULL)
return NULL;
cw_dbg(DBG_MOD, "MOD: loading module from file: %s", filename);
cw_dbg(DBG_MOD, "Loading module from file: %s", filename);
/* Open the DLL */
handle = dlopen(filename, RTLD_NOW);
@ -189,7 +189,7 @@ struct cw_Mod *cw_mod_load(const char *mod_name, cw_Cfg_t * global_cfg, int role
goto errX;
}
cw_dbg(DBG_MOD, "MOD: %s sucessfull loaded, calling init now.", filename);
cw_dbg(DBG_MOD, "Module %s sucessfull loaded, calling init now.", filename);
if (!mod->init(mod, global_cfg, role)){
dlclose(handle);
mod=NULL;

View File

@ -223,7 +223,7 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
break;
continue;
case CW_DELETE:
cw_dbg(DBG_MOD, " deleting message element %d %d %d - %s",
cw_dbg(DBG_MOD_DETAIL, " deleting message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor, elemdef->id, handler->name);
@ -248,11 +248,11 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
result = mavl_replace(msgdata->elements_tree, &ed, &replaced);
if (!replaced) {
cw_dbg(DBG_MOD, " adding message element %d %d %d - %s",
cw_dbg(DBG_MOD_DETAIL, " adding message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor, elemdef->id, handler->name);
} else {
cw_dbg(DBG_MOD, " replacing message element %d %d %d - %s",
cw_dbg(DBG_MOD_DETAIL, " replacing message element %d %d %d - %s",
elemdef->proto,
elemdef->vendor, elemdef->id, handler->name);
}
@ -275,7 +275,7 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
result->vendor, result->id);
if (result->mand){
mlist_append_ptr(msgdata->mand_keys,(void*)handler->key);
cw_dbg(DBG_MOD," Add mandatory key: %s",handler->key);
cw_dbg(DBG_MOD_DETAIL," Add mandatory key: %s",handler->key);
}
/*//printf("Have Result %d %d - %s\n",result->id,result->mand, handler->key);*/
}
@ -294,7 +294,7 @@ int cw_msgset_add(struct cw_MsgSet *set,
struct cw_MsgDef *msgdef;
/* Create mavl for all handlers */
for (handler = handlers; handler->id; handler++) {
cw_dbg(DBG_MOD, "Adding handler for element %d - %s - with key: %s",
cw_dbg(DBG_MOD_DETAIL, "Adding handler for element %d - %s - with key: %s",
handler->id, handler->name, handler->key);
mavl_replace(set->handlers_by_id, handler, NULL);
mavl_replace(set->handlers_by_key, handler, NULL);
@ -339,7 +339,7 @@ int cw_msgset_add(struct cw_MsgSet *set,
msg->receiver = msgdef->receiver;
cw_dbg(DBG_MOD, "Add message Type:%d - %s ", msgdef->type, msgdef->name);
cw_dbg(DBG_MOD_DETAIL, "Add message Type:%d - %s ", msgdef->type, msgdef->name);
update_msgdata(set, msg, msgdef);
@ -376,7 +376,7 @@ int cw_msgset_add_states(struct cw_MsgSet * set, cw_StateMachineState_t * states
else{
repstr = "Adding";
}
cw_dbg(DBG_MOD,"%s machine state : [%s->%s]",repstr,
cw_dbg(DBG_MOD_DETAIL,"%s machine state : [%s->%s]",repstr,
cw_strstate(s->prevstate),
cw_strstate(s->state));
s++;

View File

@ -157,6 +157,7 @@ extern const struct cw_Type cw_type_ipaddress;
extern const struct cw_Type cw_type_sysptr;
extern const struct cw_Type cw_type_bool;
extern const struct cw_Type cw_type_struct;
extern const struct cw_Type cw_type_array;
#define CW_TYPE_BYTE (&cw_type_byte)
#define CW_TYPE_WORD (&cw_type_word)
@ -168,6 +169,15 @@ extern const struct cw_Type cw_type_struct;
#define CW_TYPE_STR (&cw_type_str)
#define CW_TYPE_BOOL (&cw_type_bool)
#define CW_TYPE_STRUCT (&cw_type_struct)
#define CW_TYPE_ARRAY (&cw_type_array)
struct cw_ValArrayDef{
void * get_count;
void * put_count;
const struct cw_Type * type;
void *param;
};
/*
void cw_kvstore_mavl_delete(const void *data);