Fixed some bugs, added more Cisco elements
Almost able to create a WLAN
This commit is contained in:
25
src/cw/cfg.c
25
src/cw/cfg.c
@ -584,7 +584,12 @@ void cw_cfg_iter_init(cw_Cfg_t * cfg, struct cw_Cfg_iter *cfi, const char *base)
|
||||
search.key = base;
|
||||
|
||||
mavliter_init(&(cfi->it), cfg->cfg);
|
||||
mavliter_seek(&(cfi->it), &search, 0);
|
||||
if (base == NULL){
|
||||
mavliter_seek_set(&(cfi->it));
|
||||
mavliter_next(&(cfi->it));
|
||||
}
|
||||
else
|
||||
mavliter_seek(&(cfi->it), &search, 0);
|
||||
cfi->base = base;
|
||||
}
|
||||
|
||||
@ -594,12 +599,12 @@ struct cw_Cfg_entry *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *nnkey
|
||||
struct cw_Cfg_entry *e;
|
||||
int bl, kl;
|
||||
const char *d;
|
||||
|
||||
e = mavliter_get(&(cfi->it));
|
||||
if (e == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cfi->base ==NULL)
|
||||
goto eeX;
|
||||
|
||||
bl = strlen(cfi->base);
|
||||
kl = strlen(e->key);
|
||||
@ -623,7 +628,7 @@ struct cw_Cfg_entry *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *nnkey
|
||||
|
||||
if (strncmp(cfi->base, e->key, bl) != 0)
|
||||
return NULL;
|
||||
|
||||
eeX:
|
||||
mavliter_next(&(cfi->it));
|
||||
return e;
|
||||
}
|
||||
@ -739,25 +744,25 @@ int cw_cfg_get_first_index(cw_Cfg_t * cfg, const char *key, int n)
|
||||
char ikey[CW_CFG_MAX_KEY_LEN];
|
||||
struct cw_Cfg_entry search, * result;
|
||||
char *d;
|
||||
int l;
|
||||
|
||||
sprintf(ikey,"%s.%d",key,n);
|
||||
|
||||
search.key=ikey;
|
||||
|
||||
result = mavl_get_first(cfg->cfg,&search);
|
||||
if (result == NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
d = strrchr(result->key,'.');
|
||||
|
||||
d = strrchr(ikey,'.');
|
||||
if (d==NULL){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strncmp(result->key,ikey,d-result->key)!=0)
|
||||
l = d-ikey;
|
||||
if (strncmp(result->key,ikey,l)!=0)
|
||||
return -1;
|
||||
|
||||
return atoi(d+1);
|
||||
return atoi(result->key+l+1);
|
||||
}
|
||||
|
||||
int cw_cfg_get_first_index_l(cw_Cfg_t ** cfgs, const char *key, int n)
|
||||
|
@ -554,7 +554,6 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
|
||||
* Put further actions here, if needed.
|
||||
*/
|
||||
}
|
||||
|
||||
if (params.unrecognized)
|
||||
mlist_destroy(params.unrecognized);
|
||||
cw_cfg_destroy(params.cfg);
|
||||
|
181
src/cw/cw.c
181
src/cw/cw.c
@ -36,10 +36,9 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
|
||||
|
||||
|
||||
|
||||
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst)
|
||||
int cw_out_generic0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst,const char *key)
|
||||
{
|
||||
|
||||
int start, len, l;
|
||||
|
||||
// cw_dbg(DBG_X,"cw_out_generic (%s)%s",((struct cw_Type*)handler->type)->name,handler->key);
|
||||
@ -49,19 +48,21 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
|
||||
// cw_dbg(DBG_X,"Generic out!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDDUMP");
|
||||
//
|
||||
//
|
||||
if (!cw_cfg_base_exists(params->cfg_list[0],handler->key)){
|
||||
cw_dbg(DBG_MSG_COMPOSE," Add Elem: %d %d %d %s %s - (skip)",
|
||||
params->elemdata->proto,
|
||||
params->elemdata->vendor,
|
||||
params->elemdata->id,
|
||||
handler->name, handler->key);
|
||||
return 0;
|
||||
}
|
||||
if (!params->elemdata->mand){
|
||||
if (!cw_cfg_base_exists(params->cfg_list[0],key)){
|
||||
cw_dbg(DBG_MSG_COMPOSE," Add Elem: %d %d %d %s %s - (bskip)",
|
||||
params->elemdata->proto,
|
||||
params->elemdata->vendor,
|
||||
params->elemdata->id,
|
||||
handler->name, key);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
start = params->msgset->header_len(handler);
|
||||
len = ((const cw_Type_t*)(handler->type))->
|
||||
write(params->cfg_list,handler->key,dst+start,handler->param);
|
||||
write(params->cfg_list,key,dst+start,handler->param);
|
||||
// cw_dbg(DBG_X, "Type result is %d",len);
|
||||
|
||||
if (len == -1) {
|
||||
@ -73,7 +74,7 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
|
||||
cw_log(LOG_ERR,
|
||||
"Can't put mandatory element %s %d-(%s) into %s. No value for '%s' found.",
|
||||
vendor, handler->id, handler->name, params->msgdata->name
|
||||
, handler->key
|
||||
, key
|
||||
);
|
||||
}
|
||||
else{
|
||||
@ -90,6 +91,15 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
|
||||
l = params->msgset->write_header(handler,dst,len);
|
||||
|
||||
return l;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst)
|
||||
{
|
||||
return cw_out_generic0(handler,params,dst,handler->key);
|
||||
}
|
||||
|
||||
|
||||
@ -314,3 +324,148 @@ cw_put_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
|
||||
|
||||
return d-dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int cw_out_traverse0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst, int i, const char *current, const char * next,
|
||||
int * stack)
|
||||
{
|
||||
char *sl;
|
||||
int l;
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int len;
|
||||
len = 0;
|
||||
|
||||
printf("Next: %s\n", next);
|
||||
|
||||
sl = strchr(next,'/');
|
||||
if (sl==NULL){
|
||||
cw_Val_t * result;
|
||||
sprintf(key,"%s/%s",current,next);
|
||||
result = cw_ktv_base_exists(params->cfg,key);
|
||||
if (result != NULL){
|
||||
int offset;
|
||||
int i,l;
|
||||
offset = params->msgset->header_len(handler);
|
||||
printf("Yea! We can do it: %s\n",result->key);
|
||||
for (i=0;i<stack[0];i++){
|
||||
printf("I=%i\n",stack[i+1]);
|
||||
}
|
||||
l= cw_ktv_write_struct(params->cfg,params->cfg,
|
||||
handler->type,key,dst+offset);
|
||||
|
||||
printf("Write struct len %i\n",l);
|
||||
|
||||
l=params->msgset->write_header(handler,dst,l);
|
||||
printf("header wr len %d\n",l);
|
||||
if (handler->patch){
|
||||
handler->patch(dst+offset,stack);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(key,current);
|
||||
|
||||
printf("current is %s\n", current);
|
||||
|
||||
if (key[0!=0])
|
||||
strcat(key,"/");
|
||||
l = sl - next;
|
||||
strncat(key,next,l);
|
||||
|
||||
|
||||
printf("Here we are %s\n",key);
|
||||
cw_dbg_ktv_dump(params->cfg,DBG_INFO,"start"," ", "end" );
|
||||
i=-1;
|
||||
while(1){
|
||||
char basekey[CW_CFG_MAX_KEY_LEN];
|
||||
cw_Val_t * result;
|
||||
|
||||
i = cw_ktv_idx_get_next(params->cfg,key,i+1);
|
||||
|
||||
if (i==-1)
|
||||
break;
|
||||
sprintf(basekey,"%s.%d",key,i);
|
||||
printf("Our basekey is %s\n",basekey);
|
||||
result = cw_ktv_base_exists(params->cfg,basekey);
|
||||
if (result == NULL){
|
||||
continue;
|
||||
}
|
||||
|
||||
stack[0]++;
|
||||
stack[stack[0]]=i;
|
||||
len += cw_out_traverse0(handler,params,dst+len,-1,basekey,next+l+1, stack);
|
||||
printf("Len is now %d\n", len);
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
int cw_out_traverse(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst)
|
||||
|
||||
{
|
||||
/* char current[CW_CFG_MAX_KEY_LEN];
|
||||
int stack[10];
|
||||
stack[0]=0;
|
||||
current[0]=0;
|
||||
// return cw_out_traverse0(handler,params,dst,-1,current,handler->key, stack);*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int walk0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst, const char *current, const char * next)
|
||||
{
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
const char *sl;
|
||||
int rc;
|
||||
int len=0;
|
||||
|
||||
/* Is this the last key ? */
|
||||
sl = strchr(next,'/');
|
||||
if (sl){
|
||||
char basekey[CW_CFG_MAX_KEY_LEN+13];
|
||||
int i,l;
|
||||
strcpy(key,current);
|
||||
l = sl - next;
|
||||
strncat(key,next,l);
|
||||
|
||||
for (i=0; (i=cw_cfg_get_first_index_l(params->cfg_list,key,i))!=-1; i++){
|
||||
sprintf(basekey,"%s.%d%c",key,i, *(sl+1) ?'/':'\0');
|
||||
rc = walk0(handler,params,dst,basekey,next+l+1);
|
||||
if (rc>0)
|
||||
len+=rc;
|
||||
}
|
||||
return len;
|
||||
|
||||
}
|
||||
|
||||
printf("Final %s [%s]\n",current,next);
|
||||
return cw_out_generic0(handler,params,dst,current);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int cw_out_generic_walk(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst)
|
||||
{
|
||||
char current[CW_CFG_MAX_KEY_LEN];
|
||||
// int stack[10];
|
||||
// stack[0]=0;
|
||||
current[0]=0;
|
||||
|
||||
return walk0(handler,params,dst,current,handler->key);
|
||||
}
|
||||
|
||||
|
@ -558,6 +558,8 @@ int cw_put_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
|
||||
|
||||
|
||||
int cw_send_request(struct cw_Conn *conn,int msg_id);
|
||||
int cw_out_generic_walk(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst);
|
||||
|
||||
/**
|
||||
*@}
|
||||
|
@ -42,106 +42,8 @@ int cw_out_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemH
|
||||
|
||||
cdst+=params->msgset->write_header(handler,cdst,l);
|
||||
}
|
||||
return cdst-dst;
|
||||
return cdst-dst;*/
|
||||
}
|
||||
|
||||
|
||||
int cw_out_traverse0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst, int i, const char *current, const char * next,
|
||||
int * stack)
|
||||
{
|
||||
char *sl;
|
||||
int l;
|
||||
char key[CW_CFG_MAX_KEY_LEN];
|
||||
int len;
|
||||
len = 0;
|
||||
|
||||
printf("Next: %s\n", next);
|
||||
|
||||
sl = strchr(next,'/');
|
||||
if (sl==NULL){
|
||||
cw_Val_t * result;
|
||||
sprintf(key,"%s/%s",current,next);
|
||||
result = cw_ktv_base_exists(params->cfg,key);
|
||||
if (result != NULL){
|
||||
int offset;
|
||||
int i,l;
|
||||
offset = params->msgset->header_len(handler);
|
||||
printf("Yea! We can do it: %s\n",result->key);
|
||||
for (i=0;i<stack[0];i++){
|
||||
printf("I=%i\n",stack[i+1]);
|
||||
}
|
||||
l= cw_ktv_write_struct(params->cfg,params->cfg,
|
||||
handler->type,key,dst+offset);
|
||||
|
||||
printf("Write struct len %i\n",l);
|
||||
|
||||
l=params->msgset->write_header(handler,dst,l);
|
||||
printf("header wr len %d\n",l);
|
||||
if (handler->patch){
|
||||
handler->patch(dst+offset,stack);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
strcpy(key,current);
|
||||
|
||||
printf("current is %s\n", current);
|
||||
|
||||
if (key[0!=0])
|
||||
strcat(key,"/");
|
||||
l = sl - next;
|
||||
strncat(key,next,l);
|
||||
|
||||
|
||||
printf("Here we are %s\n",key);
|
||||
cw_dbg_ktv_dump(params->cfg,DBG_INFO,"start"," ", "end" );
|
||||
i=-1;
|
||||
while(1){
|
||||
char basekey[CW_CFG_MAX_KEY_LEN];
|
||||
cw_Val_t * result;
|
||||
|
||||
i = cw_ktv_idx_get_next(params->cfg,key,i+1);
|
||||
|
||||
if (i==-1)
|
||||
break;
|
||||
sprintf(basekey,"%s.%d",key,i);
|
||||
printf("Our basekey is %s\n",basekey);
|
||||
result = cw_ktv_base_exists(params->cfg,basekey);
|
||||
if (result == NULL){
|
||||
continue;
|
||||
}
|
||||
|
||||
stack[0]++;
|
||||
stack[stack[0]]=i;
|
||||
len += cw_out_traverse0(handler,params,dst+len,-1,basekey,next+l+1, stack);
|
||||
printf("Len is now %d\n", len);
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cw_out_traverse(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst)
|
||||
|
||||
{
|
||||
|
||||
//char current[CW_CFG_MAX_KEY_LEN];
|
||||
//int stack[10];
|
||||
//stack[0]=0;
|
||||
|
||||
//current[0]=0;
|
||||
|
||||
//stop();
|
||||
return 0;
|
||||
|
||||
// return cw_out_traverse0(handler,params,dst,-1,current,handler->key, stack);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ int cw_setup_dtls(struct cw_Conn *conn, cw_Cfg_t * cfg, const char *prefix,
|
||||
sprintf(key, "%s/%s", prefix, "ssl-cipher");
|
||||
conn->dtls_cipher = cw_cfg_get(cfg, key, default_cipher);
|
||||
|
||||
cw_dbg(DBG_DTLS,"Using cipher: %s",conn->dtls_cipher);
|
||||
|
||||
sprintf(key, "%s/%s", prefix, "ssl-psk");
|
||||
conn->dtls_psk = (bstr16_t)cw_cfg_get(cfg, key, NULL);
|
||||
|
||||
|
@ -158,6 +158,7 @@ static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void *
|
||||
i=0,l=0;
|
||||
do {
|
||||
sprintf(skey,"%s.%d",key,i);
|
||||
// printf("iSKEY %s\n",skey);
|
||||
i++;
|
||||
if (cw_cfg_get_l(cfgs,skey,NULL)==NULL){
|
||||
break;
|
||||
@ -165,7 +166,7 @@ static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void *
|
||||
l+=def->type->write(cfgs,skey,dst,def->param);
|
||||
}while(1);
|
||||
|
||||
// printf("LEN: %d pl: %d\n",l,n);
|
||||
// printf("LEN: %d (K: %s)\n",l,key);
|
||||
fun(cfgs,key,dst,param,l);
|
||||
return l;
|
||||
}
|
||||
|
@ -113,12 +113,13 @@ static int write_struct(cw_Cfg_t ** cfgs, const cw_ValStruct_t * stru, const ch
|
||||
|
||||
if (!rc){
|
||||
int l;
|
||||
cw_log(LOG_ERR,"Can't put %s, no value found, filling wth zeros.",key);
|
||||
cw_log(LOG_ERR,"Can't put %s, no value found, filling with zeros.",key);
|
||||
l = stru[i].len;
|
||||
if (l==-1)
|
||||
l = 0;
|
||||
|
||||
memset(dst+pos,0,l);
|
||||
wrlen=l;
|
||||
}
|
||||
else{
|
||||
struct cw_Type * type;
|
||||
|
@ -122,7 +122,7 @@ struct cw_dbg_cfgstrs cw_dbg_cfgstrs[] = {
|
||||
{"elem_err",DBG_ELEM_ERR},
|
||||
|
||||
{"dtls",DBG_DTLS},
|
||||
{"dtls_dietail",DBG_DTLS_DETAIL},
|
||||
{"dtls_detail",DBG_DTLS_DETAIL},
|
||||
{"dtls_bio",DBG_DTLS_BIO},
|
||||
{"dtls_bio_dmp",DBG_DTLS_BIO_DMP},
|
||||
|
||||
|
Reference in New Issue
Block a user