More work on typeless

This commit is contained in:
7u83 2022-08-13 09:47:12 +02:00
parent add6ffa314
commit 370942ef7e
69 changed files with 1030 additions and 507 deletions

View File

@ -19,6 +19,7 @@ enum {
AC_PROTO_UNKNOWN
};
void start_shell();
#endif

View File

@ -175,19 +175,27 @@ int main (int argc, char *argv[])
{
int rc = 0;
struct bootcfg bootcfg;
FILE * file;
mavl_t types_tree;
const cw_Type_t **ti;
/*
cw_Cfg_t * tcfg = cw_cfg_create();
cw_cfg_set(tcfg,"tube.0","hallo");
cw_cfg_set(tcfg,"tube.1","welt");
cw_cfg_set(tcfg,"tube.2","der guten laune");
cw_cfg_dump(tcfg);
printf("Next Index: %d\n",cw_cfg_get_next_index(tcfg,"kinder"));
exit(0);
*/
/* parse arguments */
parse_args (argc, argv, &bootcfg);
cw_statemachine_run(NULL);
exit(0);
global_cfg=cw_cfg_create();
if (!global_cfg){
@ -250,12 +258,6 @@ void process_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer, in
void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer, int len);
static void pcb(char *dst, struct mavlnode *node)
{
struct cw_Cfg_entry *e = mavlnode_dataptr(node);
sprintf(dst, "%s", e->key);
}
int ac_run(cw_Cfg_t * cfg)
{
@ -441,7 +443,7 @@ void process_cw_data_packet (int index, struct sockaddr *addr, uint8_t * buffer,
dataman_list_unlock();
dataman_add_packet (dm, buffer, len);
//dataman_add_packet (dm, buffer, len);
return;
@ -505,7 +507,7 @@ void process_cw_ctrl_packet (int index, struct sockaddr *addr, uint8_t * buffer,
wtpman_start (wtpman, preamble & 0xf);
}
printf("Got Packet with len: %d\n",len);
//printf("Got Packet with len: %d\n",len);
wtpman_addpacket (wtpman, buffer, len);
wtplist_unlock();

View File

@ -37,3 +37,20 @@ actube/mod.0: cisco
actube/mod.1: capwap
actube/mod.2: capwap80211
ac-descriptor/dtls-policy: 1
ac-descriptor/hardware/vendor: 4232704
ac-descriptor/hardware/version: .x01000001
ac-descriptor/max-wtps : 200
ac-descriptor/active-wtps: 2
ac-descriptor/r-mac-field: 1
ac-descriptor/reserved1 : 0
ac-descriptor/security : 2
ac-descriptor/software/vendor : 0
ac-descriptor/software/version: v0.0.1
ac-descriptor/station-limit: 1000
ac-descriptor/stations: 0
capwap-control-ip-address/address.0: 192.168.0.14

View File

@ -45,34 +45,6 @@
#include "actube.h"
static void reset_echointerval_timer(struct wtpman *wtpman)
{
/* char sock_buf[SOCK_ADDR_BUFSIZE];*/
/* uint16_t ct = mbag_get_word(wtpman->conn->local, CW_ITEM_CAPWAP_TIMERS,
CW_MAX_DISCOVERY_INTERVAL << 8 |
CAPWAP_ECHO_INTERVAL);
*/
/* start echinterval timer and put 2 seconds for "safety" on it */
/*
// wtpman->echointerval_timer = cw_timer_start(2+ (ct & 0xff));
// db_ping_wtp(sock_addr2str_p(&wtpman->conn->addr,sock_buf), conf_acname);
// cw_dbg(DBG_X, "Starting capwap timer: %d", wtpman->echointerval_timer);
*/
}
/*
static int msg_start_handler(struct cw_Conn *conn, struct cw_action_in *a,
uint8_t * data, int len, struct sockaddr *from)
{
struct wtpman *wtpman = conn->data;
reset_echointerval_timer(wtpman);
return 0;
}
*/
static void wtpman_remove(struct wtpman *wtpman)
{
@ -86,9 +58,6 @@ static void wtpman_remove(struct wtpman *wtpman)
static void wtpman_run_discovery(void *arg)
{
cw_dbg(DBG_STATE,"Run discovery");
exit(0);
struct wtpman *wtpman = (struct wtpman *) arg;
@ -100,6 +69,7 @@ static void wtpman_run_discovery(void *arg)
&& wtpman->conn->capwap_state == CAPWAP_STATE_DISCOVERY) {
int rc;
rc = cw_read_messages(wtpman->conn);
if (cw_result_is_ok(rc)) {
wtpman->conn->capwap_state = CAPWAP_STATE_JOIN;
@ -141,7 +111,7 @@ static int wtpman_dtls_setup(void *arg)
return 1;
}
/*
static int wtpman_join(void *arg)
{
int rc;
@ -192,6 +162,9 @@ static int wtpman_join(void *arg)
}
*/
static void wtpman_image_data(struct wtpman *wtpman)
{
@ -312,7 +285,7 @@ int cw_run_state_machine(struct cw_Conn *conn, time_t * timer)
if (result->timer_key) {
timerval =
cw_ktv_get_word(conn->local_cfg, result->timer_key,
cw_cfg_get_word(conn->local_cfg, result->timer_key,
result->timer_default);
*timer = cw_timer_start(timerval);
cw_dbg(DBG_STATE, "Starting timer: [%s] - %d seconds.",
@ -338,7 +311,7 @@ static void *wtpman_main(void *arg)
wtpman->conn->seqnum = 0;
conn = wtpman->conn;
wtpman->conn->remote_cfg = cw_ktv_create();
wtpman->conn->remote_cfg = cw_cfg_create();
if (!wtpman->dtlsmode) {
@ -647,6 +620,41 @@ void wtpman_destroy(struct wtpman *wtpman)
free(wtpman);
}
static void discovery_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
{
struct wtpman * wtpman = (struct wtpman *)params->conn->data;
cw_dbg(DBG_X,"Discovery->Callback");
wtpman->pdiscovery(params,elems_ptr,elems_len);
}
static void join_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
{
struct wtpman * wtpman = (struct wtpman *)params->conn->data;
cw_dbg(DBG_X,"JOIN->Callback");
wtpman->pjoin(params,elems_ptr,elems_len);
}
static void update_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
{
struct wtpman * wtpman = (struct wtpman *)params->conn->data;
cw_dbg(DBG_X,"UPDATE->Callback");
if ( wtpman->pupdate )
wtpman->pupdate(params,elems_ptr,elems_len);
}
static setup_complete(struct cw_Conn *conn)
{
struct wtpman * wtpman = (struct wtpman *)conn->data;
wtpman->pdiscovery = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_DISCOVERY_REQUEST,discovery_cb);
wtpman->pjoin = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_JOIN_REQUEST,join_cb);
wtpman->pupdate = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,update_cb);
cw_dbg(DBG_X,"SETUP COMPLETE");
}
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
@ -662,8 +670,6 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
if (!wtpman)
return 0;
if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
int port = sock_getport(&socklist[socklistindex].addr);
@ -699,9 +705,11 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
wtpman_destroy(wtpman);
return NULL;
}
wtpman->conn->global_cfg = global_cfg;
wtpman->conn->local_cfg = cw_cfg_create();
wtpman->conn->role = CW_ROLE_AC;
wtpman->conn->data=wtpman;
wtpman->conn->data_sock = socklist[socklistindex].data_sockfd;
sock_copyaddr(&wtpman->conn->data_addr,
@ -712,6 +720,8 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
wtpman->conn->strict_capwap = conf_strict_capwap;
wtpman->conn->strict_hdr = conf_strict_headers;
wtpman->conn->setup_complete = setup_complete;
/*
// wtpman->conn->radios = mbag_i_create();
// wtpman->conn->radios_upd = mbag_i_create();
@ -722,9 +732,6 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
*/
wtpman->conn->local_cfg = cw_ktv_create();
wtpman->conn->global_cfg = global_cfg;
wtpman->conn->local_cfg = global_cfg;
/* when created caused by a packet in DTLS mode, we try
* to find out the modules to load, for detected connection
@ -742,15 +749,22 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
cw_mod_get_msg_set(wtpman->conn, cmod, bmod);
wtpman->conn->detected = 1;
cmod->setup_cfg(wtpman->conn);
if (wtpman->conn->setup_complete)
wtpman->conn->setup_complete(wtpman->conn);
}
}
cw_dbg(DBG_X,"WTPMAN_CREATED: %p",wtpman);
return wtpman;
}
void wtpman_addpacket(struct wtpman *wtpman, uint8_t * packet, int len)
{
cw_dbg(DBG_X,"ADD PACKET DETECTED %d",wtpman->conn->detected);
conn_q_add_packet(wtpman->conn, packet, len);
}

View File

@ -9,6 +9,7 @@
#include "cw/fragman.h"
#include "cw/timer.h"
#include "cw/cfg.h"
#include "cw/capwap.h"
#define WTPMAN_QSIZE 1024
@ -38,6 +39,12 @@ struct wtpman {
*/
cw_MsgCallbackFun pdiscovery;
cw_MsgCallbackFun pjoin;
cw_MsgCallbackFun pupdate;
};
/*

View File

@ -140,7 +140,7 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
bstr16_t bstr16_create(const uint8_t *data, uint16_t len);
uint8_t * bstr16_create_from_str(const char *s);
bstr16_t bstr16_create_from_str(const char *s);
extern uint8_t * bstr16_create_from_cfgstr(const char * s);
#define bstr16_replace bstr_replace

View File

@ -2,7 +2,7 @@
#include "format.h"
uint8_t * bstr16_create_from_str(const char *s)
bstr16_t bstr16_create_from_str(const char *s)
{
uint8_t * mem;
int msize;

View File

@ -1,18 +0,0 @@
#include "bstr.h"
/*
uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len)
{
uint8_t * str = malloc(bstrv_size(len));
if (!str)
return 0;
bstrv_set_vendor_id(str,vendor_id);
bstrv_set_len(str,len);
memcpy(bstrv_data(str),data,len);
*(bstrv_data(str)+bstrv_len(str))=0;
return str;
}
*/

View File

@ -3,10 +3,13 @@
#include <mavl.h>
#include "cw.h"
#include "cfg.h"
#include "val.h"
#include "cfg.h"
#include "dbg.h"
#include "log.h"
#include "cw.h"
static const char *nextc(const char *s)
{
@ -119,6 +122,30 @@ const char *cw_cfg_get(cw_Cfg_t * cfg, const char *key, const char *def)
return r->val;
}
const char *cw_cfg_get2(cw_Cfg_t *cfg1, cw_Cfg_t *cfg2, const char *key, const char *def)
{
return cw_cfg_get(cfg1, key, cw_cfg_get(cfg2,key,def));
}
bstr16_t cw_cfg_get_bstr16(cw_Cfg_t * cfg, const char * key, const char *def)
{
const char *s;
s = cw_cfg_get(cfg,key,def);
if(s==NULL)
return NULL;
return bstr16_create_from_str(s);
}
int cw_cfg_set_bstr16(cw_Cfg_t * cfg, const char * key, bstr16_t str)
{
CW_TYPE_BSTR16->read(cfg,key,bstr16_data(str),bstr16_len(str),NULL);
return 0;
}
void cw_cfg_dump(cw_Cfg_t * cfg)
@ -492,27 +519,95 @@ int cw_cfg_get_bool(cw_Cfg_t * cfg, const char * key, const char *def)
}
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, const char * def)
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, uint8_t def)
{
struct cw_Val v;
const char *s = cw_cfg_get(cfg,key,def);
memset(&v,0,sizeof(struct cw_Val));
const char *s = cw_cfg_get(cfg,key,NULL);
if (s==NULL)
return def;
CW_TYPE_BYTE->from_str(&v,s);
return v.val.word;
}
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, const char * def)
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, uint16_t def)
{
struct cw_Val v;
const char *s = cw_cfg_get(cfg,key,def);
const char *s = cw_cfg_get(cfg,key,NULL);
if (s==NULL)
return def;
CW_TYPE_WORD->from_str(&v,s);
return v.val.word;
}
/*
int cw_cfg_get_word(cw_Cfg_t * cfg, char *key, const char * def)
{
const char *s;
s=cw_cfg_get(cfg,key,def);
if (s==NULL)
return 0;
}
*/
void cw_cfg_set_int(cw_Cfg_t * cfg, const char * key, int val)
{
char a[128];
sprintf(a,"%d",val);
cw_cfg_set(cfg,key,a);
}
int cw_cfg_get_next_index(cw_Cfg_t * cfg, const char *key)
{
char ikey[CW_CFG_MAX_KEY_LEN];
struct cw_Cfg_entry search, * result;
char *d;
sprintf(ikey,"%s.%d",key,65536);
search.key=ikey;
/*//result = ktvn(ktv,&search);*/
result = mavl_get_last(cfg,&search);
if (result == NULL){
return 0;
}
d = strchr(result->key,'.');
if (d==NULL){
return 0;
}
if (strncmp(result->key,ikey,d-result->key)!=0)
return 0;
return atoi(d+1)+1;
}
int cw_cfg_set_val(cw_Cfg_t * cfg, const char *key, const struct cw_Type *type, const void * valguard, const uint8_t * data, int len)
{
cw_Val_t mdata, *mresult;
char str[2048];
memset(&mdata,0,sizeof(cw_Val_t));
mdata.type=type;
mdata.valguard=valguard;
cw_dbg(DBG_X,"SETVAL FOR TYPE: %s",type->name);
mresult = type->get(&mdata,data,len);
if (!mresult){
cw_log(LOG_ERR, "Can't create cfg element for key %s of type %s: %s",
key,type->name, strerror(errno));
free(mdata.key);
return 0;
}
type->to_str(&mdata,str,2048);
cw_cfg_set(cfg,key,str);
if (type->del)
type->del(&mdata);
return 1;
}

