more progress in new ktv storage

FossilOrigin-Name: a2c26a366de1946feb707439302b22de2e3d02f7621d0834fdf242852b28639c
This commit is contained in:
7u83@mail.ru 2018-03-15 19:07:17 +00:00
parent 8b2e36e912
commit 15cca4e553
40 changed files with 411 additions and 310 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="actube" Database="">
<Project Name="ac" Path="ac.project" Active="No"/>
<Project Name="wtp" Path="wtp.project" Active="Yes"/>
<Project Name="wtp" Path="wtp.project" Active="No"/>
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="Yes"/>
<Project Name="libcw" Path="libcw.project" Active="No"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>

View File

@ -117,7 +117,6 @@
<File Name="src/cw/lw_cisco_id_to_str.c"/>
<File Name="src/cw/bstr_create_from_cfgstr.c"/>
<File Name="src/cw/sock_getifhwaddr.c"/>
<File Name="src/cw/stravltree.h"/>
<File Name="src/cw/conn_send_packet.c"/>
<File Name="src/cw/mbag_type_bstr16.c"/>
<File Name="src/cw/cipwap.h"/>
@ -159,7 +158,6 @@
<File Name="src/cw/sock.h"/>
<File Name="src/cw/aciplist.c"/>
<File Name="src/cw/log_syslog.c"/>
<File Name="src/cw/stravltree.c"/>
<File Name="src/cw/radio.c"/>
<File Name="src/cw/lw_put_ac_descriptor.c"/>
<File Name="src/cw/conn_destroy.c"/>
@ -327,6 +325,11 @@
<File Name="src/cw/msgset.h"/>
<File Name="src/cw/mlist_get.c"/>
<File Name="src/cw/mlist_replace.c"/>
<File Name="src/cw/cw_ktv_add_from_str.c"/>
<File Name="src/cw/keys.h"/>
<File Name="src/cw/cw_ktv_put.c"/>
<File Name="src/cw/cw_ktv_get.c"/>
<File Name="src/cw/cw_write_descriptor_subelem.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

View File

@ -164,8 +164,8 @@
#define CAPWAP_MSG_RESET_REQUEST 17
#define CAPWAP_MSG_RESET_RESPONSE 18
#define CW_MSG_PRIMARY_DISCOVERY_REQUEST 19
#define CW_MSG_PRIMARY_DISCOVERY_RESPONSE 20
#define CAPWAP_MSG_PRIMARY_DISCOVERY_REQUEST 19
#define CAPWAP_MSG_PRIMARY_DISCOVERY_RESPONSE 20
#define CW_MSG_DATA_TRANSFER_REQUEST 21
#define CW_MSG_DATA_TRANSFER_RESPONSE 22
@ -202,7 +202,7 @@
* @see CW_ELEM_AC_NAME_WITH_PRIORITY */
#define CW_ELEM_AC_NAME_WITH_INDEX CW_ELEM_AC_NAME_WITH_PRIORITY
#define CW_ELEM_AC_TIMESTAMP 6
#define CAPWAP_ELEM_AC_TIMESTAMP 6
/**@{
* one for all
*/

View File

