More work on CAPWAP VM

FossilOrigin-Name: 9d9a86d2bafe31253a6f505e874f188792539485bb4462f4d778e6c53ac3000b
This commit is contained in:
7u83@mail.ru 2015-04-05 18:27:17 +00:00
parent ab8128a20f
commit 1158167262
33 changed files with 648 additions and 532 deletions

View File

@ -198,7 +198,7 @@ AP = RAD = WTP
| ResetBtnState |
+-+-+-+-+-+-+-+-+
Type: 128 for Cisco Rest Button State
Type: 128 for Cisco Reset Button State
Length: 1
ResetBtnState: 1 = Enabeled

View File

@ -98,7 +98,13 @@ int readelem_cisco_rad_name(struct conn *conn,struct cw_action * a,uint8_t *data
*/
/*
int avlprint(void *priv, void *data)
{
struct cw_str * d = (struct cw_str*) data;
printf("String: %d - %s\n",d->id,d->str);
}
*/
int main (int argc, const char * argv[])
{
@ -117,7 +123,19 @@ int main (int argc, const char * argv[])
cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP;
cw_register_actions_capwap_ac(&capwap_actions);
cw_register_actions_cipwap_ac(&capwap_actions);
/*
struct avltree *avlt = capwap_actions.strelem;
avltree_foreach_asc(avlt,avlprint,0);
exit(0);
*/
ac_global_init();
/*

View File

@ -353,6 +353,7 @@ static struct cwrmsg * wtpman_wait_for_message(struct wtpman * wtpman, time_t ti
return cwrmsg;
}
int conn_msg_processor(struct conn *conn);
static void wtpman_run_discovery(void *arg)
@ -361,7 +362,6 @@ static void wtpman_run_discovery(void *arg)
struct wtpman * wtpman = (struct wtpman *)arg;
struct cwrmsg * cwrmsg;
void conn_msg_processor(struct conn *conn);
time_t timer = cw_timer_start(10);
@ -370,7 +370,6 @@ extern cw_actionlist_in_t the_tree;
wtpman->conn->capwap_state=CW_STATE_DISCOVERY;
wtpman->conn->actions = &capwap_actions;
wtpman->conn->itemstore = cw_itemstore_create();
wtpman->conn->local = ac_config;
wtpman->conn->remote = cw_itemstore_create();
@ -379,6 +378,12 @@ extern cw_actionlist_in_t the_tree;
conn_msg_processor(wtpman->conn);
}
struct cw_item * wn = cw_itemstore_get(wtpman->conn->remote,CW_ITEM_WTP_NAME);
if (wn ) {
printf("WTP Name: %s\n",wn->data);
}
wtpman_remove(wtpman);
return;
@ -594,16 +599,20 @@ wtpman->conn->capwap_state=CW_STATE_JOIN;
wtpman->conn->capwap_state=CW_STATE_JOIN;
wtpman->conn->actions = &capwap_actions;
wtpman->conn->itemstore = cw_itemstore_create();
// wtpman->conn->itemstore = cw_itemstore_create();
wtpman->conn->local = ac_config;
wtpman->conn->remote = cw_itemstore_create();
while ( !cw_timer_timeout(timer) && wtpman->conn->capwap_state==CW_STATE_JOIN){
conn_msg_processor(wtpman->conn);
int rc = conn_msg_processor(wtpman->conn);
if (rc <0 ) {
break;
}
}
printf("Breaked\n");
exit(0);

View File

@ -169,12 +169,15 @@ CAPWAPOBJS= \
capwap_strings_elem.o \
itemstore.o \
cw_in_vendor_specific_payload.o \
cw_in_wtp_name.o \
cw_in_wtp_board_data.o \
cw_out_generic.o \
cw_out_ac_descriptor.o \
cw_out_capwap_control_ip_addrs.o
cw_out_cisco_ac_descriptor.o \
cw_out_cisco_ap_timesync.o \
cw_out_capwap_control_ip_addrs.o \
strheap.o
#cw_in_wtp_name.o \
#cw_msgtostr.o \
#cw_msgelemtostr.o \
#cwmsg_addelem_ctrl_ip_addrs.o \
@ -265,6 +268,9 @@ CWACTION=action.o \
cw_in_generic.o \
cw_in_wtp_descriptor.o \
cipwap_actions_ac.o \
cipwap_strings_elem.o \
cw_put_msg.o \
capwap_action_helpers.o \

View File

@ -119,6 +119,10 @@ static int cw_action_out_cmp(const void *elem1,const void *elem2)
if (r!=0)
return r;
r = e1->vendor_id - e2->vendor_id;
if (r!=0)
return r;
return 0;
}
@ -163,3 +167,6 @@ cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_
}

View File

@ -25,6 +25,7 @@
#include "avltree.h"
#include "conn.h"
#include "itemstore.h"
#include "strheap.h"
/* Generic functions and structs */
@ -63,11 +64,12 @@ extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t
struct cw_action_out{
uint32_t msg_id;
uint32_t item_id;
uint32_t vendor_id;
uint16_t elem_id;
int (*out)(struct conn * conn, uint32_t elem_id, uint8_t * dst ,struct cw_item * item);
struct cw_item *(*get)(struct conn *conn,uint32_t item_id);
int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a);
};
typedef struct cw_action_out cw_action_out_t;
@ -84,6 +86,10 @@ extern int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_ou
struct cw_actiondef{
cw_actionlist_in_t in;
cw_actionlist_out_t out;
cw_strheap_t strmsg;
cw_strheap_t strelem;
};

View File

@ -19,7 +19,7 @@
/**
* @file
* @brief Yet another AVL tree implementation
*/
*/
#include <stdlib.h>
#include <stdio.h>
@ -32,35 +32,36 @@
* @param cmp pointer compare function
* @param del pointer to delete function which is called when an element will be deletet
* @return pointer to an #avltree struct
*/
struct avltree * avltree_create(int (*cmp)(const void*,const void*),void(*del)(void*))
*/
struct avltree *avltree_create(int (*cmp) (const void *, const void *),
void (*del) (void *))
{
struct avltree * t = malloc(sizeof(struct avltree));
struct avltree *t = malloc(sizeof(struct avltree));
if (!t)
return NULL;
t->root=0;
t->count=0;
t->cmp=cmp;
t->del=del;
t->root = 0;
t->count = 0;
t->cmp = cmp;
t->del = del;
return t;
}
struct avlnode * avlnode_create(void * data)
struct avlnode *avlnode_create(void *data)
{
struct avlnode * n = malloc(sizeof(struct avlnode));
if(!n)
struct avlnode *n = malloc(sizeof(struct avlnode));
if (!n)
return NULL;
n->left=n->right=0;
n->bal=0;
n->left = n->right = 0;
n->bal = 0;
n->data = data;
return n;
}
void avlnode_destroy(struct avltree *t,struct avlnode *n)
void avlnode_destroy(struct avltree *t, struct avlnode *n)
{
if(t->del){
if (t->del) {
t->del(n->data);
}
free(n);
@ -68,66 +69,62 @@ void avlnode_destroy(struct avltree *t,struct avlnode *n)
}
static int avltree_add0(struct avltree *t, struct avlnode ** parent, void ** data)
static int avltree_add0(struct avltree *t, struct avlnode **parent, void **data)
{
// struct avlnode * rn;
// struct avlnode * rn;
struct avlnode *tmp;
struct avlnode * n = *parent;
int rc=t->cmp(*data,n->data);
struct avlnode *n = *parent;
int rc = t->cmp(*data, n->data);
int bal;
if (rc==0){
*data=n->data;
int bal;
if (rc == 0) {
*data = n->data;
return 2;
}
if (rc<0){
if (n->left)
{
bal = avltree_add0(t,&n->left,data);
if (bal>1)
if (rc < 0) {
if (n->left) {
bal = avltree_add0(t, &n->left, data);
if (bal > 1)
return bal;
n->bal -=bal;
if (n->bal==0)
n->bal -= bal;
if (n->bal == 0)
return 0;
if (n->bal==-2){
if (n->left->bal==-1){
n->bal=0;
n->left->bal=0;
*parent=n->left;
tmp=n->left->right;
n->left->right=n;
n->left=tmp;
if (n->bal == -2) {
if (n->left->bal == -1) {
n->bal = 0;
n->left->bal = 0;
*parent = n->left;
tmp = n->left->right;
n->left->right = n;
n->left = tmp;
return 0;
}
if (n->left->bal==1){
*parent=n->left->right;
if ((*parent)->bal==1) {
n->bal=0;
n->left->bal=-1;
}
else if ((*parent)->bal==-1){
n->bal=1;
n->left->bal=0;
}
else{
n->bal=0;
n->left->bal=0;
if (n->left->bal == 1) {
*parent = n->left->right;
if ((*parent)->bal == 1) {
n->bal = 0;
n->left->bal = -1;
} else if ((*parent)->bal == -1) {
n->bal = 1;
n->left->bal = 0;
} else {
n->bal = 0;
n->left->bal = 0;
}
(*parent)->bal=0;
n->left->right=(*parent)->left;
(*parent)->left=n->left;
(*parent)->bal = 0;
n->left->right = (*parent)->left;
(*parent)->left = n->left;
tmp = (*parent)->right;
(*parent)->right=n;
n->left=tmp;
(*parent)->right = n;
n->left = tmp;
return 0;
}
}
//printf("!!!!left bal = %i\n",n->left->bal);
//exit(0);
@ -137,67 +134,63 @@ static int avltree_add0(struct avltree *t, struct avlnode ** parent, void ** da
}
/* n->left is 0 */
n->left=avlnode_create(*data);
n->left = avlnode_create(*data);
if (!n->left)
return 3;
t->count++;
if(n->right==0){
n->bal=-1;
if (n->right == 0) {
n->bal = -1;
return 1;
}
n->bal=0;
n->bal = 0;
return 0;
}
else{
if (n->right){
bal = avltree_add0(t,&n->right,data);
if(bal>1)
} else {
if (n->right) {
bal = avltree_add0(t, &n->right, data);
if (bal > 1)
return bal;
n->bal+=bal;
if (n->bal==0)
n->bal += bal;
if (n->bal == 0)
return 0;
if (n->bal==2){
if (n->right->bal==1){
n->bal=0;
n->right->bal=0;
*parent=n->right;
tmp=n->right->left;
n->right->left=n;
n->right=tmp;
if (n->bal == 2) {
if (n->right->bal == 1) {
n->bal = 0;
n->right->bal = 0;
*parent = n->right;
tmp = n->right->left;
n->right->left = n;
n->right = tmp;
return 0;
}
else if(n->right->bal==-1){
*parent=n->right->left;
} else if (n->right->bal == -1) {
*parent = n->right->left;
if ((*parent)->bal==-1) {
n->bal=0;
n->right->bal=1;
}
else if ((*parent)->bal==1){
n->bal=-1;
n->right->bal=0;
}
else{
n->bal=0;
n->right->bal=0;
if ((*parent)->bal == -1) {
n->bal = 0;
n->right->bal = 1;
} else if ((*parent)->bal == 1) {
n->bal = -1;
n->right->bal = 0;
} else {
n->bal = 0;
n->right->bal = 0;
}
(*parent)->bal=0;
n->right->left=(*parent)->right;
(*parent)->right=n->right;
(*parent)->bal = 0;
n->right->left = (*parent)->right;
(*parent)->right = n->right;
tmp = (*parent)->left;
(*parent)->left=n;
n->right=tmp;
(*parent)->left = n;
n->right = tmp;
return 0;
}
//printf("!!!!iright bal = %i\n",n->left->bal);
@ -211,16 +204,16 @@ static int avltree_add0(struct avltree *t, struct avlnode ** parent, void ** da
/* n->right is 0 */
n->right=avlnode_create(*data);
n->right = avlnode_create(*data);
if (!n->right)
return 3;
t->count++;
if(n->left==0){
n->bal=1;
if (n->left == 0) {
n->bal = 1;
return 1;
}
n->bal=0;
n->bal = 0;
return 0;
}
}
@ -232,18 +225,18 @@ static int avltree_add0(struct avltree *t, struct avlnode ** parent, void ** da
* @data pointer to element
* @return added alement or NULL if error.
*/
void * avltree_add(struct avltree *t, void * data)
void *avltree_add(struct avltree *t, void *data)
{
if (t->root==0){
if (t->root == 0) {
t->root = avlnode_create(data);
if (t->root)
t->count++;
return t->root->data;
}
void * d = data;
int rc = avltree_add0(t,&t->root,&d);
void *d = data;
int rc = avltree_add0(t, &t->root, &d);
if (rc>3)
if (rc > 3)
return NULL;
return d;
@ -252,21 +245,21 @@ void * avltree_add(struct avltree *t, void * data)
static void rot_l(struct avlnode *n, struct avlnode **parent)
{
struct avlnode *tmp;
*parent=n->right;
tmp=n->right->left;
n->right->left=n;
n->right=tmp;
*parent = n->right;
tmp = n->right->left;
n->right->left = n;
n->right = tmp;
}
static void rot_r(struct avlnode *n, struct avlnode **parent)
{
struct avlnode *tmp;
*parent=n->left;
tmp=n->left->right;
n->left->right=n;
n->left=tmp;
}
*parent = n->left;
tmp = n->left->right;
n->left->right = n;
n->left = tmp;
}
@ -308,84 +301,79 @@ static int avltree_delete_hi(struct avlnode **parent, void **data)
static void rot_rl(struct avlnode *n, struct avlnode **parent)
{
struct avlnode * tmp;
*parent=n->right->left;
n->right->left=(*parent)->right;
(*parent)->right=n->right;
struct avlnode *tmp;
*parent = n->right->left;
n->right->left = (*parent)->right;
(*parent)->right = n->right;
tmp = (*parent)->left;
(*parent)->left=n;
n->right=tmp;
(*parent)->left = n;
n->right = tmp;
}
static void rot_lr(struct avlnode *n, struct avlnode **parent)
{
struct avlnode * tmp;
*parent=n->left->right;
n->left->right=(*parent)->left;
(*parent)->left=n->left;
struct avlnode *tmp;
*parent = n->left->right;
n->left->right = (*parent)->left;
(*parent)->left = n->left;
tmp = (*parent)->right;
(*parent)->right=n;
n->left=tmp;
(*parent)->right = n;
n->left = tmp;
}
static int adj_bal_l(struct avlnode *n, struct avlnode **parent)
{
if (n->right->bal==1){
n->bal=0;
n->right->bal=0;
rot_l(n,parent);
if (n->right->bal == 1) {
n->bal = 0;
n->right->bal = 0;
rot_l(n, parent);
return 1;
}
else if(n->right->bal==0){
n->bal=1;
n->right->bal=-1;
rot_l(n,parent);
} else if (n->right->bal == 0) {
n->bal = 1;
n->right->bal = -1;
rot_l(n, parent);
return 0;
}else if(n->right->bal==-1){
// int rb;
n->bal=0;
n->right->bal=0;
// rb = n->right->left->bal;
n->right->left->bal=0;
rot_rl(n,parent);
} else if (n->right->bal == -1) {
// int rb;
n->bal = 0;
n->right->bal = 0;
// rb = n->right->left->bal;
n->right->left->bal = 0;
rot_rl(n, parent);
return 1;
}
// printf("adj bal l not handled \n");
// exit(0);
// printf("adj bal l not handled \n");
// exit(0);
return -11; /* that should never happen */
return -11; /* that should never happen */
}
int adj_bal_r(struct avlnode *n, struct avlnode **parent)
{
if (n->left->bal==-1){
n->bal=0;
n->left->bal=0;
rot_r(n,parent);
if (n->left->bal == -1) {
n->bal = 0;
n->left->bal = 0;
rot_r(n, parent);
return 1;
}
else if(n->left->bal==0){
n->bal=-1;
n->left->bal=1;
rot_r(n,parent);
} else if (n->left->bal == 0) {
n->bal = -1;
n->left->bal = 1;
rot_r(n, parent);
return 0;
}
else if(n->left->bal==1){
// int rb;
n->bal=0;
n->left->bal=0;
// rb = n->left->right->bal;
n->left->right->bal=0;
rot_lr(n,parent);
} else if (n->left->bal == 1) {
// int rb;
n->bal = 0;
n->left->bal = 0;
// rb = n->left->right->bal;
n->left->right->bal = 0;
rot_lr(n, parent);
return 1;
}
// printf("adj bal li left not handled \n");
// exit(0);
return -11; /* that should never happen */
// printf("adj bal li left not handled \n");
// exit(0);
return -11; /* that should never happen */
}
@ -393,29 +381,29 @@ int adj_bal_r(struct avlnode *n, struct avlnode **parent)
static int avltree_del_lo(struct avlnode **parent, void **data)
{
struct avlnode * n = *parent;
struct avlnode *n = *parent;
if(n->left!=0){
int bal = avltree_del_lo(&n->left,data);
n->bal+=bal;
if (n->bal==1){
if (n->left != 0) {
int bal = avltree_del_lo(&n->left, data);
n->bal += bal;
if (n->bal == 1) {
return 0;
}
if (n->bal!=2)
}
if (n->bal != 2)
return bal;
adj_bal_l(n,parent);
adj_bal_l(n, parent);
return 0;
}
/* found the lowest element */
*parent=n->right;
*parent = n->right;
*data = n->data;
free (n);
free(n);
return 1;
if (n->right){
if (n->right) {
free(n);
return 1;
}
@ -429,98 +417,98 @@ static int avltree_del_lo(struct avlnode **parent, void **data)
int avltree_del0(struct avltree *t, struct avlnode **parent, void **data)
{
struct avlnode * n = *parent;
struct avlnode *n = *parent;
int rc;
int bal;
rc = t->cmp(*data, n->data);
rc =t->cmp(*data,n->data);
if (rc==0){
if (n->right == 0 && n->left ==0){
*parent=0;
avlnode_destroy(t,n);
if (rc == 0) {
if (n->right == 0 && n->left == 0) {
*parent = 0;
avlnode_destroy(t, n);
return 1;
}
if (n->right && n->left==0){
*parent=n->right;
avlnode_destroy(t,n);
if (n->right && n->left == 0) {
*parent = n->right;
avlnode_destroy(t, n);
return 1;
}
if (n->left && n->right==0){
avlnode_destroy(t,n);
*parent=n->left;
if (n->left && n->right == 0) {
avlnode_destroy(t, n);
*parent = n->left;
return 1;
}
/* node has two childs */
if (t->del){
if (t->del) {
t->del(n->data);
}
t->count--;
bal = avltree_del_lo(&n->right,&n->data);
n->bal-= bal;
if (n->bal==-1)
bal = avltree_del_lo(&n->right, &n->data);
n->bal -= bal;
if (n->bal == -1)
return 0;
if (n->bal != -2)
return bal;
return adj_bal_r(n,parent);
return adj_bal_r(n, parent);
}
if (rc<0){
if (n->left)
{
bal = avltree_del0(t,&n->left,data);
if (bal==2)
if (rc < 0) {
if (n->left) {
bal = avltree_del0(t, &n->left, data);
if (bal == 2)
return 2;
n->bal+=bal;
if (n->bal==1)
n->bal += bal;
if (n->bal == 1)
return 0;
if (n->bal!=2)
if (n->bal != 2)
return bal;
return adj_bal_l(n,parent);
return adj_bal_l(n, parent);
}
return 2; /* not found */
}
else { /* rc must be > 0 */
if (n->right){
bal = avltree_del0(t,&n->right,data);
if (bal==2)
return 2; /* not found */
} else { /* rc must be > 0 */
if (n->right) {
bal = avltree_del0(t, &n->right, data);
if (bal == 2)
return 2;
n->bal-=bal;
if (n->bal==-1)
n->bal -= bal;
if (n->bal == -1)
return 0;
if (n->bal != -2)
return bal;
return adj_bal_r(n,parent);
return adj_bal_r(n, parent);
}
return 2; /* not found */
return 2; /* not found */
}
}
void * avltree_del(struct avltree *t, void *data)
void *avltree_del(struct avltree *t, void *data)
{
if (!t->root)
return NULL;
void *d = data;
int rc = avltree_del0(t,&t->root,&d);
if (rc==2)
return 0;
int rc = avltree_del0(t, &t->root, &d);
if (rc == 2)
return NULL;
return data;
}
@ -609,11 +597,13 @@ void walk(struct avlnode *n)
*/
/*
void avltree_destroy(struct avltree *t)
{
avltree_del_all(t);
free (t);
}
*/
//#include <time.h>

View File

@ -16,65 +16,81 @@
*/
/*
* yet another avl tree implementation!
/**
* @file
* @brief Yet another avl tree implementation!
*/
#ifndef __AVLTREE_H
#define __AVLTREE_H
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct avlnode{
void * data;
struct avlnode * left;
struct avlnode * right;
struct avlnode {
void *data;
struct avlnode *left;
struct avlnode *right;
int bal;
};
struct avltree{
struct avlnode * root;
int (*cmp)(const void*,const void*);
void(*del)(void*);
struct avltree {
struct avlnode *root;
int (*cmp) (const void *, const void *);
void (*del) (void *);
int count;
};
void avlnode_destroy(struct avltree *t,struct avlnode *n);
void avlnode_destroy(struct avltree *t, struct avlnode *n);
struct avltree * avltree_create(int (*cmp)(const void*,const void*),void(*del)(void*));
void avltree_destroy(struct avltree *t);
struct avltree *avltree_create(int (*cmp) (const void *, const void *),
void (*del) (void *));
//void avltree_destroy(struct avltree *t);
void avltree_del_all(struct avltree *t);
void * avltree_del(struct avltree *t, void *data);
void * avltree_add(struct avltree *t, void *data);
void *avltree_del(struct avltree *t, void *data);
void *avltree_add(struct avltree *t, void *data);
//void * avltree_get(struct avltree *t ,void *data);
struct avlnode * avltree_get_node(struct avltree *t ,void *data);
struct avlnode *avltree_get_node(struct avltree *t, void *data);
extern int avltree_foreach_lr(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv);
extern int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv);
int avltree_foreach_from_lr(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv);
extern int avltree_foreach_lr(struct avlnode *n, int (*callback) (void *, void *),
void *cbpriv);
extern int avltree_foreach_rl(struct avlnode *n, int (*callback) (void *, void *),
void *cbpriv);
int avltree_foreach_from_lr(struct avltree *t, struct avlnode *n, void *data,
int (*callback) (void *, void *), void *cbpriv);
//extern void avltree_foreach(struct avltree *t, int (*callback)(void *,void*),void *cbpriv,int dir);
static inline void * avltree_get(struct avltree *t ,void *data){
struct avlnode * n = avltree_get_node(t,data);
static inline void *avltree_get(struct avltree *t, void *data)
{
struct avlnode *n = avltree_get_node(t, data);
if (!n)
return NULL;
return n->data;
}
static inline void * avltree_replace_data(struct avltree *t ,void *data,int len) {
void * df = avltree_get(t,data);
if(!df)
static inline void *avltree_replace_data(struct avltree *t, void *data, int len)
{
void *df = avltree_get(t, data);
if (!df)
return NULL;
memcpy(df,data,len);
memcpy(df, data, len);
return df;
}
static inline void avltree_destroy(struct avltree *t)
{
avltree_del_all(t);
free (t);
}
#define avltree_find(t,d) avltree_get(t,d)
#define avltree_insert(t,d) avltree_add(t,d)
//#define avltree_walk(t,dir) avltree_foreach(t,dir)
@ -86,5 +102,3 @@ static inline void * avltree_replace_data(struct avltree *t ,void *data,int len)
#endif

View File

@ -13,14 +13,22 @@
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief Implementation of avltree_get
*/
#include <stdio.h>
#include "avltree.h"
/**
* Get an AVL tree element.
* @param data Element to get
* @return pointer to element or NULL if not found.
*/
void * avltree_get(struct avltree *t ,void *data)
{
struct avlnode *n = t->root;

View File

@ -34,6 +34,7 @@
#include "conn.h"
#include "lwapp.h"
#include "strheap.h"
/* capwap version and iana number */
#define CW_VERSION 0
@ -83,6 +84,9 @@ enum capwap_states {
#define CWTH_FLAGS_T 0x100 /* bit 8 type of payload frame */
/**
* CAWAP header flags.
*/
#define CW_FLAG_HDR_R1 0x01 /* bit 0 reserved 1 */
#define CW_FLAG_HDR_R2 0x02 /* bit 1 reserved 2 */
#define CW_FLAG_HDR_R3 0x04 /* bit 2 reserved 3 */
@ -521,6 +525,9 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le
#define cw_put_data lw_put_data
#define cw_put_bstr lw_put_bstr
#define cw_set_dword lw_set_dword
#define cw_get_byte lw_get_byte
#define cw_get_word lw_get_word
#define cw_get_dword lw_get_dword
@ -557,6 +564,36 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le
#define cw_get_hdr_msg_offset(th) (4*cw_get_hdr_hlen(th))
#define cw_get_hdr_msg_elems_offset(th) (cw_get_hdr_msg_offset(th)+8)
#define cw_set_hdr_preamble(th,v) ((*th)=v)
/**
* Set the HLEN field of a CAWAP Header
* @param th pointer to the header
* @param hlen velue to set (max. 5 bits)
*/
static inline void cw_set_hdr_hlen(uint8_t *th,int hlen){
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) <<19;
cw_set_dword(th,d);
}
/**
* Set CAPWAP header flags
* @param th pointer to header
* @param flags list of flags to set or unset
* @param set 1=set flag, 0=unset flag
*/
#define cw_set_hdr_flags(th,flags,set) \
( set ? ((*((uint32_t*)th)) |= htonl(flags)) : ((*((uint32_t*)th)) &= (0xffffffff^htonl(flags))) )
#define cw_set_hdr_flag_f(th,set) cw_set_hdr_flag(th, CW_FLAG_HDR_F)
/* Macros for message headers */
#define cw_get_msg_id(msgptr) (cw_get_dword(msgptr))
#define cw_get_msg_type(msgptr) cw_get_msg_id(msgptr)
@ -565,15 +602,6 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le
#define cw_get_msg_elems_ptr(msgptr) ((msgptr)+8)
#define cw_set_hdr_preamble(th,v) ((*th)=v)
#define cw_set_hdr_flags(th,val,set) \
( set ? ((*((uint32_t*)th)) |= htonl(val)) : ((*((uint32_t*)th)) &= (0xffffffff^htonl(val))) )
#define cw_set_hdr_flag_f(th,set) cw_set_hdr_flag(th, CW_FLAG_HDR_F)
#define cw_set_msg_id(msgptr,t) cw_put_dword(msgptr,t)
#define cw_set_msg_type(msgptr,t) cw_set_msg_id(msgptr,t)
#define cw_set_msg_seqnum(msgptr,s) cw_put_byte( (msgptr) +4,s);
@ -606,14 +634,14 @@ static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
* @pram e pointer to element (uint8_t*)
* @return type of element
*/
#define cw_get_elem_len(e) cw_get_word(e+2)
#define cw_get_elem_len(e) cw_get_word((e)+2)
/**
* Get a pointer to the data of a CAPWAP message element
* @param e pointer to message element
* @return pointer to data
*/
#define cw_get_elem_data(e) (e+4)
#define cw_get_elem_data(e) ((e)+4)
/**
* Iterate through message elements of a CAPWAP message
@ -770,19 +798,11 @@ extern int cw_send_configuration_update_response(struct conn *conn, int seqnum,
/* Message to text stuff */
struct cw_strlist {
uint32_t id;
const char *str;
};
extern const char *cw_strlist_get_str(struct cw_strlist *s, int id);
/* Constants to string conversion lists */
extern struct cw_strlist capwap_strings_msg[];
extern struct cw_strlist capwap_strings_state[];
extern struct cw_strlist capwap_strings_vendor[];
extern struct cw_strlist capwap_strings_elem[];
extern struct cw_str capwap_strings_msg[];
extern struct cw_str capwap_strings_state[];
extern struct cw_str capwap_strings_vendor[];
extern struct cw_str capwap_strings_elem[];
#define cw_strmsg(id) cw_strlist_get_str(capwap_strings_msg,id)
@ -791,6 +811,13 @@ extern struct cw_strlist capwap_strings_elem[];
#define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id)
#define cw_strelemp(p,id) cw_strheap_get((p)->strelem,id)
extern const char *cw_strlist_get_str(struct cw_str *s, int id);
int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len);
@ -806,13 +833,18 @@ extern int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8
int len);
//extern int cw_out_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
extern int cw_out_generic(struct conn *conn, uint32_t elem_id, uint8_t * dst,
struct cw_item *item);
extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
struct cw_item *item);
extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id,
uint8_t * dst, struct cw_item *item);
extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item);
//extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
//struct cw_item *item);
extern int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst); //,struct cw_item * item)
//extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id,
// uint8_t * dst, struct cw_item *item);
extern int cw_out_capwap_control_ip_addrs(struct conn *conn,struct cw_action_out *a,uint8_t *dst) ;
extern int cw_put_msg(struct conn *conn, uint8_t * rawout);
struct cw_ac_status {
@ -825,9 +857,42 @@ struct cw_ac_status {
int dtls_policy;
};
/**
* Put an cw_ac_stauts structure to a buffer
* @param dst destination buffer
* @param s #cw_ac_status to put
* @return number of bytes put
* This function is only useful (used) in conjunction with
* putting AC Descriptor message elements.
*/
static inline int cw_put_ac_status(uint8_t *dst, struct cw_ac_status *s){
uint8_t *d=dst;
d += cw_put_dword (d, (s->stations << 16) | (s->limit) );
d += cw_put_dword (d, (s->active_wtps <<16) | (s->max_wtps) );
d += cw_put_dword (d, (s->security<<24) | (s->rmac_field<<16) | (s->dtls_policy));
return d-dst;
}
static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint32_t vendor_id,bstr16_t data)
{
uint8_t *d=dst;
d += cw_put_dword(d,vendor_id);
d += cw_put_dword(d, (subelem_id<<16) | bstr16_len(data));
d += cw_put_data(d,bstr16_data(data),bstr16_len(data));
return d-dst;
}
int cw_register_actions_capwap_ac(struct cw_actiondef *def);
int cw_register_actions_cipwap_ac(struct cw_actiondef *def);
int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a);
#endif

View File

@ -61,7 +61,7 @@
CW_ITEM_WTP_MAC_TYPE, /* ID to use store */ \
1, 1 /* min/max length */
#define CW_ACTION_VENDOR_SPECIFIC_PAYLOAD \
#define CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD \
CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, /* Element ID */ \
cw_in_vendor_specific_payload, 0 /* start/end callback*/ \

View File

@ -21,13 +21,7 @@
#include "action.h"
#include "capwap_items.h"
#include "capwap_actions.h"
int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len)
{
conn->capwap_state=CW_STATE_NONE;
return 1;
}
#include "strheap.h"
@ -58,8 +52,7 @@ cw_action_in_t capwap_actions_ac_in[] = {
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE}
,
/* Vendor Specific Payload */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ELEM_VENDOR_SPECIFIC_PAYLOAD,
cw_in_vendor_specific_payload, 0}
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD}
,
/* -------------------------------------------------------------------------------*/
@ -90,6 +83,9 @@ cw_action_in_t capwap_actions_ac_in[] = {
/* Element WTP MAC Type */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE}
,
/* Element Vendor Specific Payload */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD}
,
@ -121,6 +117,7 @@ cw_action_in_t capwap_actions_ac_in[] = {
};
/*
int cw_out_ac_name(uint8_t * dst, struct cw_item *item)
{
@ -130,13 +127,8 @@ int cw_out_ac_name(uint8_t * dst, struct cw_item *item)
int len = cw_put_data(dst + 4, data, strlen((char *) data));
return len + cw_put_elem_hdr(dst, CW_ELEM_AC_NAME, len);
}
*/
struct cw_item *cw_get_local(struct conn *conn, uint32_t item_id)
{
struct cw_item i;
i.id = item_id;
return cw_itemstore_get(conn->local, item_id);
}
@ -145,26 +137,38 @@ cw_action_out_t capwap_actions_ac_out[] = {
,
/* AC Descriptor */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR,
CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0}
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0
,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0}
,
/* AC Name */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME,
CW_ELEM_AC_NAME, cw_out_generic, cw_get_local}
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME, 0,
CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_local}
,
/* List of CAPWAP Control IPv4 and IPv6 addresses */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_LIST,
0, cw_out_capwap_control_ip_addrs, cw_get_local}
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_LIST, 0,
0, cw_out_capwap_control_ip_addrs, cw_out_get_local}
,
/* -------------------------------------------------------------------------------
* Join Response OUT
*/
{CW_MSG_JOIN_RESPONSE, CW_ITEM_NONE}
,
/* Result Code */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local}
,
/* AC Descriptor */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0
,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0}
,
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME}
,
{CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE}
,
{0, 0}
@ -180,9 +184,18 @@ int cw_register_actions_capwap_ac(struct cw_actiondef *def)
{
def->in = cw_actionlist_in_create();
def->out = cw_actionlist_out_create();
def->strmsg = cw_strheap_create();
def->strelem = cw_strheap_create();
cw_actionlist_in_register_actions(def->in, capwap_actions_ac_in);
cw_actionlist_out_register_actions(def->out, capwap_actions_ac_out);
int rc ;
rc = cw_strheap_register_strings(def->strmsg,capwap_strings_msg);
rc += cw_strheap_register_strings(def->strelem,capwap_strings_elem);
printf("Registered %d strings\n",rc);
return 1;
}