View File

@ -2,6 +2,8 @@
#define _CFG_H
#include <mavl.h>
#include "val.h"
#include "bstr.h"
#define CW_CFG_MAX_KEY_LEN 1024
@ -30,9 +32,21 @@ const char *cw_cfg_iter_next(struct cw_Cfg_iter *cfi, const char *key);
void cw_cfg_iter_init(cw_Cfg_t * cfg, struct cw_Cfg_iter *cfi, const char *base);
int cw_cfg_get_bool(cw_Cfg_t * cfg, const char * key, const char *def);
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, const char * def);
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, uint16_t def);
void cw_cfg_set_int(cw_Cfg_t * cfg, const char * key, int val);
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, const char * def);
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, uint8_t def);
bstr16_t cw_cfg_get_bstr16(cw_Cfg_t * cfg, const char * key, const char *def);
int cw_cfg_set_bstr16(cw_Cfg_t * cfg, const char * key, bstr16_t str);
int cw_cfg_get_next_index(cw_Cfg_t * cfg, const char *key);
int cw_cfg_set_val(cw_Cfg_t * cfg, const char *key, const struct cw_Type *t, const void * valguard, const uint8_t * data, int len);
#define cw_cfg_get_word2(cfg1,cfg2,key,def) \
cw_cfg_get_word(cfg1,key,cw_cfg_get_word(cfg2,key,def))
#define cw_dget(fun,cfg1,cfg2,key,def)\
fun(cfg1,key,fun(cfg2,key,def))
#endif