@ -9,7 +9,7 @@ struct cw_strlist_elem capwap_strings_elem[] = {
{CW_ELEM_AC_NAME, "AC Name"},
{CW_ELEM_AC_NAME_WITH_PRIORITY, "AC Name with Priority"},
// {CW_ELEM_AC_NAME_WITH_INDEX, "AC Name with Index"},
{CW_ELEM_AC_TIMESTAMP, "AC Timestamp"},
{CAPWAP_ELEM_AC_TIMESTAMP, "AC Timestamp"},
{CW_ELEM_ADD_MAC_ACL_ENTRY, "Add MAC ACL Entry"},
{CW_ELEM_ADD_STATION, "Add Station"},
{CW_ELEM_RESERVED_9, "Reserved 9"},

View File

@ -44,8 +44,8 @@ struct cw_strlist_elem capwap_strings_msg[] = {
{ CAPWAP_MSG_IMAGE_DATA_RESPONSE,"Image Data Response"},
{ CAPWAP_MSG_RESET_REQUEST,"Reset Request"},
{ CAPWAP_MSG_RESET_RESPONSE,"Reset Response"},
{ CW_MSG_PRIMARY_DISCOVERY_REQUEST,"Primary Discovery Request"},
{ CW_MSG_PRIMARY_DISCOVERY_RESPONSE,"Primary Discovery Response"},
{ CAPWAP_MSG_PRIMARY_DISCOVERY_REQUEST,"Primary Discovery Request"},
{ CAPWAP_MSG_PRIMARY_DISCOVERY_RESPONSE,"Primary Discovery Response"},
/* Data Transfer Request 21
Data Transfer Response 22

View File

@ -28,7 +28,7 @@
#include "conn.h"
#include "sock.h"
#include "stravltree.h"
/*#include "stravltree.h"*/
#include "mod.h"
#include "msgset.h"
@ -153,29 +153,6 @@ int cw_send_error_response(struct conn *conn, uint8_t * rawmsg, uint32_t result_
return 1;
}
static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
if (!a->max_len)
return 1;
/* if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d",
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
a->min_len);
return 0;
}
if (len > a->max_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too big, len=%d, max len=%d", a->elem_id,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0;
}
*/
return 1;
}
static struct cw_MsgSet *load_msg_set(struct conn *conn, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from)
@ -369,7 +346,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
uint8_t *elem;
/* Create an avltree to catch the found mandatory elements */
//conn->mand = stravltree_create();
/* //conn->mand = stravltree_create();*/
mand_found = mavl_create_conststr();
unrecognized = mlist_create(NULL,NULL,sizeof(uint8_t*));
@ -408,99 +385,19 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
if (result_code == CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT){
mlist_append(unrecognized,&elem);
}
/*
elem_id = cw_get_elem_id(elem);
handler = cw_msgset_get_elemhandler(conn->msgset,0, 0, elem_id);
if (!handler) {
cw_dbg(DBG_ELEM_ERR, "Unknown message element: %d, ignoring",
elem_id);
continue;
}
elem_data_search.id=elem_id;
elem_data_search.proto=0;
elem_data_search.vendor=0;
elem_data = mavl_find_ptr(message->elements_tree,&elem_data_search);
if (!elem_data){
cw_dbg(DBG_ELEM_ERR, "Element %d - %s, not allowed here",
elem_id, handler->name);
continue;
}
elem_len = cw_get_elem_len(elem);
//printf ("Would start elem processing now %d - %s\n",handler->id, handler->name);
cw_dbg_elem(DBG_ELEM, conn, message->type, handler,
cw_get_elem_data(elem),elem_len);
handler->get(conn, handler, cw_get_elem_data(elem), elem_len, from);
*/
continue;
exit(0);
struct cw_ElemDef * elem;
/*
// TODO XXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
*/
af = 0;
if (!af) {
//unrecognized++;
/* cw_dbg(DBG_ELEM_ERR,
"Element %d (%s) not allowed in msg of type %d (%s), ignoring.",
// TODO XXXX as.elem_id, cw_strelemp(conn->actions, as.elem_id),
as.msg_id, cw_strmsg(as.msg_id));
*/
continue;
}
if (!check_len(conn, af, cw_get_elem_data(elem), elem_len, from)) {
/* if (!check_len(conn, af, cw_get_elem_data(elem), elem_len, from)) {
continue;
}
cw_dbg_elem(DBG_ELEM, conn, as.msg_id, as.elem_id, cw_get_elem_data(elem),
elem_len);
int afrc = 1;
if (af->start) {
afrc =
af->start(conn, af, cw_get_elem_data(elem), elem_len, from);
}
if (af->mand && afrc) {
/* add found mandatory message element
to mand list */
stravltree_add(conn->mand, af->item_id);
}
if(conn->elem_end){
/*
// TODO XXXX
// afrc = conn->elem_end(conn,af,afrc,cw_get_elem_data(elem), elem_len,from);
*/
}
}
@ -508,12 +405,13 @@ exit(0);
by calling the "end" function for the message */
cw_check_missing_mand(message,mand_found);
mavl_destroy(mand_found);
{
mavliter_t it;
const struct cw_Type * type;
printf("********** THE REMODE CFG **************\n");
cw_dbg (DBG_INFO, "********** THE REMOTE CFG **************\n");
mavliter_init(&it,conn->remote_cfg);
@ -524,13 +422,13 @@ exit(0);
type = data->type;
type->to_str(data,value,0);
printf("Got %s (%s): %s\n",data->key,type->name, value);
cw_dbg(DBG_INFO,"RMTCFG: %s (%s): %s",data->key,type->name, value);
}
mavliter_init(&it,mand_found);
mavliter_foreach(&it){
printf("MAnd found: %s\n", mavliter_get_str(&it));
printf("MAnd found: %s", mavliter_get_str(&it));
}
{
@ -543,7 +441,7 @@ exit(0);
printf("Unrecognized: %d %d\n",elem_id,elem_len);
}
}
mavl_destroy(mand_found);
}
@ -602,7 +500,7 @@ exit(0);
*/
}
stravltree_destroy(conn->mand);
/*stravltree_destroy(conn->mand);*/
return result_code;

View File

