Work on msgset

FossilOrigin-Name: 47f9ccd5e442443a9023a8d408ef2ebe2d073c947767058ba631d8b1a94063b2
This commit is contained in:
7u83@mail.ru 2018-03-03 07:15:19 +00:00
parent b1e98fdd4a
commit ca22c44590
31 changed files with 669 additions and 1071 deletions

View File

@ -307,6 +307,13 @@
<File Name="src/cw/message_set.h"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
<File Name="src/cw/cw_filename.c"/>
<File Name="src/cw/mdata.h"/>
<File Name="src/cw/mdata.c"/>
<File Name="src/cw/mdata_elem_new.c"/>
<File Name="src/cw/cw_type_byte.c"/>
<File Name="src/cw/cw_type_word.c"/>
<File Name="src/cw/cw_types.h"/>
<File Name="src/cw/cw_type_dword.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

View File

@ -118,7 +118,7 @@ int ac_global_init()
ac_status.max_wtps = 200;
ac_status.security = CW_FLAG_AC_SECURITY_X | CW_FLAG_AC_SECURITY_S;
ac_status.rmac_field = CW_FLAG_RMAC_SUPPORTED;
ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C; // | CW_FLAG_DTLS_POLICY_D;
ac_status.dtls_policy = CAPWAP_FLAG_DTLS_POLICY_C; // | CW_FLAG_DTLS_POLICY_D;
mbag_set_bstrv(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0,

View File

@ -95,6 +95,7 @@ extern struct cw_Mod * cw_get_mod_ac(const char *name);
extern void test_sets();
#include "cw/file.h"
int main(int argc, char *argv[])
{
@ -121,13 +122,11 @@ int main(int argc, char *argv[])
DBGX("Attention! %s", "DBG X is ON!");
// cw_mod_set_mod_path("../../lib/actube");
// cw_mod_load("capwap");
//cw_mod_load("capwap");
//test_sets();
//exit(0);
/* Initialize the database */
if (!db_init())

View File

@ -87,7 +87,10 @@ typedef mavl_t 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);
@ -118,7 +121,9 @@ extern cw_actionlist_out_t cw_actionlist_out_create();
extern int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions);
mlist_t * cw_actionlist_out_get(cw_actionlist_out_t,int msg_id);
/*
//extern cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a);
*/
/**
* @}

View File

@ -26,7 +26,7 @@
#define __CAPWAP_H
#include <stdint.h>
//#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
@ -181,7 +181,7 @@
* @defgroup CAPWAPMsgElems CAPWAP Message Elements
* @brief CAPWAP message elements as defined in RFC 5415
* @{
*/ //namin
*/
#define CAPWAP_ELEM_AC_DESCRIPTOR 1 /**< AC Descriptor */
@ -332,10 +332,10 @@
#define CW_WTP_MAC_TYPE_BOTH 2
/*
//#define CWMSG_MAX_SIZE 65536
//#define CWMSG_MAX_SIZE 2048
*/
#define CW_SESSION_ID_LEN 16
@ -359,9 +359,10 @@
#define CW_TIMERS ((CW_DISCOVERY_INTERVAL << 8) | CAPWAP_ECHO_INTERVAL)
//#define CAPWAP_CIPHER "PSK-AES128-CBC-SHA:"
/*
//#define CAPWAP_CIPHER "PSK-AES128-CBC-SHA:"
//#define CAPWAP_CIPHER "AES128-SHA"
*/
#ifdef WITH_GNUTLS
#define CAPWAP_CIPHER "NORMAL"
@ -385,15 +386,24 @@
/**
* @defgroup ACDTLSPOLICY AC DTLS Policy Flags
* @defgroup ACDTLSPOLICY CAPWAP DTLS Policy Flags
* The DTLS policy flags are describing the data transfer
* policy by AC.
* @{
*/
/** Reserved */
#define CW_FLAG_DTLS_POLICY_R 1
/** Clear Text Data Channel Support */
#define CW_FLAG_DTLS_POLICY_C 2
/** DTLS Data Channel Support */
#define CW_FLAG_DTLS_POLICY_D 4
#define CAPWAP_FLAG_DTLS_POLICY_R 1
/**
* Clear Text Data Channel Support.
* Means unencrypted data is supprted.*/
#define CAPWAP_FLAG_DTLS_POLICY_C 2
/**
* DTLS Data Channel Support.
* Encrypted data is supported. */
#define CAPWAP_FLAG_DTLS_POLICY_D 4
/**
* @}
*/
@ -416,12 +426,15 @@ struct cwimage_identifier{
*/
/*
//extern void cwmsg_addelem_wtp_radio_infos(struct cwmsg * cwmsg,struct wtpinfo * wtpinfo);
*/
extern void cwmsg_addelem_wtp_radio_infos(struct cwmsg *msg,
struct radioinfo *radioinfos);
/*
//extern void cwmsg_addelem_result_code(struct cwmsg *msg, int rc);
*/
extern void cwmsg_addelem_vendor_specific_payload(struct cwmsg *msg, int vendor_id,
int type, uint8_t * payload, int len);
@ -431,6 +444,7 @@ extern int hdr_print(char *str, uint8_t * packet, int len);
extern int cw_readelem_ecn_support(uint8_t * ecn_support, int type, uint8_t * msgelem,
int len);
/*
//extern int cw_readelem_maximum_message_length(uint16_t * dst, int type, uint8_t * msgelem,
// int len);
//extern int cw_readelem_ac_name(uint8_t ** dst, int type, uint8_t * msgelem, int len);
@ -442,6 +456,8 @@ extern int cw_readelem_ecn_support(uint8_t * ecn_support, int type, uint8_t * ms
// uint8_t * msgelem, int len);
//extern int cw_readelem_radio_operational_state(struct radioinfo *radioinfo, int type,
// uint8_t * msgelem, int len);
*/
extern int cw_readelem_statistics_timer(uint16_t * timer, int type, uint8_t * msgelem,
int len);
@ -467,7 +483,7 @@ enum cw_reboot_failure_types {
};
#define CW_RESULT_SUCCESS 0
#define CAPWAP_RESULT_SUCCESS 0
#define CW_RESULT_MISSING_AC_LIST 1
#define CW_RESULT_SUCCESS_NAT 2
#define CW_RESULT_JOIN_FAILURE 3
@ -481,20 +497,35 @@ enum cw_reboot_failure_types {
#define CW_RESULT_RESET_FAILURE_FIRMWARE_WRITE_ERROR 11
#define CW_RESULT_CONFIGURATION_FAILURE 12 //Configuration Failure (Unable to Apply Requested Configuration
/**
* Configuration Failure (Unable to Apply Requested Configuration
* - Service Provided Anyhow)
*/
#define CW_RESULT_CONFIGURATION_FAILURE 12
// - Service Provided Anyhow)
/*
/**
13 Configuration Failure (Unable to Apply Requested Configuration
- Service Not Provided)
*/
#define CW_RESULT_IMAGE_DATA_INVALID_CHECKSUM 14 //Image Data Error (Invalid Checksum)
/**
* Image Data Error (Invalid Checksum)
*/
#define CW_RESULT_IMAGE_DATA_INVALID_CHECKSUM 14
#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length)
/**
* Image Data Error (Invalid Data Length)
*/
#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15
/**
* Image Data Error (Other Error)
*/
#define CAPWAP_RESULT_IMAGE_DATA_ERROR 16
#define CW_RESULT_IMAGE_DATA_ERROR 16 //Image Data Error (Other Error)
/*
17 Image Data Error (Image Already Present)
*/
@ -533,11 +564,12 @@ enum cw_reboot_failure_types {
extern void cw_read_image_data_request(struct cwimage_data *, uint8_t * msg, int len);
/*
//extern int cw_readelem_ac_descriptor(struct ac_info *acinfo, int type, uint8_t * msgelem,
// int len);
//extern int cw_readelem_capwap_local_ip_addr(struct sockaddr *local_ip, int type,
// uint8_t * msgelem, int len);
*/
extern int cw_send_echo_response(struct conn *conn, int seqnum,
@ -570,7 +602,9 @@ extern struct cw_strlist_elem mbag_item_strings[];
#define cw_strelem(id) cw_strlist_get_str(capwap_strings_elem,id)
#define cw_strstate(id) cw_strlist_get_str(capwap_strings_state,id)
#define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id)
#define cw_strresult(id) cw_strlist_get_str(capwap_strings_result,id)
#define cw_strboardelem(id) cw_strlist_get_str(capwap_strings_board,id)
#define cw_stritem(id) cw_strlist_get_str(mbag_item_strings,(id))
@ -595,9 +629,9 @@ const char *cw_strelemp_(cw_strheap_t h, int msg_id);
/*
//int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len);
*/
extern int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from);
@ -607,24 +641,31 @@ extern int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8
int len,struct sockaddr *from);
extern int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
//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, struct cw_action_out *a, uint8_t * dst); //, struct mbag_item *item);
/*
//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, struct cw_action_out *a, uint8_t * dst);
/*
//extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
//struct mbag_item *item);
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //,struct mbag_item * item)
*/
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
extern int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
/*
//extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id,
// uint8_t * dst, struct mbag_item *item);
*/
extern int cw_out_capwap_control_ip_addr_list(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
extern int cw_put_msg(struct conn *conn, uint8_t * rawout);
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); // ,struct mbag_item * item)
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
struct cw_ac_status {
@ -706,7 +747,9 @@ extern int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_
int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
int cw_send_request(struct conn *conn, int msg_id);
/*
//int cw_is_utf8(unsigned char *str, size_t len);
*/
int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
@ -720,14 +763,16 @@ int cw_in_ac_descriptor(struct conn *conn,struct cw_action_in * a,uint8_t *data,
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
/*
//int cw_out_capwap_local_ip_address(struct conn *conn, struct cw_action_out *action, uint8_t * dst);
*/
int cw_in_check_chng_state_evnt_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
/*
//int cw_out_radio_operational_states(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
*/
int cw_in_check_cfg_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);

View File

@ -3,12 +3,12 @@
struct cw_strlist_elem capwap_strings_result[] = {
{CW_RESULT_SUCCESS,"Success"}, /* 0 */
{CAPWAP_RESULT_SUCCESS,"Success"}, /* 0 */
{CW_RESULT_MISSING_AC_LIST,"AC List Message Element MUST be Present"}, /* 1 */
{CW_RESULT_SUCCESS_NAT,"Success - NAT Detected"}, /* 2 */
{CW_RESULT_RESET_UNABLE_TO_RESET,"Reset Failure - Unable to Reset"}, /* 10 */
{CW_RESULT_IMAGE_DATA_INVALID_CHECKSUM,"Image Data Error (Invalid Checksum)"}, /* 14 */
{CW_RESULT_IMAGE_DATA_ERROR,"Image Data Error (Unspecified)"}, /* 16 */
{CAPWAP_RESULT_IMAGE_DATA_ERROR,"Image Data Error (Unspecified)"}, /* 16 */
{CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE,"Message unexpected (Invalid in current state)"}, /* 18 */
{CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"}, /* 20 */
{CW_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT,"Unrecognized Message Element"}, /* 21 */

View File

@ -98,7 +98,7 @@ struct conn {
/** Actionsdefs - this defines the possible actions for
this conn object, so in the end this is the specification
of the protocoll */
// struct cw_actiondef *actions;
struct cw_MsgSet * msgset;
@ -140,17 +140,17 @@ struct conn {
int (*recv_packet) (struct conn *, uint8_t *, int);
int (*recv_packet_peek) (struct conn *, uint8_t *, int);
int (*send_packet) (struct conn *, const uint8_t *, int);
/*
// int (*recv_data_packet) (struct conn *, uint8_t *,int);
// int (*send_data_packet) (struct conn *, const uint8_t *, int);
*/
int (*readfrom) (struct conn *, uint8_t *, int, struct sockaddr_storage *);
int (*read) (struct conn *, uint8_t *, int);
int (*write) (struct conn *, const uint8_t *, int);
/*
// int (*write_data) (struct conn *, const uint8_t *, int);
*/
/* optional packet queue */
uint8_t **q;
int qsize;
@ -222,7 +222,9 @@ struct conn {
int (*elem_end)(struct conn *conn,struct cw_action_in *a,int afrc,uint8_t*elem,int len,struct sockaddr *from);
/*
// void (*actions_registered)(struct conn *conn);
*/
};
@ -237,8 +239,11 @@ struct conn *conn_create_noq(int sock, struct sockaddr *addr);
extern int conn_send_cwmsg(struct conn *conn, struct cwmsg *cwmsg);
/*
//extern int conn_process_packet(struct conn *conn, uint8_t * packet, int len,
// int (*cb) (void *, uint8_t *,int len), void *cbarg);
*/
extern int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from);
extern int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
@ -274,7 +279,10 @@ struct cwimage_data;
extern void conn_prepare_request(struct conn *conn, int type);
extern int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *,
struct image_identifier *id);
/*
//extern void conn_detect_capwap(struct conn *conn, struct wtpinfo *wtpinfo);
*/
struct cwrmsg *conn_send_request(struct conn *conn);
struct cwrmsg *conn_wait_for_message(struct conn *conn, time_t timer);

View File

@ -346,23 +346,23 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
as.elem_id = cw_get_elem_id(elem);
int elem_len = cw_get_elem_len(elem);
cw_elem_handler_t search_eh;
memset(&search_eh,0,sizeof(search_eh));
struct cw_ElemDef search_elem;
search_elem.handler=&search_eh;
//cw_elem_handler_t search_eh;
//memset(&search_eh,0,sizeof(search_eh));
// struct cw_ElemDef search_elem;
// search_elem.handler=&search_eh;
search_eh.id = cw_get_elem_id(elem);
// search_eh.id = cw_get_elem_id(elem);
struct cw_ElemDef * elem;
elem = mavl_find(message->elements_tree,&search_elem);
// elem = mavl_find(message->elements_tree,&search_elem);
printf("ElemCHeck %d\n",search_eh.id);
if (elem){
printf("Elem %d found! %s\n", elem->handler->id , elem->handler->name);
}
//printf("ElemCHeck %d\n",search_eh.id);
//if (elem){
//printf("Elem %d found! %s\n", elem->handler->id , elem->handler->name);
//}
// TODO XXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;

View File

@ -107,45 +107,12 @@
typedef struct {
const char * name;
int proto;
int vendor;
int id;
int min_len;
int max_len;
int (*start_in)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);
int (*end_in)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from);
}cw_elem_handler_t;
struct cw_MsgSet {
mavl_t messages;
mavl_t all_elems;
};
typedef struct cw_MsgSet cw_MsgSet_t;
typedef struct cw_ElemDef{
cw_elem_handler_t * handler;
int mand;
int op;
};
typedef struct cw_ElemDef cw_ElemDef_t;
#define CW_RECEIVER_AC 1
#define CW_RECEIVER_WTP 1
struct cw_MsgDef{
int type; /**< Message type */
int * states; /**< states in wich the message is allowed */
int receiver; /**< Who can receive this message */
cw_ElemDef_t * elements;
const char * name;
};
typedef struct cw_MsgDef cw_msgdef_t;
@ -455,9 +422,10 @@ extern int cw_put_radio_operational_states(mbag_t radios, uint8_t * dst, int *ne
* @{
*/
extern int cw_radio_set_admin_state(mbag_t radios,int rid, int state, int cause);
/*
//extern int cw_put_elem_radio_administrative_state(uint8_t *dst,int radio_id,mbag_t radio);
//extern int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int os, int d7mode);
*/
int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int state, int cause);
int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state);

View File

@ -29,7 +29,7 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
char * image_filename = malloc(6+bstrv_len(i->data)+1+strlen(image_dir));
if (!image_filename)
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
sprintf(image_filename,"%s%04X/%s",image_dir,vendor_id,bstrv_data(i->data));
@ -39,7 +39,7 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
cw_log(LOG_WARNING,"Can't open image file: %s - %s - requestet by WTP",
image_filename,strerror(errno));
free(image_filename);
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
}
mbag_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
@ -50,6 +50,6 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
}

View File

@ -17,7 +17,7 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
//usleep(100000);
return 0;
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
return 0;
@ -40,7 +40,7 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
char * image_filename = malloc(6+bstrv_len(i->data)+1+strlen(image_dir));
if (!image_filename)
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
sprintf(image_filename,"%s%04X/%s",image_dir,vendor_id,bstrv_data(i->data));
@ -50,7 +50,7 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
cw_log(LOG_WARNING,"Can't open image file: %s - %s - requestet by WTP",
image_filename,strerror(errno));
free(image_filename);
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
}
mbag_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
@ -61,6 +61,6 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint
return CW_RESULT_IMAGE_DATA_ERROR;
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
}

