Initial commit.
FossilOrigin-Name: 33449a23862bb9bb64d23c0f680217d08c36d4ffd717bcd89e19d88f171f81bd
This commit is contained in:
parent
e74e8772f8
commit
95d19ace38
73
src/capwap/cw_action.c
Normal file
73
src/capwap/cw_action.c
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cw_action.h"
|
||||
|
||||
static inline int cw_action_cmp(const void *elem1,const void *elem2)
|
||||
{
|
||||
struct cw_action * e1 = (struct cw_action*)elem1;
|
||||
struct cw_action * e2 = (struct cw_action*)elem2;
|
||||
int r;
|
||||
|
||||
r = e1->elem_id - e2->elem_id;
|
||||
if (r!=0)
|
||||
return 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;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cw_action_del(void*d)
|
||||
{
|
||||
free(d);
|
||||
}
|
||||
|
||||
cw_action_t * cw_actionlist_add(cw_actionlist_t t, struct cw_action * a)
|
||||
{
|
||||
struct cw_action *an = malloc(sizeof(struct cw_action));
|
||||
if (!an)
|
||||
return NULL;
|
||||
|
||||
memcpy(an,a,sizeof(struct cw_action));
|
||||
return avltree_add(t,an);
|
||||
}
|
||||
|
||||
|
||||
struct cw_action * cw_actionlist_get(cw_actionlist_t t,struct cw_action *a)
|
||||
{
|
||||
return avltree_get(t,a);
|
||||
}
|
||||
|
||||
|
||||
cw_actionlist_t cw_actionlist_create()
|
||||
{
|
||||
return avltree_create(cw_action_cmp,cw_action_del);
|
||||
}
|
||||
|
||||
|
||||
int cw_register_actions(cw_actionlist_t t,cw_action_t * actions)
|
||||
{
|
||||
while(actions->capwap_state){
|
||||
cw_action_t *a = actions;
|
||||
printf("State: %d MSG_ID: %d ELEM_ID: %d\n",a->capwap_state,a->msg_id,a->elem_id);
|
||||
cw_action_t * rc = cw_actionlist_add(t,actions);
|
||||
if (rc==0)
|
||||
return 0;
|
||||
actions++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
39
src/capwap/cw_action.h
Normal file
39
src/capwap/cw_action.h
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#ifndef __MSGTREE_H
|
||||
#define __MSGTREE_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "avltree.h"
|
||||
|
||||
struct cw_action{
|
||||
uint8_t capwap_state;
|
||||
uint32_t msg_id;
|
||||
uint16_t elem_id;
|
||||
uint32_t vendor_id;
|
||||
uint16_t vendor_elem_id;
|
||||
|
||||
int (*start)(struct conn *conn,struct cw_action *a,uint8_t*data,int len);
|
||||
int (*end)(struct conn *conn,struct cw_action *a,uint8_t*data,int len);
|
||||
|
||||
|
||||
const char *name;
|
||||
};
|
||||
typedef struct cw_action cw_action_t;
|
||||
|
||||
|
||||
typedef struct avltree * cw_actionlist_t;
|
||||
|
||||
|
||||
extern cw_actionlist_t cw_actionlist_create();
|
||||
extern cw_action_t * cw_actionlist_get(cw_actionlist_t t,cw_action_t *a);
|
||||
extern cw_action_t * cw_actionlist_add(cw_actionlist_t t,cw_action_t *a);
|
||||
extern int cw_register_actions(cw_actionlist_t t,cw_action_t * actions);
|
||||
|
||||
int check(uint8_t *elem,int len);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
65
src/capwap/cw_process_msg.c
Normal file
65
src/capwap/cw_process_msg.c
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "conn.h"
|
||||
#include "capwap.h"
|
||||
#include "cw_action.h"
|
||||
|
||||
int cw_process_msg(struct conn * conn,uint8_t * rawmsg,int len)
|
||||
{
|
||||
struct cw_action as,*af;
|
||||
|
||||
|
||||
uint8_t * msg_ptr = rawmsg+cw_get_hdr_msg_offset(rawmsg);
|
||||
|
||||
/* prepare struct for search operation */
|
||||
as.elem_id=-1;
|
||||
as.capwap_state=conn->capwap_state;
|
||||
as.msg_id = cw_get_msg_id(msg_ptr);
|
||||
|
||||
/* Search for state/message combination */
|
||||
af = cw_actionlist_get(conn->msgtr,&as);
|
||||
|
||||
if ( !af ){
|
||||
printf("Error - Message not found: %d\n",as.msg_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (af->start){
|
||||
af->start(conn,af,rawmsg,len);
|
||||
}
|
||||
|
||||
int elems_len = cw_get_msg_elems_len(msg_ptr);
|
||||
uint8_t * elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
|
||||
|
||||
|
||||
|
||||
uint8_t *elem;
|
||||
|
||||
cw_foreach_elem(elem,elems_ptr,elems_len) {
|
||||
|
||||
as.elem_id = cw_get_elem_id(elem);
|
||||
int elem_len = cw_get_elem_len(elem);
|
||||
|
||||
af = cw_actionlist_get(conn->msgtr,&as);
|
||||
|
||||
if (!af) {
|
||||
printf("Wrong Elem: %d, %d\n",as.elem_id,elem_len);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("Elem OK: %d, %d\n",as.elem_id,elem_len);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user