@ -328,6 +328,10 @@ int cw_read_wtp_descriptor(mavl_t mbag, struct conn *conn,
struct cw_ElemHandler *eh, uint8_t * data, int len,
struct cw_DescriptorSubelemDef *allowed);
int cw_write_descriptor_subelem (uint8_t *dst, mavl_t ktvstore,
int subelem_id, const char * parent_key);
extern int cw_read_wtp_descriptor_7(mavl_t mbag, struct conn *conn,
struct cw_ElemHandler *eh, uint8_t * data, int len,

View File

@ -1,52 +1,37 @@
#include "capwap.h"
#include "dbg.h"
#include "log.h"
int cw_check_missing_mand(struct cw_MsgData *msgdata, mavl_t keys )
{
mlistelem_t * elem;
char *mandkey, *result;
mlist_t missing;
int count;
missing = mlist_create_conststr();
if (missing==NULL){
cw_log(LOG_ERR, "Can't allocate memory for check of missing mand elems: %s", strerror(errno));
return 0;
}
mlist_foreach(elem, msgdata->mand_keys){
mandkey = mlistelem_get_str(elem);
result = mavl_get_str(keys,mandkey);
if (result == NULL){
printf("Missing\n");
mlist_append_ptr(missing,mandkey);
}
else printf("Ok\n");
}
/* cw_action_in_t as;
as.capwap_state = a->capwap_state;
as.msg_id = a->msg_id;
as.vendor_id = 0;
as.elem_id = 0;
as.proto=0;
*/
/// TODO XXXX
/*
DEFINE_AVLITER(it,conn->actions->in);
int n=0;
avliter_foreach_from(&it,&as) {
cw_action_in_t * ai = avliter_get(&it);
if (ai->msg_id != as.msg_id || ai->capwap_state != as.capwap_state)
break;
if (!ai->mand)
continue;
void * rc = mavl_get(conn->mand,(void*)ai->item_id);
if (!rc) {
out[n++]=ai;
}
mlist_foreach(elem,missing){
cw_dbg(DBG_RFC," Missing mandatory message element: %s", mlistelem_get_str(elem));
}
return n;
*/
count = missing->count;
mlist_destroy(missing);
return count;
}

View File

@ -14,6 +14,7 @@
int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
/*
cw_acpriolist_t prios = mbag_get_mavl(conn->config,CW_ITEM_AC_NAME_WITH_PRIORITY);
if (!prios)
return 0;
@ -25,7 +26,7 @@ int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8
prio->prio=cw_get_byte(data);
prio->name=strndup((char*)data+1,len-1);
mavl_replace(prios,prio,NULL);
*/
return 1;
}

View File

@ -43,7 +43,7 @@
int cw_in_capwap_control_ip_address(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from)
{
cw_acip_t * acip;
/* cw_acip_t * acip;
cw_aciplist_t list =
mbag_get_mavl_c(conn->incomming,a->item_id,cw_aciplist_create);
@ -81,6 +81,7 @@ int cw_in_capwap_control_ip_address(struct conn *conn, struct cw_action_in *a,
cw_aciplist_replace(list,acip);
*/
return 1;
}

View File

@ -11,14 +11,15 @@
int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from)
{
/*
cw_action_in_t *mlist[20];
// int n = cw_check_missing_mand(mlist, conn, a);
//cw_dbg(DBG_INFO,"This response came from: %s",sock_addr2str(&conn->addr));
/* if mandatory elements are missing, ignore this response */
/* if (n && conn->strict_capwap) {
// if mandatory elements are missing, ignore this response
if (n && conn->strict_capwap) {
cw_dbg_missing_mand(DBG_MSG_ERR, conn, mlist, n, a);
cw_dbg(DBG_MSG_ERR,
"Ignoring Discovery Response from %s - missing mandatory elements.",
@ -29,8 +30,8 @@ int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
if (n) {
cw_dbg_missing_mand(DBG_RFC, conn, mlist, n, a);
}
*/
/* we have all AC information in the incomming buffer */
// we have all AC information in the incomming buffer
mbag_t discs;
discs = mbag_get_mavl_c(conn->remote, CW_ITEM_DISCOVERIES,
@ -51,4 +52,6 @@ int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * d
return 0;
*/
}

View File

@ -0,0 +1,43 @@
#include "ktv.h"
#include "cw.h"
#include "log.h"
#include "dbg.h"
const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key, const struct cw_Type *type,
const char * str)
{
cw_KTV_t mdata, *mresult;
int exists;
/* cw_dbg(DBG_ELEM,"KVStore (%p,%d) add elem (%s): %s", kvstore, kvstore->count,
type->name, key );
*/
mdata.key=cw_strdup(key);
if (!mdata.key){
cw_log(LOG_ERR, "Can't allocate memory for key %s: %s",
key,strerror(errno));
return NULL;
}
printf("Want To Add: %s:%s (%s)\n",key,str,type->name);
mresult = type->from_str(&mdata,str);
if (!mresult){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
key,type->name, strerror(errno));
free(mdata.key);
return NULL;
}
mresult = mavl_add(kvtstore, &mdata, &exists);
if (exists){
cw_log(LOG_ERR, "Element already exists %s", key);
/* element already exists */
free(mdata.key);
if (type->del)
type->del(&mdata);
return key;
}
return mdata.key;
}

23
src/cw/cw_ktv_get.c Normal file
View File