62
src/cw/cw_type_byte.c Normal file
View File

@ -0,0 +1,62 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "cw.h"
#include "cw_types.h"
static struct mdata_Elem *from_str(const char *src)
{
struct mdata_Elem *i = mdata_elem_new(&cw_type_byte);
if (!i)
return NULL;
i->data.byte = atoi(src);
return i;
}
static int to_str(const struct mdata_Elem *e, char *dst)
{
return sprintf(dst, "%d", e->data.byte);
}
static struct mdata_Elem *get(const uint8_t * src, int len)
{
struct mdata_Elem *e = mdata_elem_new(&cw_type_byte);
if (!e)
return NULL;
e->data.byte = cw_get_byte(src);
return e;
}
static int put(struct mdata_Elem *e, uint8_t * dst)
{
return cw_put_byte(dst, e->data.byte);
}
#define _I_NAME "Byte"
#define _I_PUT put
#define _I_GET get
#define _I_DEL NULL
#define _I_TO_STR to_str
#define _I_FROM_STR from_str
const struct mdata_Type cw_type_byte = MDATA_TYPE_INIT();

61
src/cw/cw_type_dword.c Normal file
View File

@ -0,0 +1,61 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "cw_types.h"
#include "cw.h"
static struct mdata_Elem * from_str(const char *src)
{
struct mdata_Elem * e = mdata_elem_new(&cw_type_dword);
if (!e)
return NULL;
e->data.word=atoi(src);
return e;
}
static int to_str(const struct mdata_Elem *e, char *dst)
{
return sprintf(dst, "%d", e->data.word);
}
static struct mdata_Elem * get(const uint8_t *src,int len)
{
struct mdata_Elem * e = mdata_elem_new(&cw_type_dword);
if (!e)
return NULL;
e->data.word=cw_get_dword(src);
return e;
}
static int put(struct mdata_Elem * e, uint8_t *dst)
{
return cw_put_dword(dst,e->data.word);
}
#define _I_NAME "Dword"
#define _I_PUT put
#define _I_GET get
#define _I_DEL NULL
#define _I_TO_STR to_str
#define _I_FROM_STR from_str
const struct mdata_Type cw_type_dword = MDATA_TYPE_INIT();