View File

@ -54,7 +54,7 @@ int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout)
struct mlistelem * elem;
int len,l;
cw_dbg(DBG_INFO, "Number of elements in ktv: %d",conn->local_cfg->count);
//cw_dbg(DBG_INFO, "Number of elements in ktv: %d",conn->local_cfg->count);
/* cw_dbg_ktv_dump(conn->local_cfg,DBG_CFG_DMP,"Local CFG","LOCAL:","End Local CFG");*/
/* rawout is already initialized, so we can get
@ -86,14 +86,13 @@ int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout)
data = mlistelem_dataptr(elem);
handler = cw_msgset_get_elemhandler(conn->msgset,data->proto,data->vendor,data->id);
printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name);
// cw_dbg(DBG_X,"Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name);
if (handler==NULL){
cw_log(LOG_ERR,"Can't put message element %d %d %d, no handler defined.",
data->proto,data->vendor,data->id);
continue;
}
cw_dbg(DBG_X,"Hello!");
if (handler->put == NULL){
if (data->mand){
@ -104,11 +103,10 @@ cw_dbg(DBG_X,"Hello!");
continue;
}
/* params.conn=conn;*/
params.local_cfg=conn->local_cfg;
params.remote_cfg=conn->remote_cfg;
params.conn=conn;
params.cfg=conn->remote_cfg;
params.default_cfg=conn->default_cfg;
params.global_cfg=conn->global_cfg;
params.msgset=conn->msgset;
@ -123,11 +121,9 @@ cw_dbg(DBG_X,"Hello!");
cisco/ap-led-flash-config/flash-enable
}*/
cw_dbg(DBG_X,"Calling Handler put for %s",handler->name);
l = handler->put(handler,&params,dst+len);
cw_dbg(DBG_X,"L = %d",l);
/* if(l>0)
cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,dst+len,l);
@ -156,11 +152,12 @@ cw_dbg(DBG_X,"L = %d",l);
uint8_t *msg_ptr = rawout + offset;
int elems_len = cw_get_msg_elems_len(msg_ptr);
elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
mavl_t * cfg = cw_ktv_create();
mavl_t * cfg = cw_cfg_create();
struct cw_ElemHandlerParams params;
params.remote_cfg=cfg;
params.cfg=cfg;
params.default_cfg=NULL;
params.msgset=conn->msgset;
params.msgdata=msg;

View File

@ -235,6 +235,8 @@ struct cw_Conn {
int detected;
void (*setup_complete)(struct cw_Conn *conn);
// void * mods;

View File

@ -274,7 +274,7 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
}
/* Detect the connecting AC type */
/* Detect the connecting WTP type */
if (!conn->detected) {
struct cw_MsgSet *set =
@ -289,6 +289,10 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
conn->cmod->setup_cfg(conn);
conn->msgset = set;
conn->detected = 1;
if (conn->setup_complete)
conn->setup_complete(conn);
}
/** debug the received message */
@ -365,16 +369,6 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
params.local_cfg = conn->local_cfg;
params.remote_cfg = conn->remote_cfg;
params.default_cfg = conn->default_cfg;
params.global_cfg = conn->global_cfg;
params.msgset = conn->msgset;
params.from = from;
params.msgdata = message;
params.mand_found = mand_found;
mand_found = mavl_create_conststr();
@ -386,8 +380,14 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
cw_dbg(DBG_MSG_PARSING, "*** Parsing message of type %d - (%s) ***",
message->type, message->name);
params.cfg = cw_cfg_create(); //conn->remote_cfg;
params.default_cfg = NULL;
params.from = from;
params.msgdata = message;
params.mand_found = mand_found;
params.msgset=conn->msgset;
params.conn = conn;
params.cfg = cw_cfg_create();
cw_decode_elements(&params,elems_ptr, elems_len);
/* all message elements are processed, do now after processing
@ -407,7 +407,8 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
if (message->postprocess) {
message->postprocess(conn);
// message->postprocess(conn);
message->postprocess(&params,elems_ptr, elems_len);
}
@ -660,7 +661,6 @@ int cw_read_messages(struct cw_Conn *conn)
{
uint8_t buf[2024];
int len = 2024;
cw_dbg(DBG_X,"Conn cw_read_messages from dsco request");
int n = conn->read(conn, buf, len);
if (n < 0)

View File

@ -527,7 +527,7 @@ int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state);
int cw_put_local_ip_address(uint8_t *dst, int id, int ipv_id, int ipv6_id,
uint8_t *src, int len);
int cw_detect_nat(struct cw_Conn *conn);
int cw_detect_nat(struct cw_ElemHandlerParams *conn);
uint8_t *cw_init_data_keep_alive_msg(uint8_t * buffer,uint8_t *rmac);

View File

@ -10,15 +10,13 @@
* @retval 1 NAT detected
* @retval 0 no NAT was detected
*/
int cw_detect_nat(struct cw_Conn *conn)
int cw_detect_nat(struct cw_ElemHandlerParams *params)
{
cw_Val_t * result;
const char * remote_str;
char local_str[128];
char remote_str[128];
result = cw_ktv_get(conn->remote_cfg,"capwap-local-ip-address",CW_TYPE_IPADDRESS);
if (result == NULL){
remote_str = cw_cfg_get(params->cfg,"capwap-local-ip-address",NULL);
if (remote_str == NULL){
cw_dbg(DBG_WARN,"Can't detect NAT. No local IP from peer received.");
return 0;
}
@ -26,8 +24,7 @@ int cw_detect_nat(struct cw_Conn *conn)
/* convert remote connected and sent ip addresse to
* strings */
sock_addrtostr((struct sockaddr*)&conn->addr,local_str,128,0);
result->type->to_str(result,remote_str,128);
sock_addrtostr((struct sockaddr*)&(params->conn->addr),local_str,128,0);
/* if connected and sent address is the same, there is
@ -37,3 +34,4 @@ int cw_detect_nat(struct cw_Conn *conn)
/* otherwise ther must be something between AC and WTP */
return 1;
}

View File

@ -3,48 +3,35 @@
#include "msgset.h"
#include "val.h"
#include "log.h"
#include "dbg.h"
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len)
{
cw_Val_t * result;
cw_Val_t val;
cw_Type_t * type;
int n;
char strval[2048];
memset(&val,0,sizeof(cw_Val_t));
type = (cw_Type_t*)handler->type;
char mkey[CW_KTV_MAX_KEY_LEN];
const char *key;
if (!type){
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
type->read(params->local_cfg, handler->key,elem_data,elem_len,handler->param);
// exit(0);
/* if (!result){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
handler->key,type->name, strerror(errno));
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
if (handler->mkkey != NULL){
handler->mkkey(handler->key,elem_data,elem_len, mkey);
key = mkey;
}
*/
else{
key = handler->key;
}
// n = type->to_str(&val,strval,2048);
// printf("SETTING: %s: %s (%d)\n",handler->key,strval,n);
// result = cw_ktv_add(params->remote_cfg, handler->key,
// handler->type,NULL, elem_data,elem_len);
// params->elem=result;
/* cw_dbg(DBG_X, "READ: %s / %s",type->name,key);*/
type->read(params->cfg, key,elem_data,elem_len,handler->param);
return CAPWAP_RESULT_SUCCESS;
}

View File

@ -1,6 +1,8 @@
#include "cw.h"
#include "cfg.h"
static const cw_ValEnum_t * get_enum(const cw_ValEnum_t * e, int val){
@ -21,7 +23,7 @@ int cw_in_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemHa
const cw_ValEnum_t * e;
const cw_ValIndexed_t * ie;
char key[CW_KTV_MAX_KEY_LEN];
char key[CW_CFG_MAX_KEY_LEN];
struct cw_ElemHandler thandler;
ie = handler->type;
@ -46,8 +48,11 @@ int cw_in_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemHa
}
memset(&thandler,0,sizeof(thandler));
thandler.type=e->type;
thandler.key=key;
thandler.type=e->type;
thandler.param=e->param;
return e->fun_in(&thandler,params,elem_data+f,elem_len-l);
}