@ -0,0 +1,23 @@
#include "ktv.h"
#include "mavl.h"
cw_KTV_t * cw_ktv_get(mavl_t ktv, const char *key, const cw_Type_t * type)
{
cw_KTV_t search, *result;
/* we can safely cast from const char * to char *, because
* we never will use the search varaiable to store ktv values */
search.key=(char*)key;
result = mavl_get(ktv,&search);
if (result == NULL){
return NULL;
}
if (type == NULL){
return result;
}
if (strcmp(type->name,result->type->name)==0){
return result;
}
return NULL;
}

View File

@ -1,8 +1,49 @@
#include "ktv.h"
cw_kvt_read_file(mavl_t ktv, mavl_t types)
int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types)
{
char key[256];
char xtype[256];
char val[2048];
int rc;
struct cw_Type typesearch, *cwtype;
}
do {
cw_KTV_t nktv, *nres;
rc = cw_ktv_read_line(file,key,xtype,val);
if (rc == 0){
printf("Got a line %s:%s:%s\n",key,xtype,val);
}
typesearch.name=xtype;
/* printf("Searching for type: '%s'\n",xtype);*/
cwtype = mavl_get_ptr(types,&typesearch);
if (cwtype != NULL){
// printf("Yes! I know the type: %s\n",cwtype->name);
}
else
continue;
cw_ktv_add_from_str(ktv,key,cwtype,val);
/* nres = cwtype->from_str(&nktv,val);
if (nres !=NULL ){
// printf("Yea, created from string\n");
nktv.key=cw_strdup(key);
mavl_add(ktv, &nktv, NULL);
}
*/
}while(rc==0);
return 0;
}

View File

@ -21,7 +21,7 @@ int cw_put_ac_name_with_priority(uint8_t *dst,cw_acprio_t * acprio)
int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
cw_acpriolist_t prios = mbag_get_mavl(conn->config,CW_ITEM_AC_NAME_WITH_PRIORITY);
/* cw_acpriolist_t prios = mbag_get_mavl(conn->config,CW_ITEM_AC_NAME_WITH_PRIORITY);
if (!prios)
return 0;
@ -37,5 +37,6 @@ int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uin
}
return d-dst;
*/
}

View File

