A lot of Cisco stuff added
FossilOrigin-Name: ea4edc78cae6fe99d7b4b29d95a8c30a4672d1d1448c0597f5e65e2a74138b9b
This commit is contained in:
@ -59,10 +59,11 @@ CWSRC=\
|
||||
cw_in_check_join_resp.c\
|
||||
cw_in_generic.c\
|
||||
cw_in_generic_struct.c\
|
||||
cw_in_radio_generic_struct.c\
|
||||
cw_in_generic_enum.c\
|
||||
cw_out_generic_struct.c\
|
||||
cw_init_data_keep_alive_msg.c\
|
||||
cw_inline.c\
|
||||
cw_in_radio_generic.c\
|
||||
cw_in_wtp_reboot_statistics.c\
|
||||
cw_is_printable.c\
|
||||
cw_load_file.c\
|
||||
@ -100,6 +101,7 @@ CWSRC=\
|
||||
cw_write_descriptor_subelem.c\
|
||||
cw_read_from.c \
|
||||
cw_write_radio_element.c\
|
||||
cw_detect_nat.c\
|
||||
|
||||
KTVSRC=\
|
||||
cw_ktv_add.c\
|
||||
|
@ -244,12 +244,12 @@
|
||||
#define CAPWAP_ELEM_LOCATION_DATA 28
|
||||
#define CAPWAP_ELEM_MAXIMUM_MESSAGE_LENGTH 29
|
||||
#define CAPWAP_ELEM_MTU_DISCOVERY_PADDING 52
|
||||
#define CW_ELEM_RADIO_ADMINISTRATIVE_STATE 31
|
||||
#define CAPWAP_ELEM_RADIO_ADMINISTRATIVE_STATE 31
|
||||
#define CW_ELEM_RADIO_OPERATIONAL_STATE 32
|
||||
#define CAPWAP_ELEM_RESULT_CODE 33
|
||||
#define CW_ELEM_RETURNED_MESSAGE_ELEMENT 34
|
||||
#define CAPWAP_ELEM_SESSION_ID 35
|
||||
#define CW_ELEM_STATISTICS_TIMER 36
|
||||
#define CAPWAP_ELEM_STATISTICS_TIMER 36
|
||||
/**
|
||||
* The Vendor Specific Payload allows tronasport of
|
||||
* vebdor defined data.*/
|
||||
|
@ -38,12 +38,12 @@ struct cw_StrListElem capwap_strings_elem[] = {
|
||||
{CAPWAP_ELEM_LOCATION_DATA, "Location Data"},
|
||||
{CAPWAP_ELEM_MAXIMUM_MESSAGE_LENGTH, "Maximum Message Length"},
|
||||
{CAPWAP_ELEM_MTU_DISCOVERY_PADDING, "MTU Discovery Padding"},
|
||||
{CW_ELEM_RADIO_ADMINISTRATIVE_STATE, "Radio Administrative State"},
|
||||
{CAPWAP_ELEM_RADIO_ADMINISTRATIVE_STATE, "Radio Administrative State"},
|
||||
{CW_ELEM_RADIO_OPERATIONAL_STATE, "Radio Operational State"},
|
||||
{CAPWAP_ELEM_RESULT_CODE, "Result Code"},
|
||||
{CW_ELEM_RETURNED_MESSAGE_ELEMENT, "Returned Message Element"},
|
||||
{CAPWAP_ELEM_SESSION_ID, "Session ID"},
|
||||
{CW_ELEM_STATISTICS_TIMER, "Statistics Timer"},
|
||||
{CAPWAP_ELEM_STATISTICS_TIMER, "Statistics Timer"},
|
||||
{CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, "Vendor Specific Payload"},
|
||||
{CAPWAP_ELEM_WTP_BOARD_DATA, "WTP Board Data"},
|
||||
{CAPWAP_ELEM_WTP_DESCRIPTOR, "WTP Descriptor"},
|
||||
|
@ -428,53 +428,11 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
|
||||
cw_dbg_ktv_dump(conn->remote_cfg,DBG_CFG_DMP,
|
||||
" *** Remote CFG dump ***", "CFG:", " *** End of remote CFG dump");
|
||||
|
||||
/* {
|
||||
|
||||
{
|
||||
mlistelem_t *e;
|
||||
mlist_foreach(e,unrecognized){
|
||||
uint8_t * elem = *(uint8_t**)mlistelem_dataptr(e);
|
||||
int elem_len = cw_get_elem_len(elem);
|
||||
//int elem_data=cw_get_elem_data(elem);
|
||||
int elem_id = cw_get_elem_id(elem);
|
||||
printf("Unrecognized: %d %d\n",elem_id,elem_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (message->postprocess){
|
||||
message->postprocess(conn);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/** int rct = cw_in_check_generic(conn, afm, rawmsg, len, from); */
|
||||
|
||||
/* if (rct && conn->strict_capwap)
|
||||
{
|
||||
result_code = rct;
|
||||
}
|
||||
else {
|
||||
|
||||
if (afm->end) {
|
||||
result_code = afm->end(conn, afm, rawmsg, len, from);
|
||||
|
||||
}
|
||||
if (conn->msg_end){
|
||||
conn->msg_end(conn, afm, rawmsg, len, from);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/* if (unrecognized) {
|
||||
cw_dbg(DBG_RFC, "Message has %d unrecognized message elements.",
|
||||
unrecognized);
|
||||
// set only resultcode for request messages
|
||||
|
||||
if ( (!result_code) && ((afm->msg_id & 1))) {
|
||||
if (conn->strict_capwap) {
|
||||
result_code = CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/* if we've got a request message, we always have to send a response message */
|
||||
|
@ -397,6 +397,9 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
|
||||
int cw_in_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len);
|
||||
|
||||
int cw_in_generic_enum(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len);
|
||||
|
||||
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst);
|
||||
|
||||
@ -406,6 +409,9 @@ int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandler
|
||||
int cw_in_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len);
|
||||
|
||||
int cw_in_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len);
|
||||
|
||||
int cw_out_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst);
|
||||
|
||||
|
39
src/cw/cw_detect_nat.c
Normal file
39
src/cw/cw_detect_nat.c
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "dbg.h"
|
||||
#include "cw.h"
|
||||
|
||||
/**
|
||||
* @brief Detect NAT after a join/discovery request
|
||||
* @param conn Connection object
|
||||
* @retval 1 NAT detected
|
||||
* @retval 0 no NAT was detected
|
||||
*/
|
||||
int cw_detect_nat(struct conn *conn)
|
||||
{
|
||||
cw_KTV_t * result;
|
||||
|
||||
char local_str[128];
|
||||
char remote_str[128];
|
||||
|
||||
result = cw_ktv_get(conn->remote_cfg,"capwap-local-ip-address",CW_TYPE_IPADDRESS);
|
||||
if (result == NULL){
|
||||
cw_dbg(DBG_WARN,"Can't detect NAT. No local IP from peer received.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* convert remote connected and sent ip addresse to
|
||||
* strings */
|
||||
|
||||
sock_addrtostr((struct sockaddr*)&conn->addr,local_str,128,0);
|
||||
result->type->to_str(result,remote_str,128);
|
||||
|
||||
|
||||
/* if connected and sent address is the same, there is
|
||||
* no NAT */
|
||||
if (strcmp(remote_str,local_str)==0)
|
||||
return 0;
|
||||
/* otherwise ther must be something between AC and WTP */
|
||||
return 1;
|
||||
}
|
36
src/cw/cw_in_generic_enum.c
Normal file
36
src/cw/cw_in_generic_enum.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include "cw.h"
|
||||
|
||||
|
||||
static const cw_KTVEnum_t * get_enum(const cw_KTVEnum_t * e, int val){
|
||||
int i;
|
||||
for (i=0; e[i].type != NULL; i++ ){
|
||||
if (e[i].value==val){
|
||||
return &(e[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int cw_in_generic_enum(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len)
|
||||
{
|
||||
int val;
|
||||
const cw_KTVEnum_t * e;
|
||||
char key[CW_KTV_MAX_KEY_LEN];
|
||||
struct cw_ElemHandler thandler;
|
||||
|
||||
val = cw_get_byte(elem_data+1);
|
||||
e = get_enum(handler->type,val);
|
||||
if (e!=NULL){
|
||||
sprintf(key,"%s/%s",handler->key,e->name);
|
||||
}
|
||||
else{
|
||||
sprintf(key,"%s/%u",handler->key,val);
|
||||
}
|
||||
|
||||
thandler.type=e->type;
|
||||
thandler.key=key;
|
||||
return e->fun(&thandler,params,elem_data,elem_len-1);
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
|
||||
|
||||
#include "dbg.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "cw.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
int len, struct sockaddr *from)
|
||||
{
|
||||
// TODO XXXX
|
||||
// const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE);
|
||||
const cw_itemdef_t * idef = 0;
|
||||
|
||||
if (!idef){
|
||||
cw_log(LOG_ERR,"No definition found for %s",a->item_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int rid = cw_get_byte(data);
|
||||
mbag_t radio = mbag_i_get_mbag(conn->radios, rid, NULL);
|
||||
if (!radio) {
|
||||
if (a->vendor_id != 0
|
||||
|| ( (a->vendor_id == 0) && (a->msg_id != CAPWAP_MSG_DISCOVERY_REQUEST
|
||||
&& a->msg_id != CAPWAP_MSG_JOIN_REQUEST) )) {
|
||||
cw_dbg(DBG_ELEM_ERR, "Radio not found %d", rid);
|
||||
return 0;
|
||||
}
|
||||
mbag_i_set_mbag(conn->radios,rid,mbag_create());
|
||||
radio = mbag_i_get_mbag(conn->radios, rid, NULL);
|
||||
}
|
||||
|
||||
int rc = mbag_set_from_buf(radio,idef->type,a->item_id,data+1,len-1);
|
||||
if (!rc){
|
||||
cw_log(LOG_ERR,
|
||||
"Can't handle item type %s in definition for incomming msg %d (%s) - %d, cw_in_radio_generic.",
|
||||
idef->type->name, a->msg_id, cw_strmsg(a->msg_id), a->elem_id);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
27
src/cw/cw_in_radio_generic_struct.c
Normal file
27
src/cw/cw_in_radio_generic_struct.c
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "capwap.h"
|
||||
#include "msgset.h"
|
||||
#include "ktv.h"
|
||||
#include "log.h"
|
||||
#include "cw.h"
|
||||
|
||||
int cw_in_radio_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len)
|
||||
{
|
||||
char key[CW_KTV_MAX_KEY_LEN];
|
||||
int radio;
|
||||
|
||||
if (!handler->type){
|
||||
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
||||
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
|
||||
radio = cw_get_byte(elem_data);
|
||||
sprintf(key,"radio/%d/%s",radio,handler->key);
|
||||
|
||||
cw_ktv_read_struct(params->conn->remote_cfg,handler->type,key,elem_data+1,elem_len-1);
|
||||
|
||||
/*params->elem=result;*/
|
||||
|
||||
return CAPWAP_RESULT_SUCCESS;
|
||||
}
|
@ -196,7 +196,7 @@ int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int state, int c
|
||||
int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state) {
|
||||
cw_set_byte(dst+4,rid);
|
||||
cw_set_byte(dst+5,state);
|
||||
return 2+cw_put_elem_hdr(dst,CW_ELEM_RADIO_ADMINISTRATIVE_STATE,2);
|
||||
return 2+cw_put_elem_hdr(dst,CAPWAP_ELEM_RADIO_ADMINISTRATIVE_STATE,2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,6 +12,8 @@ int cw_ktv_read_struct(mavl_t ktv,const cw_KTVStruct_t * stru, const char *pkey,
|
||||
pos=0; i=0;
|
||||
while (stru[i].type != NULL){
|
||||
char dbstr[100];
|
||||
if(stru[i].position!=-1)
|
||||
pos=stru[i].position;
|
||||
|
||||
sprintf(key,"%s/%s",pkey,stru[i].key);
|
||||
result = cw_ktv_add(ktv,key,stru[i].type,data+pos,stru[i].len);
|
||||
@ -21,8 +23,7 @@ int cw_ktv_read_struct(mavl_t ktv,const cw_KTVStruct_t * stru, const char *pkey,
|
||||
|
||||
if(stru[i].position == -1)
|
||||
pos+=stru[i].len;
|
||||
else
|
||||
pos=stru[i].position;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
int cw_readelem_statistics_timer(uint16_t *timer, int type, uint8_t * msgelem, int len)
|
||||
{
|
||||
if (type != CW_ELEM_STATISTICS_TIMER)
|
||||
if (type != CAPWAP_ELEM_STATISTICS_TIMER)
|
||||
return 0;
|
||||
|
||||
if (len!=2){
|
||||
|
11
src/cw/ktv.h
11
src/cw/ktv.h
@ -7,6 +7,7 @@
|
||||
#include "mavl.h"
|
||||
#include "bstr.h"
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup ALGOS
|
||||
* @{
|
||||
@ -90,7 +91,17 @@ struct cw_KTVStruct {
|
||||
int len;
|
||||
int position;
|
||||
};
|
||||
|
||||
typedef struct cw_KTVStruct cw_KTVStruct_t;
|
||||
|
||||
struct cw_KTVEnum{
|
||||
int value;
|
||||
const char * name;
|
||||
const struct cw_Type * type;
|
||||
int (*fun)();
|
||||
};
|
||||
typedef struct cw_KTVEnum cw_KTVEnum_t;
|
||||
|
||||
int cw_ktv_read_struct(mavl_t ktv,const cw_KTVStruct_t * stru, const char *pkey,
|
||||
uint8_t * data, int len);
|
||||
int cw_ktv_write_struct(mavl_t ktv, const cw_KTVStruct_t * stru, const char *pkey,
|
||||
|
@ -264,21 +264,22 @@ int cw_msgset_add(struct cw_MsgSet *set,
|
||||
struct cw_MsgData *msg;
|
||||
int exists;
|
||||
|
||||
/* Look if message already exists */
|
||||
/* add the message */
|
||||
search.type = msgdef->type;
|
||||
msg = mavl_add(set->msgdata, &search, &exists);
|
||||
|
||||
if (msg == NULL) {
|
||||
cw_log(LOG_ERR, "Can't create messae");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Look if message already exists */
|
||||
if (!exists) {
|
||||
/* message is fresh createt, initialize data */
|
||||
msg->elements_tree = mavl_create(cmp_elemdata, NULL,
|
||||
sizeof(struct cw_ElemData));
|
||||
msg->mand_keys=NULL;
|
||||
|
||||
msg->elements_list = mlist_create(cmp_elemdata,NULL,sizeof(struct cw_ElemData));
|
||||
msg->postprocess=NULL;
|
||||
}
|
||||
|
||||
/* Overwrite the found message */
|
||||
@ -286,6 +287,9 @@ int cw_msgset_add(struct cw_MsgSet *set,
|
||||
msg->name = msgdef->name;
|
||||
if (msgdef->states)
|
||||
msg->states = msgdef->states;
|
||||
if (msgdef->postprocess != NULL)
|
||||
msg->postprocess = msgdef->postprocess;
|
||||
|
||||
msg->receiver = msgdef->receiver;
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ struct cw_MsgDef{
|
||||
|
||||
|
||||
struct cw_ElemDef * elements;
|
||||
|
||||
int (*postprocess)(struct conn * conn);
|
||||
};
|
||||
|
||||
|
||||
@ -82,6 +82,8 @@ struct cw_MsgData{
|
||||
mavl_t elements_tree;
|
||||
mlist_t elements_list;
|
||||
mlist_t mand_keys; /**< Keys of mandatory elements */
|
||||
|
||||
int (*postprocess)(struct conn * conn);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user