diff --git a/src/capwap/aciplist.h b/src/capwap/aciplist.h new file mode 100644 index 00000000..88168547 --- /dev/null +++ b/src/capwap/aciplist.h @@ -0,0 +1,22 @@ +#ifndef __ACIPLIST_H +#define __ACIPLIST_H + +#include "avltree.h" + +struct cw_acip{ + struct sockaddr_storage ip; + int wtp_count; +}; + +typedef struct cw_acip cw_acip_t; + +typedef struct avltree * cw_aciplist_t; + +extern cw_aciplist_t cw_aciplist_create(); + +#define cw_aciplist_destroy(l) avltree_destroy(l) +#define cw_aciplist_add(l,elem) avltree_add(l,elem) +#define cw_aciplist_foreach(l,callback,cbpriv) avltree_foreach_asc(l,callback,cbpriv) + +#endif + diff --git a/src/capwap/action.c b/src/capwap/action.c new file mode 100644 index 00000000..dfe7ceb7 --- /dev/null +++ b/src/capwap/action.c @@ -0,0 +1,174 @@ +/* + This file is part of libcapwap. + + libcapwap is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + libcapwap is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Foobar. If not, see . + +*/ + +/** + * @file + * @brief Implementation of methods for actionlists. + */ + + +#include +#include + +#include "action.h" + +static inline int cw_action_in_cmp(const void *elem1,const void *elem2) +{ + struct cw_action_in * e1 = (struct cw_action_in*)elem1; + struct cw_action_in * e2 = (struct cw_action_in*)elem2; + int r; + + r = e1->msg_id - e2->msg_id; + if (r!=0) + return r; + + r = e1->capwap_state - e2->capwap_state; + if (r!=0) + return r; + + r = e1->elem_id - e2->elem_id; + if (r!=0) + return r; + + r = e1->vendor_id - e2->vendor_id; + if (r!=0) + return r; + + r = e1->proto - e2->proto; + if (r!=0) + return r; + + + + return 0; +} + + +cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a) +{ + struct cw_action_in *an = malloc(sizeof(struct cw_action_in)); + if (!an) + return NULL; + + memcpy(an,a,sizeof(struct cw_action_in)); + return avltree_add(t,an); +} + + +struct cw_action_in * cw_actionlist_in_get(cw_actionlist_in_t t,struct cw_action_in *a) +{ + return avltree_get(t,a); +} + + +cw_actionlist_in_t cw_actionlist_in_create() +{ + return avltree_create(cw_action_in_cmp,free); +} + + +int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions) +{ + while(actions->capwap_state){ + cw_action_in_t * rc = cw_actionlist_in_add(t,actions); + if (rc==0) + return 0; + actions++; + } + return 1; +} + +int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions) +{ + while(actions->msg_id!=0){ + cw_action_out_t * rc = cw_actionlist_out_add(t,actions); + if (rc==0) + return 0; + actions++; + } + return 1; +} + + + + +/* + * Compare function for actionlist_out_t lists + */ +static int cw_action_out_cmp(const void *elem1,const void *elem2) +{ + struct cw_action_out * e1 = (struct cw_action_out*)elem1; + struct cw_action_out * e2 = (struct cw_action_out*)elem2; + int r; + + r = e1->msg_id - e2->msg_id; + if (r!=0) + return r; + + r = e1->item_id - e2->item_id; + if (r!=0) + return r; + + return 0; +} + + + +/** + * Add an action to an action + * @param t actionlist + * @param a action to add + * @param s size of element to add + * @return pointer to added element or NULL if an error has opccured + */ +void * cw_actionlist_add(struct avltree *t, void *a, size_t s) +{ + uint8_t * an = malloc(s); + if (!an) + return NULL; + + memcpy(an,a,s); + void * r = avltree_add(t,an); + if (r==an) + return r; + + /* action already exists, replace */ + memcpy(r,an,sizeof(struct cw_action_out)); + free (an); + return r; + +} + + +/** + * Create an action list for outgoing message lements + * @return the created action list or NULL if an erro has occured. + */ +cw_actionlist_out_t cw_actionlist_out_create() +{ + return avltree_create(cw_action_out_cmp,free); +} + + +cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a) +{ + return cw_actionlist_add(t,a,sizeof (struct cw_action_out)); + +} + + diff --git a/src/capwap/action.h b/src/capwap/action.h new file mode 100644 index 00000000..cdd40a86 --- /dev/null +++ b/src/capwap/action.h @@ -0,0 +1,95 @@ +/* + This file is part of libcapwap. + + libcapwap is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + libcapwap is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Foobar. If not, see . + +*/ + + +#ifndef __ACTION_H +#define __ACTION_H + +#include + +#include "avltree.h" +#include "conn.h" +#include "itemstore.h" + + +/* Generic functions and structs */ +void * cw_actionlist_add(struct avltree *t, void *a, size_t s); + + + +/* Definitions for incomming messages */ +struct cw_action_in{ + uint32_t vendor_id; + uint8_t proto; + uint8_t capwap_state; + uint32_t msg_id; + uint16_t elem_id; + int (*start)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len); + int (*end)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len); + uint8_t itemtype; + uint16_t item_id; + uint16_t min_len; + uint16_t max_len; +}; + + +typedef struct cw_action_in cw_action_in_t; + + +typedef struct avltree * cw_actionlist_in_t; + +extern cw_actionlist_in_t cw_actionlist_in_create(); +extern cw_action_in_t * cw_actionlist_in_get(cw_actionlist_in_t t,cw_action_in_t *a); +extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a); +extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions); + + +/* Definitions for outgoing messages */ +struct cw_action_out{ + uint32_t msg_id; + uint32_t item_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); + +}; +typedef struct cw_action_out cw_action_out_t; + +typedef struct avltree *cw_actionlist_out_t; +extern cw_actionlist_out_t cw_actionlist_out_create(); +extern cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a); +extern int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions); +#define cw_actionlist_out_get(t,a) avltree_get(t,a); + + + + +struct cw_actiondef{ + cw_actionlist_in_t in; + cw_actionlist_out_t out; +}; + + + +#define cw_actionlist_get_node(t,a) avltree_get_node(t,a) + +#endif + + diff --git a/src/capwap/avltree_foreach_lr.c b/src/capwap/avltree_foreach_lr.c new file mode 100644 index 00000000..599d7bd0 --- /dev/null +++ b/src/capwap/avltree_foreach_lr.c @@ -0,0 +1,17 @@ +#include "avltree.h" + + + +int avltree_foreach_lr(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv) +{ + if (!n) + return 1; + if (!avltree_foreach_lr(n->left,callback,cbpriv)) + return 0; + if (!callback(cbpriv,n->data)) + return 0; + return avltree_foreach_lr(n->right,callback,cbpriv); + +} + + diff --git a/src/capwap/avltree_foreach_node.c b/src/capwap/avltree_foreach_node.c new file mode 100644 index 00000000..5e0ada87 --- /dev/null +++ b/src/capwap/avltree_foreach_node.c @@ -0,0 +1,33 @@ + + + +int avltree_foreach_lr_node(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv) +{ + if (!n) + return 1; + + int rc=t->cmp(data,n->data); + if (rc<0){ + avltree_foreach_lr_node(t,n->left,data,callback,cbpriv); + callback(cbpriv,n->data); + avltree_foreach_lr(n->right, + return 0; + } + + if (rc>0) { + avltree_foreach_lr_node(t,n->right,data,callback,cbpriv); + return 0; + } + + return callback(cbpriv,n->data); + + + + +} + + +int avltree_foreach_2(struct avltree *t,void *data,int (*callback)(void *,void *),void *cbpriv) +{ + +} diff --git a/src/capwap/avltree_foreach_rl.c b/src/capwap/avltree_foreach_rl.c new file mode 100644 index 00000000..7ee82a8f --- /dev/null +++ b/src/capwap/avltree_foreach_rl.c @@ -0,0 +1,18 @@ + + + + +#include "avltree.h" + +int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv) +{ + if (!n) + return 1; + if (!avltree_foreach_rl(n->right,callback,cbpriv)) + return 0; + if (!callback(cbpriv,n->data)) + return 0; + return avltree_foreach_rl(n->left,callback,cbpriv); +} + +