@ -11,10 +11,12 @@
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
struct cw_KTV * elem;
struct cw_KTV * elem, search;
int start, len;
/* Get the element to put */
elem = mavl_get(params->conn->local_cfg, handler->key);
search.key=handler->key;
elem = mavl_get(params->conn->local_cfg, &search);
/* Size for msg elem header depends on
vendor specific payload */
@ -25,15 +27,13 @@ int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams
if ( handler->vendor ) {
vendor=cw_strvendor(handler->vendor);
}
if ( 0) {
/* cw_log(LOG_ERR,
if ( params->elemdata->mand) {
cw_log(LOG_ERR,
"Can't put mandatory element %s %d - (%s) into %s. No value for '%s' found.",
vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id)
, a->item_id
vendor, handler->id, handler->name, "nona"
, handler->key
);
*/ }
}
else{
/* cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
vendor,

View File

@ -24,8 +24,12 @@
#include "log.h"
#include "dbg.h"
#include "ktv.h"
int cw_put_mbag_item(uint8_t * dst, struct mbag_item *item)
{
cw_KTV_t ktv;
ktv.type->put(&ktv,dst);
/*
if (item->type->put){
cw_dbg(DBG_X,"User put method to put ");

View File

@ -38,7 +38,6 @@
*/
int cw_put_msg(struct conn *conn, uint8_t * rawout)
{
uint8_t *msgptr,*dst;
int type;
struct cw_MsgData * msg;
@ -50,7 +49,6 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
msgptr = rawout + cw_get_hdr_msg_offset(rawout);
type = cw_get_msg_type(msgptr);
printf("Looking in %p for %d\n", conn->msgset,type);
msg = cw_msgset_get_msgdata(conn->msgset,type);
if (msg == NULL){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
@ -66,8 +64,14 @@ int cw_put_msg(struct 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);
//printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name);
if (handler->put == NULL){
if (data->mand){
cw_log(LOG_ERR,"Error: Can't add mandatory message element %d - %s, no put method defined",
handler->id, handler->name);
}
continue;
}
@ -75,6 +79,8 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
params.elemdata = data;
l = handler->put(handler,&params,dst+len);
len += l;
cw_dbg_elem(DBG_ELEM,conn,type,handler,dst+len,l);
}
cw_set_msg_elems_len(msgptr, len);

View File

@ -50,7 +50,7 @@ int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
if (!elems[i].maxlen) {
cw_dbg_version_subelem(DBG_ELEM_ERR, "Not allowed",
cw_dbg_version_subelem(DBG_ELEM_ERR, "Can't handle sub-elem, vendor or type unknonw",
subtype, vendor_id, data+sub+8, sublen);
errors++;
} else {
@ -68,11 +68,11 @@ int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
/* vendor */
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VENDOR);
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_SKEY_VENDOR);
cw_ktv_add(cfg,key,CW_TYPE_DWORD,data + sub,4);
/* version */
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_KEY_VERSION);
sprintf(key,"%s/%s/%s",parent_key,elems[i].key,CW_SKEY_VERSION);
cw_ktv_add(cfg,key,CW_TYPE_BSTR16,data+sub+8,l);
sprintf(dbgstr, "%s", key);

View File

@ -8,10 +8,10 @@
static struct cw_DescriptorSubelemDef allowed_default[] = {
{-1,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_KEY_HARDWARE, 1024,0},
{-1,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_KEY_SOFTWARE, 1024.0},
{-1,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_KEY_BOOTLOADER, 1024,0},
{-1,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_KEY_OTHER_SOFTWARE, 1024,0},
{-1,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_SKEY_HARDWARE, 1024,0},
{-1,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_SKEY_SOFTWARE, 1024.0},
{-1,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_SKEY_BOOTLOADER, 1024,0},
{-1,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_SKEY_OTHER_SOFTWARE, 1024,0},
{0,0, NULL, 0,0}
};
@ -28,22 +28,12 @@ int cw_read_wtp_descriptor_7(mavl_t cfg, struct conn *conn,
int ncrypt, pos;
char key[64];
sprintf(key,"%s/%s",eh->key, "max_radios");
/* md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data,1));
*/
sprintf(key,"%s/%s",eh->key, CW_SKEY_MAX_RADIOS);
cw_ktv_add(cfg,key,CW_TYPE_BYTE,data,1);
sprintf(key,"%s/%s",eh->key, "radios_in_use");
sprintf(key,"%s/%s",eh->key, CW_SKEY_RADIOS_IN_USE);
cw_ktv_add(cfg,key,CW_TYPE_BYTE,data+1,1);
/* md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
*/
/* mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1));
*/
pos = 2;
@ -52,7 +42,6 @@ int cw_read_wtp_descriptor_7(mavl_t cfg, struct conn *conn,
pos += 2;
if (!allowed)
allowed=allowed_default;

View File

@ -65,9 +65,21 @@ static int to_str ( const struct cw_KTV *data, char *dst, int max_len )
static struct cw_KTV *from_str ( struct cw_KTV * data, const char *src )
{
return NULL;
uint8_t * s;
s = bstr16_create_from_str(src);
if ( !s )
return NULL;
data->type = &cw_type_bstr16;
data->val.ptr = s;
return data;
}
static int len ( struct cw_KTV * data ){
return bstr16_len(data->val.ptr);
}
const struct cw_Type cw_type_bstr16 = {
"Bstr16", /* name */
@ -75,5 +87,6 @@ const struct cw_Type cw_type_bstr16 = {
put, /* put */
get, /* get */
to_str, /* to_str */
from_str /* from_str */
from_str, /* from_str */
len /* len */
};

View File

@ -40,10 +40,15 @@ static int to_str(const cw_KTV_t *data, char *dst, int max_len)
static cw_KTV_t *from_str(cw_KTV_t * data, const char *src)
{
data->type = &cw_type_byte;
data->val.byte = atoi(src);
return data;
}
static int len (cw_KTV_t * data)
{
return sizeof(uint8_t);
}
const struct cw_Type cw_type_byte = {
"Byte", /* name */
@ -51,5 +56,6 @@ const struct cw_Type cw_type_byte = {
put, /* put */
get, /* get */
to_str, /* to_str */
from_str /* from_str */
from_str, /* from_str */
len /* len */
};

View File

@ -40,6 +40,7 @@ static int to_str(const struct cw_KTV *data, char *dst, int max_len)
static struct cw_KTV *from_str(struct cw_KTV * data, const char *src)
{
data->type = &cw_type_dword;
data->val.dword = atoi(src);
return data;
}

View File

@ -41,6 +41,7 @@ static int to_str(const cw_KTV_t *data, char *dst, int max_len)
static cw_KTV_t *from_str(cw_KTV_t * data, const char *src)
{
data->type = &cw_type_word;
data->val.word = atoi(src);
return data;
}

View File

@ -0,0 +1,46 @@
#include "ktv.h"
#include "keys.h"
#include "log.h"
#include "cw.h"
int cw_write_descriptor_subelem (uint8_t *dst, mavl_t ktvstore,
int subelem_id, const char * parent_key)
{
char key[256];
cw_KTV_t * vendor, *version ;
uint8_t *d;
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
*/
sprintf (key, "%s/%s", parent_key, CW_SKEY_VENDOR);
vendor = cw_ktv_get (ktvstore, key, CW_TYPE_DWORD);
if (vendor == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, not value found.", key);
return 0;
}
sprintf (key, "%s/%s", parent_key, CW_SKEY_VERSION);
version = cw_ktv_get (ktvstore, key, CW_TYPE_BSTR16);
if (version == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, not value found.", key);
return 0;
}
d = dst;
/* put vendor */
d += vendor->type->put (vendor, d);
/* put version */
d += cw_put_dword (d, (subelem_id << 16) | version->type->len(version));
d += version->type->put(version,d);
return d-dst;
}

View File

@ -1,13 +1,22 @@
#ifndef __KEYS_H
#define __KEYS_H
#define CW_KEY_HARDWARE "hardware"
#define CW_KEY_SOFTWARE "software"
#define CW_KEY_BOOTLOADER "bootloader"
#define CW_KEY_OTHER_SOFTWARE "other_software"
#define CW_KEY_VENDOR "vendor"
#define CW_KEY_VERSION "version"
#define CW_KEY_WTP_DESCRIPTOR "wtp-descriptor"
#define CW_SKEY_HARDWARE "hardware"
#define CW_SKEY_SOFTWARE "software"
#define CW_SKEY_BOOTLOADER "bootloader"
#define CW_SKEY_OTHER_SOFTWARE "other_software"
#define CW_SKEY_VENDOR "vendor"
#define CW_SKEY_VERSION "version"
#define CW_SKEY_MAX_RADIOS "max-radios"
#define CW_SKEY_RADIOS_IN_USE "radios-in-use"
#define CW_KEY_WTP_NAME "wtp-name"
#endif

View File

@ -43,10 +43,11 @@ struct cw_Type {
created by the #del function. */
struct cw_KTV *(*from_str) (struct cw_KTV * data, const char *src);
/*
int (*def)(void *, void *);
*/
int (*len)(cw_KTV_t *);
};
typedef struct cw_Type cw_Type_t;
extern const struct cw_Type cw_type_byte;
extern const struct cw_Type cw_type_word;
@ -76,5 +77,7 @@ void cw_ktv_mavldel(void *data);
mavl_create(cw_ktv_mavlcmp_type_by_name,NULL,sizeof(struct cw_Type *))
int cw_ktv_read_line (FILE *f, char * key, char * type, char *val);
int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types);
cw_KTV_t * cw_ktv_get(mavl_t ktv, const char *key, const cw_Type_t * type);
#endif /* __KVT_H */

View File

@ -2,7 +2,7 @@
#include "cw.h"
#include "dbg.h"
#include "log.h"
#include "stravltree.h"
/*#include "stravltree.h"*/
/**
* @file
@ -23,9 +23,9 @@ int lw_in_vendor_specific(struct conn *conn, struct cw_action_in *a,
as.elem_id = cw_get_word(data + 4);
as.proto = CW_ACTION_PROTO_LWAPP;
// TODO XXXX
/* TODO XXXX
//af = cw_actionlist_in_get(conn->actions->in, &as);
*/
af = 0;
if (!af) {
@ -41,7 +41,7 @@ int lw_in_vendor_specific(struct conn *conn, struct cw_action_in *a,
if (af->mand && afrc) {
/* add found mandatory message element
to mand list */
stravltree_add(conn->mand, af->item_id);
/* XXXX stravltree_add(conn->mand, af->item_id); */
}
return afrc;
}

View File

@ -73,7 +73,7 @@ const struct mbag_typedef mbag_type_vendorstr = {
};
*/
/*
void free_avltree(void*t){
mavl_t i = (mavl_t) t;
@ -83,7 +83,7 @@ void free_avltree(void*t){
const struct mbag_typedef mbag_type_avltree = {
"mavl",free_avltree
};
*/
@ -493,7 +493,7 @@ mbag_item_t * mbag_set_bstrn(mbag_t s, const char *id, uint8_t * data, int len)
}
/*
struct mavl *mbag_get_mavl(mbag_t s, const char *id)
{
@ -524,6 +524,7 @@ int mbag_set_mavl(mbag_t s, const char *id, mavl_t t)
i->u2.data = t;
return 1;
}
*/
/*
struct mavl *mbag_get_avltree_c(mbag_t s, const char *id,
@ -545,7 +546,7 @@ struct mavl *mbag_get_avltree_c(mbag_t s, const char *id,
mavl_t mbag_get_mavl_c(mbag_t s, const char *id,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_get(s, id);
/* struct mbag_item *i = mbag_get(s, id);
if (i)
return i->u2.data;
@ -556,6 +557,7 @@ mavl_t mbag_get_mavl_c(mbag_t s, const char *id,
return NULL;
mbag_set_mavl(s, id, avltree);
return avltree;
*/
}
@ -608,7 +610,7 @@ mavl_t mbag_i_get_mbag_c(mbag_t s, uint32_t iid,
mavl_t mbag_i_get_mavl(mbag_t s, uint32_t id,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_i_get(s, id);
/* struct mbag_item *i = mbag_i_get(s, id);
if (i)
return i->u2.data;
@ -619,6 +621,7 @@ mavl_t mbag_i_get_mavl(mbag_t s, uint32_t id,
return NULL;
mbag_i_set_mavl(s, id, avltree);
return avltree;
*/
}

View File

@ -160,7 +160,6 @@ extern const struct mbag_typedef mbag_type_data;
*/
#define MBAG_PTR (&mbag_type_ptr)
#define MBAG_AVLTREE (&mbag_type_avltree)
#define MBAG_FUN MBAG_STR
#define MBAG_CONST_DATA (&mbag_type_const_data)
/** MBAG_SOCK_ADDR holds a sockkaddr structure */

View File

@ -198,17 +198,6 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
elemdef->vendor, elemdef->id, handler->name);
}
{
struct mlistelem *elem;
elem = mlist_get(msgdata->elements_list,&ed);
if (elem==NULL){
printf("Elem is not in mlist\n");
}
else{
printf("Elem was in mlsit\n");
}
}
/* add message elemeent to the elements list */
switch ( elemdef->op & 0xff){
case CW_IGNORE:
@ -224,15 +213,7 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
mlist_append(msgdata->elements_list, &ed);
}
break;
}
}