View File

@ -3,12 +3,16 @@
#include "msgset.h"
#include "val.h"
#include "log.h"
#include "dbg.h"
int cw_in_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len)
{
cw_dbg(DBG_X,"STRUCT KEY: %s",handler->key);
stop();
const char * key;
char tmpkey[CW_KTV_MAX_KEY_LEN];
if (handler->mkkey != NULL){
handler->mkkey(key,elem_data,elem_len, tmpkey);
@ -29,7 +33,7 @@ printf("CW_IN_GENERIC STRUCT: %s\n",key);
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
cw_ktv_read_struct(params->remote_cfg,handler->type,key,elem_data,elem_len);
cw_ktv_read_struct(params->cfg,handler->type,key,elem_data,elem_len);
return CAPWAP_RESULT_SUCCESS;
}

View File

@ -1,4 +1,5 @@
#include "cw.h"
#include "dbg.h"
int cw_in_generic_with_index(struct cw_ElemHandler *eh,
struct cw_ElemHandlerParams *params,
@ -6,9 +7,12 @@ int cw_in_generic_with_index(struct cw_ElemHandler *eh,
{
char key[CW_KTV_MAX_KEY_LEN];
int idx;
cw_dbg(DBG_X,"Fix cw_in_generic_with_index");
stop();
idx = cw_get_byte(data);
sprintf(key,"%s.%d",eh->key,idx);
cw_ktv_add(params->remote_cfg,key,eh->type,NULL,data+1,len-1);
// cw_cfg_add(params->cfg,key,eh->type,NULL,data+1,len-1);
return 1;
}

View File

@ -1,9 +1,12 @@
#include "cw.h"
#include "log.h"
#include "dbg.h"
int cw_in_idx_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len)
{
stop();
/*
char key[CW_KTV_MAX_KEY_LEN];
cw_Val_t * result;
int idx;
@ -16,10 +19,10 @@ int cw_in_idx_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerPara
idx=cw_get_byte(elem_data);
sprintf(key,handler->key,idx);
result = cw_ktv_add(params->remote_cfg, key,
result = cw_ktv_add(params->cfg, key,
handler->type, NULL, elem_data+1,elem_len-1);
// params->elem=result;
*/
return CAPWAP_RESULT_SUCCESS;
}

View File

@ -4,12 +4,18 @@
#include "val.h"
#include "log.h"
#include "cw.h"
#include "dbg.h"
int cw_in_idx_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len)
{
char key[CW_KTV_MAX_KEY_LEN];
int idx;
cw_dbg(DBG_X,"Fix cw_in_idx_generic_struct");
exit(1);
if (!handler->type){
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
@ -19,7 +25,7 @@ int cw_in_idx_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHand
idx = cw_get_byte(elem_data);
sprintf(key, handler->key, idx);
cw_ktv_read_struct(params->remote_cfg,handler->type,key,elem_data+1,elem_len-1);
cw_ktv_read_struct(params->cfg,handler->type,key,elem_data+1,elem_len-1);
return CAPWAP_RESULT_SUCCESS;
}

View File

@ -5,9 +5,14 @@
#include "log.h"
#include "cw.h"
#include "dbg.h"
int cw_in_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len)
{
stop();
char key[CW_KTV_MAX_KEY_LEN];
int radio;
@ -19,7 +24,7 @@ int cw_in_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHa
radio = cw_get_byte(elem_data);
sprintf(key,"radio.%d/%s",radio,handler->key);
cw_ktv_read_struct(params->remote_cfg,handler->type,key,elem_data+1,elem_len-1);
cw_ktv_read_struct(params->cfg,handler->type,key,elem_data+1,elem_len-1);
/*params->elem=result;*/

View File

@ -10,7 +10,6 @@ cw_Val_t * cw_ktv_add(mavl_t kvtstore, const char *key, const struct cw_Type *ty
{
cw_Val_t mdata, *mresult;
int exists;
mdata.key=cw_strdup(key);
mdata.valguard=valguard;

View File

@ -12,19 +12,18 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
, uint8_t * dst)
{
struct cw_Val * elem;
int start, len, l;
/* Get the element */
/* search.key=(char*)handler->key;
elem = mavl_get(params->conn->local_cfg, &search);
*/
elem = cw_ktv_get(params->local_cfg,handler->key,NULL);
/* if (elem == NULL && params->conn->default_cfg !=NULL)
elem = mavl_get(params->conn->default_cfg, &search);
*/
if (elem == NULL) {
// cw_dbg(DBG_X,"Generic out!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// cw_cfg_dump(params->cfg);
// cw_dbg(DBG_X,"Generic out!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDDUMP");
start = params->msgset->header_len(handler);
len = ((const cw_Type_t*)(handler->type))->
write(params->cfg,handler->key,dst+start,handler->param);
if (len == -1) {
const char *vendor="";
if ( handler->vendor ) {
vendor=cw_strvendor(handler->vendor);
@ -46,31 +45,7 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
return 0;
}
/* Size for msg elem header depends on
vendor specific payload */
/* start = handler->vendor ? 10 : 4; */
start = params->msgset->header_len(handler);
if (cw_ktv_cast(elem,handler->type)==NULL){
cw_log(LOG_ERR,"Can't put element '%s'- can't cast from %s to %s for key: %s", handler->name,
elem->type->name, ((const cw_Type_t*)handler->type)->name, handler->key);
return 0;
}
len = ((const cw_Type_t*)(handler->type))->put(elem,dst+start);
/* ((const cw_Type_t*)(handler->type))->to_str(elem,detail,120);
sprintf(params->debug_details, " Value = %s", detail);
params->elem = elem;*/
/* if (handler->vendor)
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
l = len + cw_put_elem_hdr(dst, handler->id, len); */
l = params->msgset->write_header(handler,dst,len);
cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,handler,dst,l);
/* cw_dbg_elem(DBG_ELEM_OUT,params->conn,params->msgdata->type,handler,dst,l);*/
return l;
}

View File

@ -1,8 +1,14 @@
#include "cw.h"
#include"dbg.h"
int cw_out_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
cw_dbg(DBG_X,"Fix: cw_out_generic_indexed_enum");
exit(1);
char key[CW_KTV_MAX_KEY_LEN];
int i;
cw_Val_t * result;
@ -24,7 +30,7 @@ int cw_out_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemH
//printf("Her is the Key: %s - %s\n",key, );
result = cw_ktv_base_exists(params->local_cfg,key);
result = cw_ktv_base_exists(params->cfg,key);
if (result==NULL)
continue;
start = params->msgset->header_len(handler);
@ -35,7 +41,7 @@ int cw_out_generic_indexed_enum(struct cw_ElemHandler * handler, struct cw_ElemH
if (e[i].fun_out==NULL)
len += result->type->put(result,ob+start+len);
else
len += cw_ktv_write_struct(params->local_cfg,
len += cw_ktv_write_struct(params->cfg,
NULL,e[i].type,key,ob+start+len);
cw_set_byte(ob+start+ie->idxpos,e[i].value);

View File

@ -4,9 +4,15 @@
#include "log.h"
#include "cw.h"
#include "dbg.h"
int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
stop();
int start;
int len;
cw_Val_t search, *result;
@ -17,7 +23,7 @@ int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandler
}
search.key = (char*)handler->key;
result = mavl_get_first(params->local_cfg,&search);
result = mavl_get_first(params->cfg,&search);
if (result == NULL ){
if (params->elemdata->mand)
cw_log(LOG_ERR,"Can't put mandatory message element %s, no data available",handler->name);
@ -32,7 +38,7 @@ int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandler
start = params->msgset->header_len(handler);
len = cw_ktv_write_struct(params->local_cfg,
len = cw_ktv_write_struct(params->cfg,
params->default_cfg,
handler->type,handler->key,dst+start);

View File

@ -1,10 +1,12 @@
#include "cw.h"
#include "dbg.h"
int cw_out_generic_with_index(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst)
{
stop();
char key[CW_KTV_MAX_KEY_LEN];
int idx;
cw_Val_t * result, search;
@ -18,7 +20,7 @@ int cw_out_generic_with_index(struct cw_ElemHandler * eh,
do {
sprintf(key,"%s.%d",eh->key,idx);
search.key=key;
result = mavl_get_first(params->local_cfg,&search);
result = mavl_get_first(params->cfg,&search);
if (result==NULL)
break;
if (strncmp(result->key,key,strlen(key))!=0)

View File

@ -5,6 +5,9 @@
int cw_out_idx_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
stop();
char key[CW_KTV_MAX_KEY_LEN];
struct cw_Val * elem, search;
int i;
@ -24,7 +27,7 @@ int cw_out_idx_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHan
sprintf(key,handler->key,i);
search.key=key;
/*elem = mavl_get(params->conn->local_cfg, &search);*/
elem = mavl_get_first(params->local_cfg,&search);
elem = mavl_get_first(params->cfg,&search);
if(elem != NULL){
printf("Elem key: %s\n",elem->key);
}
@ -41,7 +44,7 @@ int cw_out_idx_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHan
start = mdst + params->msgset->header_len(handler);
len += cw_put_byte(start+len,idx);
len += cw_ktv_write_struct(params->local_cfg,NULL, handler->type,key,start+len);
len += cw_ktv_write_struct(params->cfg,NULL, handler->type,key,start+len);
mdst += params->msgset->write_header(handler,mdst,len);

View File

@ -7,6 +7,8 @@ int cw_ktv_idx_get_next(mavl_t ktv, const char *key, int n);
int cw_out_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
stop();
int len,i,l;
int radios;
len =0;
@ -20,7 +22,7 @@ int cw_out_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerP
idx++;
}
*/
radios = cw_ktv_get_byte(params->local_cfg,"wtp-descriptor/max-radios",0);
radios = cw_ktv_get_byte(params->cfg,"wtp-descriptor/max-radios",0);
for(i=0;i<radios;i++){
l = cw_write_radio_element(handler,params,i,dst+len);

View File

@ -7,6 +7,8 @@ int cw_ktv_idx_get_next(mavl_t ktv, const char *key, int n);
int cw_out_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
stop();
int i,l, offset;
uint8_t * cdst;
@ -21,12 +23,12 @@ int cw_out_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemH
char basekey[CW_KTV_MAX_KEY_LEN];
cw_Val_t * result;
i = cw_ktv_idx_get_next(params->local_cfg,"radio",i+1);
i = cw_ktv_idx_get_next(params->cfg,"radio",i+1);
if (i==-1)
break;
sprintf(basekey,"radio.%d/%s",i,handler->key);
result = cw_ktv_base_exists(params->local_cfg,basekey);
result = cw_ktv_base_exists(params->cfg,basekey);
if (result == NULL){
continue;
}
@ -34,7 +36,7 @@ int cw_out_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemH
l=0;
l+=cw_put_byte(cdst+offset+l,i);
l+= cw_ktv_write_struct(params->local_cfg,NULL, handler->type,basekey,cdst+offset+l);
l+= cw_ktv_write_struct(params->cfg,NULL, handler->type,basekey,cdst+offset+l);
cdst+=params->msgset->write_header(handler,cdst,l);
@ -59,7 +61,7 @@ printf("Next: %s\n", next);
if (sl==NULL){
cw_Val_t * result;
sprintf(key,"%s/%s",current,next);
result = cw_ktv_base_exists(params->local_cfg,key);
result = cw_ktv_base_exists(params->cfg,key);
if (result != NULL){
int offset;
int i,l;
@ -68,7 +70,7 @@ printf("Next: %s\n", next);
for (i=0;i<stack[0];i++){
printf("I=%i\n",stack[i+1]);
}
l= cw_ktv_write_struct(params->local_cfg,params->default_cfg,
l= cw_ktv_write_struct(params->cfg,params->default_cfg,
handler->type,key,dst+offset);
printf("Write struct len %i\n",l);
@ -96,19 +98,19 @@ printf("current is %s\n", current);
printf("Here we are %s\n",key);
cw_dbg_ktv_dump(params->local_cfg,DBG_INFO,"start