Work on cs_MsgSet

FossilOrigin-Name: 22ea5e3947fb5fa1b70d9384d7120ff5ae65eeb8924b724afebc0170a8f4fe3f
This commit is contained in:
7u83@mail.ru
2018-02-24 22:58:31 +00:00
parent f4723a33da
commit 8ec78cea1b
19 changed files with 169 additions and 87 deletions

View File

@ -242,7 +242,11 @@
#define CW_ELEM_RETURNED_MESSAGE_ELEMENT 34
#define CW_ELEM_SESSION_ID 35
#define CW_ELEM_STATISTICS_TIMER 36
#define CW_ELEM_VENDOR_SPECIFIC_PAYLOAD 37
/**
* The Vendor Specific Payload allows tronasport of
* vebdor defined data.*/
#define CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD 37
#define CAPWAP_ELEM_WTP_BOARD_DATA 38
/**
* The WTP Descriptor message element conteins information

View File

@ -43,7 +43,7 @@ struct cw_strlist_elem capwap_strings_elem[] = {
{CW_ELEM_RETURNED_MESSAGE_ELEMENT, "Returned Message Element"},
{CW_ELEM_SESSION_ID, "Session ID"},
{CW_ELEM_STATISTICS_TIMER, "Statistics Timer"},
{CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, "Vendor Specific Payload"},
{CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, "Vendor Specific Payload"},
{CAPWAP_ELEM_WTP_BOARD_DATA, "WTP Board Data"},
{CAPWAP_ELEM_WTP_DESCRIPTOR, "WTP Descriptor"},
{CW_ELEM_WTP_FALLBACK, "WTP Fallback"},

View File

@ -104,36 +104,34 @@
typedef struct{
int proto;
int vendor;
int id;
int mand;
}cw_messagedef_t;
typedef struct {
int type;
int * states;
cw_messagedef_t * elements;
const char * name;
}cw_message_t;
typedef struct {
int proto;
int vendor;
int id;
int min_len;
int max_len;
const char * name;
}cw_message_element_t;
}cw_msgelemdef_t;
typedef struct {
mavl_t messages;
mavl_t all_elems;
}cw_message_set_t;
typedef struct{
cw_msgelemdef_t * elem;
int mand;
}cw_msgelemprops_t;
typedef struct {
int type;
int * states;
cw_msgelemprops_t * elements;
const char * name;
}cw_msgdef_t;
/**
* Get length wireless specific data
@ -390,7 +388,7 @@ static inline int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;

View File

@ -42,7 +42,7 @@ int cw_addelem_vendor_specific_payload(uint8_t * dst, uint32_t vendor_id,
d += cw_put_data(d, data, len);
int l = d - dst;
cw_put_elem_hdr(dst, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4);
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4);
return l;
}

View File

@ -53,7 +53,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
uint8_t *dst = msgptr+8;
mlist_t *m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
if (!m){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
@ -69,7 +69,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
int len = 0;
for (e=m->list; e; e=e->next) {
for (e=m->first; e; e=e->next) {
cw_action_out_t *ae=(cw_action_out_t*)e->data;
//printf("Put %d %i %s\n",ae->msg_id,ae->elem_id,ae->item_id);

View File

@ -549,7 +549,7 @@ void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem,
char vendor_details[265];
*vendor_details = 0;
if (msgelem == CW_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
if (msgelem == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf));
int type = ntohs(*((uint16_t *) (msgbuf + 4)));
cw_format_vendor(vendor_details, vendor_id, type, msgbuf);

View File

@ -1,6 +1,7 @@
#include "cw.h"
#include "mavl.h"
#include "cw/dbg.h"
#include "message_set.h"
@ -12,9 +13,9 @@ typedef struct {
mlist_t elements_list;
}message2_t;
static inline int cmp_cw_message_element(const void *elem1, const void *elem2){
cw_message_element_t * e1 = (cw_message_element_t*)elem1;
cw_message_element_t * e2 = (cw_message_element_t*)elem2;
static inline int cmp_cw_msgelemprops(const void *elem1, const void *elem2){
cw_msgelemdef_t * e1 = ((cw_msgelemprops_t*)elem1)->elem;
cw_msgelemdef_t * e2 = ((cw_msgelemprops_t*)elem2)->elem;
int r;
r = e1->id - e2->id;
if (r!=0)
@ -58,7 +59,7 @@ cw_message_set_t * cw_message_set_create(){
memset(set,0,sizeof(cw_message_set_t));
/* create mavl for all_elems */
set->all_elems = mavl_create(cmp_cw_message_element,NULL);
set->all_elems = mavl_create(cmp_cw_msgelemprops,NULL);
if (set->all_elems==NULL){
cw_message_set_destroy(set);
return NULL;
@ -76,25 +77,85 @@ cw_message_set_t * cw_message_set_create(){
}
static void update_message(message2_t * msg, cw_msgdef_t * src, cw_message_set_t * set){
void cw_message_set_add(cw_message_set_t * set,
cw_message_t messages[],
cw_message_element_t elements[]){
cw_msgelemprops_t *md;
cw_message_element_t * e;
for (e=elements; e->id!=0; e++){
mavl_replace(set->all_elems, e);
}
cw_message_t * m;
for (m=messages; m->type !=0; m++){
printf("MESS: %d %s",m->type, m->name);
for (md = src->elements; md->elem!=0; md++){
cw_dbg(DBG_INFO," add element %d - %s, %d",md->elem->id, md->elem->name, md->mand);
mavl_add(msg->elements_tree,md);
mavl_add(set->all_elems,md);
mlist_append(msg->elements_list,md);
mlist_replace(msg->elements_list,NULL,md);
}
}
cw_message_element_t * cw_message_set_find_element(
void cw_message_set_add(cw_message_set_t * set,
cw_msgdef_t messages[]){
cw_msgdef_t * m;
for (m=messages; m->type !=0; m++){
message2_t search, *next;
search.type = m->type;
cw_dbg(DBG_INFO,"Add message: Type:%d - %s",m->type,m->name);
next = mavl_find(set->messages,&search);
/** message not already in memory,
* create a new one */
if (next == NULL){
next = malloc (sizeof(message2_t));
if (next == NULL)
return;
next->elements_tree = mavl_create(cmp_cw_msgelemprops,NULL);
if (next->elements_tree==NULL){
free(next);
return;
}
next->elements_list = mlist_create(cmp_cw_msgelemprops);
if (next->elements_list == NULL){
mavl_destroy(next->elements_tree);
free(next);
return;
}
next->type=m->type;
mavl_add(set->messages,next);
}
/* massage is alreaddy in there */
if (m->name)
next->name=m->name;
if (m->states)
next->states=m->states;
update_message(next,m, set);
}
}
cw_msgelemdef_t * cw_message_set_find_element(
cw_message_set_t * set,
cw_message_element_t * element){
cw_msgelemdef_t * element){
return mavl_find(set->all_elems,element);
}
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type){
message2_t search;
search.type = type;
message2_t * result = mavl_find(set->messages,&search);
if (!result){
printf ("no result\n");
return NULL;
}
return result->elements_list;
}

View File

@ -6,6 +6,6 @@
extern void cw_message_set_destroy(cw_message_set_t * set);
extern cw_message_set_t * cw_message_set_create();
extern void cw_message_set_add(cw_message_set_t * set,
cw_message_t messages[],
cw_message_element_t elements[]);
cw_msgdef_t messages[]);
mlist_t cw_msgset_get_msg(cw_message_set_t * set, int type);
#endif

View File

@ -1,22 +1,22 @@
#include <stdlib.h>
#include <string.h>
#include "mlist.h"
mlist_t *mlist_create(int (*cmp) (void *v1, void *v2))
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2))
{
mlist_t *l = malloc(sizeof(mlist_t));
struct mlist * l = malloc(sizeof(struct mlist));
if (!l)
return NULL;
memset(l, 0, sizeof(mlist_t));
memset(l, 0, sizeof(struct mlist));
l->cmp = cmp;
return l;
}
struct mlist_elem *mlist_append(mlist_t * l, void *data)
struct mlist_elem * mlist_append(mlist_t l, void *data)
{
struct mlist_elem **n = &l->list;
struct mlist_elem **n = &l->first;
while (*n != NULL)
n = &(*n)->next;
*n = malloc(sizeof(struct mlist_elem));
@ -29,13 +29,13 @@ struct mlist_elem *mlist_append(mlist_t * l, void *data)
return *n;
}
struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data)
struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data)
{
struct mlist_elem *e;
if (start)
e = start;
else
e = l->list;
e = l->first;
while (e) {
if (l->cmp(e->data, data) == 0)
@ -47,13 +47,13 @@ struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data)
}
struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, void *data)
struct mlist_elem * mlist_replace(mlist_t l, struct mlist_elem *start, void *data)
{
struct mlist_elem *e;
if (start)
e = start;
else
e = l->list;
e = l->first;
struct mlist_elem * f = mlist_find(l,e,data);
if (!f)

View File

@ -46,22 +46,23 @@ struct mlist_elem {
struct mlist {
void *data;
int (*cmp) (void *d1, void *d2);
struct mlist_elem *list;
int (*cmp) (const void *d1, const void *d2);
struct mlist_elem *first;
};
typedef struct mlist mlist_t;
typedef struct mlist * mlist_t;
/**
* defgroup MLIST_FUNCTIONS
* @{
*/
extern mlist_t *mlist_create(int (*cmp) (void *v1, void *v2));
extern struct mlist_elem *mlist_append(mlist_t * l, void *data);
extern struct mlist_elem *mlist_find(mlist_t * l, struct mlist_elem *start, void *data);
extern struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, void *data);
extern mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2));
extern struct mlist_elem *mlist_append(mlist_t l, void *data);
extern struct mlist_elem *mlist_find(mlist_t l, struct mlist_elem *start, void *data);
extern struct mlist_elem *mlist_replace(mlist_t l, struct mlist_elem *start, void *data);
#define mlist_add mlist_append
/**
* @}
*/
@ -70,7 +71,7 @@ extern struct mlist_elem *mlist_replace(mlist_t *l, struct mlist_elem *start, vo
#define mlist_foreach(i,l)\
for (i=l->data; i; i=i->next)
for (i=l->first; i; i=i->next)