View File

@ -1,30 +0,0 @@
#include <string.h>
#include <stdlib.h>
#include "stravltree.h"
static int cmp(const void *v1,const void*v2)
{
return strcmp( (char*)v1,(char*)v2);
}
static void del(void* d)
{
free (d);
return;
}
struct avltree * stravltree_create()
{
return mavl_create(cmp,del,100);
}
const char * stravltree_add(struct avltree * t, const char * str)
{
char * s = strdup(str);
if (!s)
return 0;
return mavl_add(t,s,NULL);
}

View File

@ -1,13 +0,0 @@
#ifndef __STRAVLTREE_H
#define __STRAVLTREE_H
#include "mavl.h"
extern struct avltree * stravltree_create();
const char * stravltree_add(struct avltree * t, const char * str);
#define stravltree_destroy(t) mavl_destroy(t)
#define stravltree_foreach_asc(t,f,p) avltree_foreach_asc(t,f,p)
#define stravltree_foreach_desc(t,f,p) avltree_foreach_desc(t,f,p)
#endif

View File

@ -132,7 +132,7 @@ int capwap_in_wtp_board_data(struct cw_ElemHandler *eh, struct cw_ElemHandlerPar
mavl_t cfg = params->conn->remote_cfg;
sprintf(vendor_key,"%s/%s",eh->key,CW_KEY_VENDOR);
sprintf(vendor_key,"%s/%s",eh->key,CW_SKEY_VENDOR);
cw_ktv_add(cfg,vendor_key,CW_TYPE_DWORD,data,len);

View File

@ -15,8 +15,12 @@ int cisco_in_wtp_descriptor(struct cw_ElemHandler *eh, struct cw_ElemHandlerPara
extern int cisco_out_ac_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
extern int cisco_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
int cisco_out_wtp_descriptor(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst);
extern int cisco_out_board_data_options(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);

View File

@ -43,7 +43,7 @@
#include "cw/msgset.h"
#include "cw/ktv.h"
#include "cw/keys.h"
static struct cw_ElemHandler handlers[] = {
{
@ -52,8 +52,9 @@ static struct cw_ElemHandler handlers[] = {
0,0, /* Vendor / Proto */
4,128, /* min/max length */
NULL, /* type */
"wtp_descriptor", /* Key */
cisco_in_wtp_descriptor /* get */
CW_KEY_WTP_DESCRIPTOR, /* Key */
cisco_in_wtp_descriptor, /* get */
cisco_out_wtp_descriptor /* put */
}
,
{
@ -62,8 +63,9 @@ static struct cw_ElemHandler handlers[] = {
CW_VENDOR_ID_CISCO,0, /* Vendor / Proto */
1,512, /* min/max length */
CW_TYPE_BSTR16, /* type */
"wtp_name", /* Key */
cw_in_generic /* handler */
CW_KEY_WTP_NAME, /* Key */
cw_in_generic, /* get */
cw_out_generic /* put */
}
,
@ -71,10 +73,11 @@ static struct cw_ElemHandler handlers[] = {
"Board Data Options", /* name */
CW_CISCO_BOARD_DATA_OPTIONS, /* Element ID */
CW_VENDOR_ID_CISCO,0, /* Vendor / Proto */
2,2, /* min/max length */
4,4, /* min/max length */
CW_TYPE_DWORD, /* type */
"cisco_board_data_options", /* Key */
cw_in_generic /* handler */
"cisco/board-data-options", /* Key */
cw_in_generic, /* handler */
cw_out_generic /* put */
}
,
{0,0,0,0,0,0,0,0}

View File

@ -27,10 +27,10 @@ int cisco_in_wtp_descriptor(struct cw_ElemHandler *eh, struct cw_ElemHandlerPara
{
static struct cw_DescriptorSubelemDef allowed[] = {
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_KEY_HARDWARE, 1024,0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_KEY_SOFTWARE, 1024.0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_KEY_BOOTLOADER, 1024.0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_KEY_OTHER_SOFTWARE, 1024.0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_SKEY_HARDWARE, 1024,0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_SKEY_SOFTWARE, 1024.0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_SKEY_BOOTLOADER, 1024.0},
{CW_VENDOR_ID_CISCO,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_SKEY_OTHER_SOFTWARE, 1024.0},
{0,0, NULL, 0,0}
};

View File

@ -5,29 +5,86 @@
#include "cisco.h"
#include "cw/ktv.h"
#include "cw/keys.h"
#include "cw/dbg.h"
//#extern mbag_t cisco_config_wtp;
int cisco_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
// mbag_t mbag = cisco_config_wtp;
mbag_t mbag = NULL;
// XXX Dummy WTP Descriptor Header
uint8_t *d = dst+4;
char key[256];
int len;
/* // XXX Dummy WTP Descriptor Header */
uint8_t *d;
cw_KTV_t * val;
d = dst+4;
/*cw_ktv_init_byte(&val,8);*/
sprintf(key,"%s/%s",eh->key,CW_SKEY_MAX_RADIOS);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL)
d+=val->type->put(val,d);
else{
cw_dbg(DBG_WARN,"Cannot get value for %s, setting to 0", CW_SKEY_MAX_RADIOS);
d+=cw_put_byte(d,0);
}
sprintf(key,"%s/%s",eh->key,CW_SKEY_RADIOS_IN_USE);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL){
d+=val->type->put(val,d);
}
else{
d+=cw_put_byte(d,0); /*radios in use*/
}
//int n =conn->radios->count;
//printf("radio count %d\n",n);
/*len = handler->type->put(elem,dst+start);*/
d+=cw_put_byte(d,conn->radios->count); //max radios
d+=cw_put_byte(d,2); //radios in use
d+=cw_put_encryption_capabilities_7(d,1);
mbag_item_t * i;
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
*/
/* sprintf(key,"%s/%s/%s",eh->key,CW_SKEY_HARDWARE,CW_SKEY_VENDOR);
vendor = cw_ktv_get(params->conn->local_cfg,key,CW_TYPE_DWORD);
sprintf(key,"%s/%s/%s",eh->key,CW_SKEY_HARDWARE,CW_SKEY_VENDOR);
version = cw_ktv_get(params->conn->local_cfg,key,CW_TYPE_BSTR16);
if (vendor == NULL){
cw_log(LOG_ERR, "Can't send %s, not found.", key);
}
*/
/* hardware version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_HARDWARE_VERSION, key);
/* software version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_SOFTWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_SOFTWARE_VERSION, key);
/* bootloader version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_BOOTLOADER);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_BOOTLOADER_VERSION, key);
/* mbag_item_t * i;
i = mbag_get(mbag,CW_ITEM_WTP_HARDWARE_VERSION);
*/
/* if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->u2.data);
}
@ -36,7 +93,7 @@ mbag_t mbag = NULL;
}
*/
i = mbag_get(mbag,CW_ITEM_WTP_SOFTWARE_VERSION);
/*i = mbag_get(mbag,CW_ITEM_WTP_SOFTWARE_VERSION);*/
/*
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_SOFTWARE_VERSION,i->u2.data);
@ -54,6 +111,6 @@ mbag_t mbag = NULL;
}
*/
int len = d-dst-4;
return len + cw_put_elem_hdr(dst,a->elem_id,len);
len = d-dst-4;
return len + cw_put_elem_hdr(dst,eh->id,len);
}

View File

@ -18,13 +18,19 @@ static int run_discovery(struct conn *conn)
{
/*// conn->incomming = mbag_create();*/
time_t timer;
uint8_t dtype=0;
conn->capwap_state = CAPWAP_STATE_DISCOVERY;
cw_ktv_add(conn->local_cfg, "discovery_type", CW_TYPE_BYTE, &dtype,1);
/* mbag_set_byte(conn->outgoing, CW_ITEM_DISCOVERY_TYPE,
CAPWAP_DISCOVERY_TYPE_UNKNOWN);
*/
cw_init_request(conn, CAPWAP_MSG_DISCOVERY_REQUEST);
cw_put_msg(conn, conn->req_buffer);
conn_send_msg(conn, conn->req_buffer);

View File

@ -65,12 +65,14 @@ static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
}
int main (int argc, char **argv)
{
struct bootcfg bootcfg;
struct cw_Mod * mod;
struct cw_MsgSet * msgset;
struct conn * conn;
FILE * file;
parse_args(argc,argv, &bootcfg);
@ -101,8 +103,16 @@ int main (int argc, char **argv)
conn->dtls_mtu = 12000;
conn->msgset=msgset;
conn->local_cfg = cw_ktv_create();
file = fopen(bootcfg.cfgfilename,"r");
if (file == NULL){
cw_log(LOG_ERR,"Cant open file '%s':%s", strerror(errno));
exit(EXIT_FAILURE);
}
cw_run_discovery(conn, "255.255.255.255","192.168.0.14");
cw_ktv_read_file(file,conn->local_cfg,msgset->types_tree);
cw_run_discovery(conn, "255.255.255.255",NULL);
return (EXIT_SUCCESS);