61
src/cw/cw_type_word.c Normal file
View File

@ -0,0 +1,61 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "cw_types.h"
#include "cw.h"
static struct mdata_Elem * from_str(const char *src)
{
struct mdata_Elem * e = mdata_elem_new(&cw_type_word);
if (!e)
return NULL;
e->data.word=atoi(src);
return e;
}
static int to_str(const struct mdata_Elem *e, char *dst)
{
return sprintf(dst, "%d", e->data.word);
}
static struct mdata_Elem * get(const uint8_t *src,int len)
{
struct mdata_Elem * e = mdata_elem_new(&cw_type_word);
if (!e)
return NULL;
e->data.word=cw_get_word(src);
return e;
}
static int put(struct mdata_Elem * e, uint8_t *dst)
{
return cw_put_word(dst,e->data.word);
}
#define _I_NAME "Word"
#define _I_PUT put
#define _I_GET get
#define _I_DEL NULL
#define _I_TO_STR to_str
#define _I_FROM_STR from_str
const struct mdata_Type cw_type_word = MDATA_TYPE_INIT();

12
src/cw/cw_types.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __CW_TYPES_H
#define __CW_TYPES_H
#include "mdata.h"
extern const struct mdata_Type cw_type_byte;
#define CW_TYPE_BYTE (&cw_type_byte)
extern const struct mdata_Type cw_type_word;
extern const struct mdata_Type cw_type_dword;
#endif

View File

@ -4,8 +4,6 @@
#include <stdint.h>
#include "radioinfo.h"
//#include "acinfo.h"
//#include "wtpinfo.h"
struct cwmsg{
uint8_t * buffer;

View File

@ -48,7 +48,10 @@
struct frag {
/*
// uint8_t buffer[FRAG_MAXSIZE];
*/
uint8_t * buffer;
int fragid;
int bytesreceived;
@ -57,18 +60,21 @@ struct frag {
uint8_t * header;
};
typedef struct frag frag_t; //FRAGMAN;
typedef struct frag frag_t; /*FRAGMAN;*/
/*
//extern struct frag * fragman_add(struct frag * frags[], uint8_t *packet, int len); // struct cw_transport_header * th)
//extern uint8_t * fragman_add(struct frag * frags, uint8_t *packet, int len); // struct cw_transport_header * th)
*/
extern uint8_t * fragman_add( frag_t * frags, uint8_t *packet, int hlen, int payloadlen );
extern frag_t * fragman_create();
extern void fragman_destroy(frag_t * frags);
/*
//extern frag_init(struct frag ** frag[]);
*/
extern void fragman_free(frag_t * frags,struct frag * f);

View File

@ -56,5 +56,5 @@ extern const cw_itemdef_t * cw_itemdef_get(cw_itemdefheap_t t, const char *id,
struct cw_itemdef *cw_item_get_by_name(const char *name, struct cw_itemdef *table);
typedef const char *cw_item_id_t;
//
#endif

View File

@ -46,13 +46,13 @@
/*
//extern void cw_log_dbg_(int type, const char *file, int line, const char *fromat, ...);
//extern void cw_log_dbg_dmp_(int type, const char *file, int line, const uint8_t * data,
//int len, const char *format, ...);
*/
#ifdef WITH_CW_LOG
@ -61,6 +61,7 @@
#define cw_log(...)
#endif
/*
//#ifdef WITH_CW_LOG_DEBUG
@ -83,6 +84,8 @@
//#define cw_dbg_missing_mand_elems(conn, msgtyoe, mand)
//#endif
*/
extern void (*cw_log_cb) (int level, const char *fromat, ...);
extern void (*cw_log_vcb) (int level, const char *fromat, va_list args);
@ -99,11 +102,13 @@ void cw_log_file(int level,const char *format, ...);
void cw_log_colored(int level, const char *format, ...);
/*
//extern void (*cw_log_debug_cb) (int type, const char *format, ...);
//extern void (*cw_log_debug_cbs[]) (const char *fromat, ...);
*/
extern int cw_log_debug_dump_(int level, const uint8_t * data, int len,
const char *format, ...);

View File

@ -53,6 +53,8 @@
* @}
*/
/**
* Defines the structure of an AVL Node.
*/
@ -115,7 +117,7 @@ int mavl_foreach_from_lr(struct mavl *t, struct mavlnode *n, void *data,
* @}
*/
//extern void mavl_foreach(struct mavl *t, int (*callback)(void *,void*),void *cbpriv,int dir);
void *mavl_replace_data(struct mavl *t, void *data, int len);
@ -128,7 +130,7 @@ void mavl_destroy(struct mavl *t);
#define mavl_find(t,d) mavl_get(t,d)
#define mavl_insert(t,d) mavl_add(t,d)
//#define mavl_walk(t,dir) mavl_foreach(t,dir)
#define mavl_foreach_asc(t,cb,priv) mavl_foreach_lr((t)->root,cb,priv)
#define mavl_foreach_desc(t,cb,priv) mavl_foreach_rl((t)->root,cb,priv)
@ -170,7 +172,7 @@ extern void * mavliter_seek(mavliter_t *i,void *d);
* \code
mavl_t datatree = mavl_create();
// fill up datatree with some values
// fill up datatree with some values
MAVLITER_DEFINE (i,datatree);
mavliter_foreach(&i) {
@ -178,7 +180,7 @@ extern void * mavliter_seek(mavliter_t *i,void *d);
void * value = mavliter_get(&i);
}
* \endcode
\endcode
*/
#define MAVLITER_DEFINE(i,t)\
mavliter_t i; mavliter_init(&i,t)

View File

@ -49,6 +49,7 @@ static struct mbag_item * get(const uint8_t *src, int len)
}
const struct mbag_typedef mbag_type_bstr16 = {
.name = "Bstr16",
.del = free,

8
src/cw/mdata.c Normal file
View File

@ -0,0 +1,8 @@
#include "mavl.h"
#include "mdata.h"
mdata_create(){
return 0;
}

68
src/cw/mdata.h Normal file
View File

@ -0,0 +1,68 @@
#ifndef __MDATA_H
#define __MDATA_H
#include <stdint.h>
union mdata_ElemData {
void *raw;
uint8_t byte;
uint16_t word;
uint32_t dword;
uint64_t qword;
};
struct mdata_Elem{
const char * key;
const struct mdata_Type * type;
union mdata_ElemData data;
};
struct mdata_Type{
/** A human readable name for this type */
const char *name;
/** A pointer to a function to delete elements of this type */
void (*del)(void*);
/** A method to put this object to a buffer */
int (*put)(struct mdata_Elem *i,uint8_t*dst);
/** The get emthod */
struct mdata_Elem * (*get)(const uint8_t*src, int len);
/** A pointer to a function to convert elements of this type to a string.
This function is mainly used to store elements to an SQL database
or to json strings */
int (*to_str)(const struct mdata_Elem * e,char *dst);
/** Cereate an item of this type from a string, which was previously
created by the #del function. */
struct mdata_Elem * (*from_str)(const char *src);
/*
int (*def)(void *, void *);
*/
};
#define MDATA_TYPE_INIT()\
{\
_I_NAME,\
_I_DEL,\
_I_PUT,\
_I_GET,\
_I_TO_STR,\
_I_FROM_STR \
}
struct mdata_Elem *mdata_elem_new( const struct mdata_Type * type );
#endif /* __MDATA_H */

15
src/cw/mdata_elem_new.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdlib.h>
#include "mdata.h"
struct mdata_Elem *mdata_elem_new( const struct mdata_Type * type )
{
struct mdata_Elem *i= malloc(sizeof(struct mdata_Elem));
if (!i)
return NULL;
i->type = type;
return i;
}

View File

@ -2,22 +2,13 @@
#include "cw.h"
#include "mavl.h"
#include "cw/dbg.h"
#include "cw/log.h"
#include "message_set.h"
/*
typedef struct {
int type;
const char * name;
int * states;
mavl_t elements_tree;
mlist_t elements_list;
}message2_t;
*/
static int cmp_cw_msgelemprops(const void *elem1, const void *elem2){
cw_elem_handler_t * e1 = ((cw_ElemDef_t*)elem1)->handler;
cw_elem_handler_t * e2 = ((cw_ElemDef_t*)elem2)->handler;
static int cmp_cw_elemhandler_by_id(const void *elem1, const void *elem2){
struct cw_ElemHandler * e1 = ((struct cw_ElemHandler*)elem1);
struct cw_ElemHandler * e2 = ((struct cw_ElemHandler*)elem2);
int r;
r = e1->id - e2->id;
if (r!=0)
@ -31,129 +22,153 @@ static int cmp_cw_msgelemprops(const void *elem1, const void *elem2){
return 0;
}
static int cmp_cw_elemhandler_by_key(const void *elem1, const void *elem2){
struct cw_ElemHandler * e1 = ((struct cw_ElemHandler*)elem1);
struct cw_ElemHandler * e2 = ((struct cw_ElemHandler*)elem2);
return strcmp(e1->key,e2->key);
}
int msg_cmp(const void *elem1, const void *elem2)
static int cmp_msgdata(const void *elem1, const void *elem2)
{
message2_t * e1 = (message2_t*)elem1;
message2_t * e2 = (message2_t*)elem2;
struct cw_MsgData * e1 = (struct cw_MsgData*)elem1;
struct cw_MsgData * e2 = (struct cw_MsgData*)elem2;
return e1->type - e2->type;
}
static void msgdata_destroy(struct cw_MsgData *data){
if (!data)
return;
if (data->elements_list)
mlist_destroy(data->elements_list);
if (data->elements_tree)
mavl_destroy( data->elements_tree );
free(data);
}
void cw_message_set_destroy(cw_MsgSet_t * set){
if (set->messages){
static struct cw_MsgData * msgdata_create(){
struct cw_MsgData * msg;
msg = malloc( sizeof(struct cw_MsgData));
if (!msg)
return NULL;
/* msg->elements_tree = mavl_create();
if (!msg->elements_tree){
msgdata_destroy(msg);
return NULL;
}
*/
}
/**
* @brief Destroy a message set
* @param set Message set to destroy
*/
void cw_msgset_destroy(struct cw_MsgSet * set){
if (set->messages)
mavl_destroy(set->messages);
}
if (set->all_elems){
mavl_destroy(set->all_elems);
}
if (set->all_elems_by_id)
mavl_destroy(set->all_elems_by_id);
if (set->all_elems_by_key)
mavl_destroy(set->all_elems_by_key);
free(set);
}
cw_MsgSet_t * cw_message_set_create(){
/**
* @brief Create a message set
* @return Message set create, NULL if an error has occured
*/
struct cw_MsgSet * cw_msgset_create(){
/* allocate memory for a message_set */
cw_MsgSet_t * set = malloc(sizeof(cw_MsgSet_t));
struct cw_MsgSet * set = malloc(sizeof(struct cw_MsgSet ));
if (set==NULL)
return NULL;
memset(set,0,sizeof(cw_MsgSet_t));
memset(set,0,sizeof(struct cw_MsgSet));
/* create mavl for all_elems */
set->all_elems = mavl_create(cmp_cw_msgelemprops,NULL);
if (set->all_elems==NULL){
cw_message_set_destroy(set);
/* create mavl for all_elems by id */
set->all_elems_by_id = mavl_create(cmp_cw_elemhandler_by_id,free);
if (set->all_elems_by_id==NULL){
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for all_elems by id */
set->all_elems_by_key = mavl_create(cmp_cw_elemhandler_by_key,NULL);
if (set->all_elems_by_key==NULL){
cw_msgset_destroy(set);
return NULL;
}
/* create mavl for messages */
set->messages = mavl_create(msg_cmp,NULL);
set->messages = mavl_create(cmp_msgdata,msgdata_destroy);
if (set->messages==NULL){
cw_message_set_destroy(set);
cw_msgset_destroy(set);
return NULL;
}
return set;
}
static void update_message(message2_t * msg, cw_msgdef_t * src, cw_MsgSet_t * set){
cw_ElemDef_t *md;
for (md = src->elements; md->handler!=0; md++){
cw_dbg(DBG_INFO," add element %d - %s, %d",md->handler->id, md->handler->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);
}
}
void cw_msgset_add(cw_MsgSet_t * set,
cw_msgdef_t messages[]){
cw_msgdef_t * message;
for (message=messages; message->type !=0; message++){
message2_t search, *next;
int cw_msgset_add(struct cw_MsgSet * set,
struct cw_MsgDef messages[],
struct cw_ElemHandler elements[]
){
struct cw_ElemHandler * handler;
struct cw_MsgDef * message;
/* Create mavl for all handlers */
for(handler = elements; handler->id; handler++){
struct cw_ElemHandler * copy;
copy = malloc(sizeof(struct cw_ElemHandler));
if (!copy){
cw_log(LOG_ERR,"Can't alloc mem:", strerror(errno));
continue;
}
search.type = message->type;
memcpy(copy,handler,sizeof(struct cw_ElemHandler));
mavl_replace(set->all_elems_by_id,copy);
mavl_replace(set->all_elems_by_key,copy);
}
for (message=messages; message->type !=0; message++){
struct cw_MsgData * msg;
cw_dbg(DBG_INFO,"Add message: Type:%d - %s",message->type,message->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=message->type;
mavl_add(set->messages,next);
msg = malloc( sizeof(struct cw_MsgData));
if (!msg) {
cw_log(LOG_ERROR,"Can't alloc cw_MsgData: %s",strerror(errno));
continue;
}
/* massage is alreaddy in there */
if (message->name)
next->name=message->name;
if (message->states)
next->states=message->states;
if (message->receiver)
next->receiver=message->receiver;
update_message(next,message, set);
}
}
cw_elem_handler_t * cw_message_set_find_element(
cw_MsgSet_t * set,
cw_elem_handler_t * element){
return mavl_find(set->all_elems,element);
struct cw_ElemHandler * cw_message_set_find_element(
struct cw_MsgSet * set,
struct cw_ElemHandler * element){
return mavl_find(set->all_elems_by_id,element);
}
mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type){
message2_t search;
mlist_t cw_msgset_get_msg(struct cw_MsgSet * set, int type){
struct cw_MsgData search;
search.type = type;
message2_t * result = mavl_find(set->messages,&search);
struct cw_MsgData * result = mavl_find(set->messages,&search);
if (!result){
printf ("no result\n");
return NULL;

View File

@ -1,13 +1,50 @@
#ifndef __MESSAGE_SET_H
#define __MESSAGE_SET_H
#include "cw.h"
extern void cw_message_set_destroy(cw_MsgSet_t * set);
extern cw_MsgSet_t * cw_message_set_create();
extern void cw_msgset_add(cw_MsgSet_t * set,
cw_msgdef_t messages[]);
mlist_t cw_msgset_get_msg(cw_MsgSet_t * set, int type);
struct cw_MsgSet {
mavl_t messages;
mavl_t all_elems_by_id;
mavl_t all_elems_by_key;
};
struct cw_ElemDef{
int id;
int mand;
int op;
};
struct cw_ElemData{
struct cw_ElemHandler *handler;
int mand;
};
struct cw_ElemHandler {
const char * name;
int id;
int vendor;
int proto;
int min_len;
int max_len;
const struct mdata_Type * type;
const char * key;
/*
int (*start_in)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);
int (*end_in)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from);
*/
};
struct cw_MsgDef{
const char * name;
int type; /**< Message type */
int receiver; /**< Who can receive this message */
int * states; /**< states in wich the message is allowed */
struct cw_ElemDef * elements;
};
struct cw_MsgData{
@ -19,7 +56,15 @@ struct cw_MsgData{