From ca22c44590f5e57ae1eeaeda18abf5807269e89f Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sat, 3 Mar 2018 07:15:19 +0000 Subject: [PATCH] Work on msgset FossilOrigin-Name: 47f9ccd5e442443a9023a8d408ef2ebe2d073c947767058ba631d8b1a94063b2 --- libcw.project | 7 + src/ac/ac_global.c | 2 +- src/ac/ac_main.c | 5 +- src/cw/action.h | 5 + src/cw/capwap.h | 107 ++- src/cw/capwap_strings_result.c | 4 +- src/cw/conn.h | 18 +- src/cw/conn_process_packet.c | 20 +- src/cw/cw.h | 36 +- src/cw/cw_in_check_img_data_req_ac.c | 6 +- src/cw/cw_in_check_img_data_req_wtp.c | 8 +- src/cw/cw_type_byte.c | 62 ++ src/cw/cw_type_dword.c | 61 ++ src/cw/cw_type_word.c | 61 ++ src/cw/cw_types.h | 12 + src/cw/cwmsg.h | 2 - src/cw/fragman.h | 12 +- src/cw/item.h | 2 +- src/cw/log.h | 11 +- src/cw/mavl.h | 10 +- src/cw/mbag_type_bstr16.c | 1 + src/cw/mdata.c | 8 + src/cw/mdata.h | 68 ++ src/cw/mdata_elem_new.c | 15 + src/cw/message_set.c | 203 +++--- src/cw/message_set.h | 61 +- src/cw/mod.c | 2 +- src/cw/sock.h | 10 + src/mod/Mod.mak | 6 +- src/mod/capwap/capwap_actions_ac.c | 909 ++------------------------ src/mod/capwap/mod_capwap_ac.c | 6 +- 31 files changed, 669 insertions(+), 1071 deletions(-) create mode 100644 src/cw/cw_type_byte.c create mode 100644 src/cw/cw_type_dword.c create mode 100644 src/cw/cw_type_word.c create mode 100644 src/cw/cw_types.h create mode 100644 src/cw/mdata.c create mode 100644 src/cw/mdata.h create mode 100644 src/cw/mdata_elem_new.c diff --git a/libcw.project b/libcw.project index a3cc5a86..33bb2126 100644 --- a/libcw.project +++ b/libcw.project @@ -307,6 +307,13 @@ + + + + + + + diff --git a/src/ac/ac_global.c b/src/ac/ac_global.c index fb726941..09e4cd3b 100644 --- a/src/ac/ac_global.c +++ b/src/ac/ac_global.c @@ -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, diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index 5151cc75..2b8e2c5f 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -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()) diff --git a/src/cw/action.h b/src/cw/action.h index 98923f7a..c6613084 100644 --- a/src/cw/action.h +++ b/src/cw/action.h @@ -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); +*/ /** * @} diff --git a/src/cw/capwap.h b/src/cw/capwap.h index a1a1fd43..5cf24f5f 100644 --- a/src/cw/capwap.h +++ b/src/cw/capwap.h @@ -26,7 +26,7 @@ #define __CAPWAP_H #include -//#include + #include #include @@ -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); diff --git a/src/cw/capwap_strings_result.c b/src/cw/capwap_strings_result.c index 8f9eeebd..e8d6339e 100644 --- a/src/cw/capwap_strings_result.c +++ b/src/cw/capwap_strings_result.c @@ -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 */ diff --git a/src/cw/conn.h b/src/cw/conn.h index 6a30a3d7..54521f54 100644 --- a/src/cw/conn.h +++ b/src/cw/conn.h @@ -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); diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index 3339ac04..7ad33dac 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -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; diff --git a/src/cw/cw.h b/src/cw/cw.h index 0d4ba6c8..6f00448f 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -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); diff --git a/src/cw/cw_in_check_img_data_req_ac.c b/src/cw/cw_in_check_img_data_req_ac.c index 3c1d038e..1a1099d0 100644 --- a/src/cw/cw_in_check_img_data_req_ac.c +++ b/src/cw/cw_in_check_img_data_req_ac.c @@ -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; } diff --git a/src/cw/cw_in_check_img_data_req_wtp.c b/src/cw/cw_in_check_img_data_req_wtp.c index a9129793..cede33bf 100644 --- a/src/cw/cw_in_check_img_data_req_wtp.c +++ b/src/cw/cw_in_check_img_data_req_wtp.c @@ -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; } diff --git a/src/cw/cw_type_byte.c b/src/cw/cw_type_byte.c new file mode 100644 index 00000000..363f1b25 --- /dev/null +++ b/src/cw/cw_type_byte.c @@ -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 . + +*/ + +#include + +#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(); diff --git a/src/cw/cw_type_dword.c b/src/cw/cw_type_dword.c new file mode 100644 index 00000000..e01dd725 --- /dev/null +++ b/src/cw/cw_type_dword.c @@ -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 . + +*/ + +#include + +#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(); diff --git a/src/cw/cw_type_word.c b/src/cw/cw_type_word.c new file mode 100644 index 00000000..dc63f2bd --- /dev/null +++ b/src/cw/cw_type_word.c @@ -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 . + +*/ + +#include + +#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(); diff --git a/src/cw/cw_types.h b/src/cw/cw_types.h new file mode 100644 index 00000000..8d26354b --- /dev/null +++ b/src/cw/cw_types.h @@ -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 diff --git a/src/cw/cwmsg.h b/src/cw/cwmsg.h index 49071a55..fb7ea1a1 100644 --- a/src/cw/cwmsg.h +++ b/src/cw/cwmsg.h @@ -4,8 +4,6 @@ #include #include "radioinfo.h" -//#include "acinfo.h" -//#include "wtpinfo.h" struct cwmsg{ uint8_t * buffer; diff --git a/src/cw/fragman.h b/src/cw/fragman.h index 7106bbf0..6bfa0d25 100644 --- a/src/cw/fragman.h +++ b/src/cw/fragman.h @@ -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); diff --git a/src/cw/item.h b/src/cw/item.h index d96c620f..179b840b 100644 --- a/src/cw/item.h +++ b/src/cw/item.h @@ -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 diff --git a/src/cw/log.h b/src/cw/log.h index a863b0c5..f0dc2da1 100644 --- a/src/cw/log.h +++ b/src/cw/log.h @@ -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, ...); diff --git a/src/cw/mavl.h b/src/cw/mavl.h index 26590884..554ec6f1 100644 --- a/src/cw/mavl.h +++ b/src/cw/mavl.h @@ -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) diff --git a/src/cw/mbag_type_bstr16.c b/src/cw/mbag_type_bstr16.c index 21c72f9a..4c2bc54b 100644 --- a/src/cw/mbag_type_bstr16.c +++ b/src/cw/mbag_type_bstr16.c @@ -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, diff --git a/src/cw/mdata.c b/src/cw/mdata.c new file mode 100644 index 00000000..a4a9008e --- /dev/null +++ b/src/cw/mdata.c @@ -0,0 +1,8 @@ +#include "mavl.h" +#include "mdata.h" + + +mdata_create(){ + return 0; +} + diff --git a/src/cw/mdata.h b/src/cw/mdata.h new file mode 100644 index 00000000..04efb873 --- /dev/null +++ b/src/cw/mdata.h @@ -0,0 +1,68 @@ +#ifndef __MDATA_H +#define __MDATA_H + + +#include + +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 */ + diff --git a/src/cw/mdata_elem_new.c b/src/cw/mdata_elem_new.c new file mode 100644 index 00000000..25529025 --- /dev/null +++ b/src/cw/mdata_elem_new.c @@ -0,0 +1,15 @@ +#include + + +#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; +} + diff --git a/src/cw/message_set.c b/src/cw/message_set.c index 0a0b6229..547f0df9 100644 --- a/src/cw/message_set.c +++ b/src/cw/message_set.c @@ -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; diff --git a/src/cw/message_set.h b/src/cw/message_set.h index 7c1418b9..b4536994 100644 --- a/src/cw/message_set.h +++ b/src/cw/message_set.h @@ -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{ mlist_t elements_list; }; -typedef struct cw_MsgData message2_t; + +extern struct cw_MsgSet * cw_msgset_create(); + +extern void cw_msgset_destroy(struct cw_MsgSet * set); +extern int cw_msgset_add(struct cw_MsgSet * set, + struct cw_MsgDef messages[], struct cw_ElemHandler elements[]); +mlist_t cw_msgset_get_msg(struct cw_MsgSet * set, int type); -#endif \ No newline at end of file + + +#endif diff --git a/src/cw/mod.c b/src/cw/mod.c index 2514fdc7..b2fc4829 100644 --- a/src/cw/mod.c +++ b/src/cw/mod.c @@ -123,7 +123,7 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn, } memset(cached_set, 0, sizeof(struct cache_item)); - struct cw_MsgSet * set = cw_message_set_create(); + struct cw_MsgSet * set = cw_msgset_create(); if (!set) { free(cached_set); cw_log(LOG_ERR, "Can't allocate memory for mod cache item %s", diff --git a/src/cw/sock.h b/src/cw/sock.h index 39e9d3d1..e8d6a238 100644 --- a/src/cw/sock.h +++ b/src/cw/sock.h @@ -56,7 +56,11 @@ extern int sock_getifaddr(const char *ifname, int family, int type, struct socka extern int sock_getifhwaddr(const char *ifname, uint8_t * hwaddr, uint8_t * addrlen); extern char *sock_hwaddrtostr(const uint8_t * haddr, int len, char *dst, const char *separator); + +/* //extern char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen); +*/ + extern int sock_strtoaddr(const char *s, struct sockaddr *saout); extern int sock_set_recvtimeout(int sock, int seconds); @@ -69,7 +73,10 @@ extern int sock_set_dontfrag(int sock, int val); extern char *sock_get_primary_if(int family); + +/* //extern char * sock_getifinfo(const struct sockaddr *sa,struct ifaddrs *result); +*/ extern int sock_getifinfo(const struct sockaddr *addr, char *ifname, struct sockaddr *broadcast, struct sockaddr *netmask); @@ -105,7 +112,10 @@ char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen, int addp #define sock_hwaddr2str(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, ":" ) ) #define sock_hwaddr2idstr(s,l) ( sock_hwaddrtostr( s,l, (char[64]){0}, "" ) ) + +/* //#define sock_addrtostr(s,str,n) sock_addrtostr(s,str,n,1) +*/ #define sock_addrfamily(addr) ( ((struct sockaddr_storage*)(addr))->ss_family ) diff --git a/src/mod/Mod.mak b/src/mod/Mod.mak index 8ad1d35a..5d288392 100644 --- a/src/mod/Mod.mak +++ b/src/mod/Mod.mak @@ -5,7 +5,9 @@ include ../../Config.local.mak OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS)) -CFLAGS = -fPIC -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 $(COMPDEFS) -DWITH_RMAC_SUPPORT -I ../../ -I../ -I../../include +#CFLAGS = -fPIC -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 $(COMPDEFS) -DWITH_RMAC_SUPPORT + +CFLAGS+= -I ../../ -I../ -I../../include SRCS = $(OBJS:.o=.c) @@ -26,7 +28,7 @@ $(SNAME) : $(OBJS) $(MODOBJS) $(DNAME) : $(OBJS) $(MODOBJS) @mkdir -p $(LIBARCHDIR) @echo " $(CC) $(DNAME)" - @$(CC) -L$(LIBARCHDIR) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(SLIBS) $(LIBS) + @$(LD) -L$(LIBARCHDIR) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(SLIBS) $(LIBS) $(MODNAME) : $(DNAME) cp $(DNAME) $(MODNAME) diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index 936e48f8..c7ad82f0 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -17,89 +17,63 @@ */ - #include "cw/cw.h" +#include "cw/cw_types.h" #include "cw/log.h" -#include "cw/action.h" -#include "cw/capwap_items.h" -#include "cw/strheap.h" -#include "cw/radio.h" #include "cw/message_set.h" #include "mod_capwap.h" -static cw_elem_handler_t _DISCOVERY_TYPE = { - .name = "Discovery Type", - .id = CAPWAP_ELEM_DISCOVERY_TYPE, - //.start = cw_in_generic2, - //.item_id = "discovery_type", - .min_len = 1, - .max_len = 1 -}; -static cw_elem_handler_t _WTP_BOARD_DATA = { - .name = "WTP Board Data", - .id = CAPWAP_ELEM_WTP_BOARD_DATA, -// .start = cw_in_wtp_board_data, -// .item_id = CW_ITEM_WTP_BOARD_DATA, -}; +static struct cw_ElemHandler elements[] = { -static cw_elem_handler_t _WTP_DESCRIPTOR = { - .id = CAPWAP_ELEM_WTP_DESCRIPTOR, - .name = "WTP Descriptor", - //.start = capwap_in_wtp_descriptor, - //.item_id = "wtp_descriptor", -}; + { + "Discovery Type", /* name */ + CAPWAP_ELEM_DISCOVERY_TYPE, /* Element ID */ + 0,0, /* Vendor / Proto */ + 1,1, /* min/max length */ + CW_TYPE_BYTE, /* type */ + "discovery_type" /* Key */ + } + , + { + "WTP Mac Type", /* name */ + CAPWAP_ELEM_WTP_MAC_TYPE, /* Element ID */ + 0,0, /* Vendor / Proto */ + 1,1, /* min/max length */ + CW_TYPE_BYTE, /* type */ + "wtp_mac_type" /* Key */ + } + , + {0,0,0,0,0,0,0,0} -static cw_elem_handler_t _WTP_FRAME_TUNNEL_MODE = { - .id = CAPWAP_ELEM_WTP_FRAME_TUNNEL_MODE, - .name = "WTP Frame Tunnel Mode", -// .start = cw_in_generic2, -// .item_id = CW_ITEM_WTP_FRAME_TUNNEL_MODE, - .min_len = 1, - .max_len = 1 -}; - -static cw_elem_handler_t _WTP_MAC_TYPE = { - .id = CAPWAP_ELEM_WTP_MAC_TYPE, - .name = "WTP Mac Type", -// .start = cw_in_generic2, -// .item_id = CW_ITEM_WTP_MAC_TYPE, - .min_len = 1, - .max_len = 1 -}; - -/* MTU Discovery Padding */ -static cw_elem_handler_t _MTU_DISCOVERY_PADDING = { - .id = CW_ELEM_MTU_DISCOVERY_PADDING, - .name = "MTU Discovery Padding" -// .start = cw_in_mtu_discovery_padding, -}; - -static cw_elem_handler_t _VENDOR_SPECIFIC_PAYLOAD = { - .name = "Vendor Specific Payload", - .id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - -// .start = cw_in_vendor_specific_payload, - .min_len=7 -}; - -/* AC Descriptor - Discovery Response */ -static cw_elem_handler_t _AC_DESCRIPTOR = { - .name = "AC Descriptor", - .id = CAPWAP_ELEM_AC_DESCRIPTOR, - //.item_id = CW_ITEM_AC_DESCRIPTOR, - //.start = cw_in_ac_descriptor, - .min_len = 12, - .max_len = 8192, }; +static int discovery_request_states[] = {CAPWAP_STATE_DISCOVERY,0}; +static struct cw_ElemDef discovery_request_elements[] ={ + {CAPWAP_ELEM_DISCOVERY_TYPE, 1, 0} +}; -static cw_msgdef_t messages[] = { +static struct cw_MsgDef messages[] = { + { + "Discovery Request", + CAPWAP_MSG_DISCOVERY_REQUEST, + CW_RECEIVER_AC, + discovery_request_states, + discovery_request_elements + }, +/* { + "Discovery Request", + CAPWAP_MSG_DISCOVERY_REQUEST, + CW_RECEIVER_AC, + (int[]){CAPWAP_STATE_DISCOVERY,0} + + }, +*/ /* Discovery Request Message*/ - { +/* { .name = "Discovery Request", .type = CAPWAP_MSG_DISCOVERY_REQUEST, .receiver = CW_RECEIVER_AC, @@ -115,8 +89,9 @@ static cw_msgdef_t messages[] = { {0,0}, } }, +*/ /* Discovery Request Response */ - { +/* { .name = "Discovery Response", .type = CAPWAP_MSG_DISCOVERY_RESPONSE, .receiver = CW_RECEIVER_WTP, @@ -126,7 +101,7 @@ static cw_msgdef_t messages[] = { {0,0}, } }, - {0,0,0,0} +*/ {0,0,0,0} @@ -137,18 +112,21 @@ static cw_msgdef_t messages[] = { struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){ if (mode != CW_MOD_MODE_CAPWAP) return NULL; - cw_msgset_add(set,messages); + cw_msgset_add(set,messages, elements); return set; } void test_sets(){ - cw_MsgSet_t * set = cw_message_set_create(); + struct cw_MsgSet * set = cw_msgset_create(); if (set==NULL){ cw_log(LOG_ERR,"No mem"); return; } + cw_msgset_add(set,messages, elements); +} +/* cw_msgset_add(set,messages); cw_elem_handler_t el; @@ -192,796 +170,9 @@ void test_sets(){ - - - - - - - - -static cw_action_in_t actions_in[] = { - - - /* -------------------------------------------------------------------------- - * Discovery Request - */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .end = cw_in_check_disc_req - } - , - - /* Element Discovery Type */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_DISCOVERY_TYPE, - .start = cw_in_generic2, - .item_id = "discovery_type", - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - /* Element WTP Board Data - Discovery Request */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_BOARD_DATA, - .start = cw_in_wtp_board_data, - .item_id = CW_ITEM_WTP_BOARD_DATA, - .mand = 1, - } - , - - /* Element WTP Descriptor - Discovery */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_DESCRIPTOR, - .start = capwap_in_wtp_descriptor, - .item_id = "wtp_descriptor", - .mand = 1, - } - , - - - /* Element WTP Frame Tunnel Mode */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_FRAME_TUNNEL_MODE, - .start = cw_in_generic2, - .item_id = CW_ITEM_WTP_FRAME_TUNNEL_MODE, - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - /* Element WTP Mac Type */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_MAC_TYPE, - .start = cw_in_generic2, - .item_id = CW_ITEM_WTP_MAC_TYPE, - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - - - /* MTU Discovery Padding */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CW_ELEM_MTU_DISCOVERY_PADDING, - .start = cw_in_mtu_discovery_padding, - } - , -// TODO: Add them - /* Vendor Specific Payload */ - { - .capwap_state = CAPWAP_STATE_DISCOVERY, - .msg_id = CAPWAP_MSG_DISCOVERY_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - .min_len=7 - } - , - - - /* -------------------------------------------------------------------------- - * Join Request - */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .end = cw_in_check_join_req - } - , - - /* Location Data - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id =CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_LOCATION_DATA, - .item_id = CW_ITEM_LOCATION_DATA, - .start = cw_in_generic2, - .max_len = 1024, - .min_len = 1, - .mand = 1 - } - , - - /* Element WTP Board Data - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_BOARD_DATA, - .start = cw_in_wtp_board_data, - .item_id = CW_ITEM_WTP_BOARD_DATA, - .mand = 1, - } - , - - /* Element WTP Descriptor - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_DESCRIPTOR, - .start = capwap_in_wtp_descriptor, - .item_id = CW_ITEM_WTP_DESCRIPTOR, - .mand = 1, - } - , - - /* Element WTP Name - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_WTP_NAME, - .start = cw_in_generic2, - .item_id = CW_ITEM_WTP_NAME, - .mand = 1, - .min_len = 1, - .max_len = 1024 - } - , - - /* Element Session ID - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_SESSION_ID, - .start = capwap_in_session_id, - .item_id = CW_ITEM_SESSION_ID, - .mand = 1, - .min_len = 16, - .max_len = 16 - } - , - - /* WTP Frame Tunnel Mode - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_FRAME_TUNNEL_MODE, - .start = cw_in_generic2, - .item_id = CW_ITEM_WTP_FRAME_TUNNEL_MODE, - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - /* WTP Mac Type - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CAPWAP_ELEM_WTP_MAC_TYPE, - .start = cw_in_generic2, - .item_id = CW_ITEM_WTP_MAC_TYPE, - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - /* The mandatory WTP Radio Information message elements, - described in RFC5145 are inserted by the apropriate - bindings mod */ - - - /* ECN Support - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_ECN_SUPPORT, - .item_id = CW_ITEM_ECN_SUPPORT, - .start = cw_in_generic2, - .mand = 1, - .min_len = 1, - .max_len = 1 - } - , - - - /* Local IPv4 Address - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_CAPWAP_LOCAL_IPV4_ADDRESS, - .item_id = CW_ITEM_CAPWAP_LOCAL_IP_ADDRESS, - .start = cw_in_capwap_local_ipv4_address, - .mand = 1, - .min_len = 4, - .max_len = 4 - } - , - - /* Local IPv6 Address - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_CAPWAP_LOCAL_IPV6_ADDRESS, - .item_id = CW_ITEM_CAPWAP_LOCAL_IP_ADDRESS, - .start = cw_in_capwap_local_ipv4_address, - .mand = 1, - .min_len = 16, - .max_len = 16 - } - , - - /* The following elements are not mandatory */ - - /* CAPWAP Transport Protocol - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_CAPWAP_TRANSPORT_PROTOCOL, - .item_id = CW_ITEM_CAPWAP_TRANSPORT_PROTOCOL, - .start = cw_in_generic2, - .min_len = 1, - .max_len = 1 - } - , - - /* Maximum Message Length - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_MAXIMUM_MESSAGE_LENGTH, - .start = cw_in_generic2, - .item_id = CW_ITEM_MAXIMUM_MESSAGE_LENGTH, - .min_len = 2, - .max_len = 2 - } - , - - /* WTP Reboot Statistics - Join Request */ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CW_ELEM_WTP_REBOOT_STATISTICS, - .start = cw_in_wtp_reboot_statistics, - .item_id = CW_ITEM_WTP_REBOOT_STATISTICS, - .min_len = 15, - .max_len = 15 - } - , - - /* Vendor Specific Payload - Join Request*/ - { - .capwap_state = CAPWAP_STATE_JOIN, - .msg_id = CAPWAP_MSG_JOIN_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - .min_len=7 - } - , - - - - /* -------------------------------------------------------------------------- - * Configuration Status Request - IN - */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .end = cw_in_check_generic_req - } - , - - /* AC Name - Config Status Request */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .elem_id = CW_ELEM_AC_NAME, - .item_id = CW_ITEM_AC_NAME, - .start = cw_in_generic2, - .min_len = 1, - .max_len = 512, - .mand = 1 - - } - , - - /* Radio Admin State (IN) - Config Status Request */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .elem_id = CW_ELEM_RADIO_ADMINISTRATIVE_STATE, - .item_id = CW_RADIOITEM_ADMIN_STATE, - .start = cw_in_radio_generic, - .mand = 1 - - } - , - - /* Statistics Timer - Config Status Request */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .elem_id = CW_ELEM_STATISTICS_TIMER, - .item_id = CW_ITEM_STATISTICS_TIMER, - .start = cw_in_generic2, - .min_len = 2, - .max_len = 2, - .mand = 1 - - } - , - - - /* WTP Reboot Statistics - Config Status Request */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .elem_id = CW_ELEM_WTP_REBOOT_STATISTICS, - .start = cw_in_wtp_reboot_statistics, - .item_id = CW_ITEM_WTP_REBOOT_STATISTICS, - .min_len = 15, - .max_len = 15, - .mand =1 - } - , - - - - /* Vendor Specific Payload - Config Status Request */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - } - , - - - /* -------------------------------------------------------------------------- - * Change State Event Request IN (in configure state) - */ - { - .capwap_state=CW_STATE_CONFIGURE, - .msg_id = CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .end = cw_in_check_chng_state_evnt_req - } - , - - /* Result Code - Change State Event Req */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id= CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CW_ELEM_RESULT_CODE, - .item_id = CW_ITEM_RESULT_CODE, - .start = cw_in_generic2, - .min_len=4, - .max_len=4, - .mand = 1 - } - , - - /* Radio Operational State - Change State Event Req */ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id= CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CW_ELEM_RADIO_OPERATIONAL_STATE, - .item_id = CW_RADIOITEM_OPER_STATE, - .start = cw_in_radio_generic, //operational_state, - .min_len=3, - .max_len=3, - .mand = 0 - } - , - - - /* Vendor Specific Payload - Change State Req*/ - { - .capwap_state = CW_STATE_CONFIGURE, - .msg_id = CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - .min_len=7 - } - , - - - /* -------------------------------------------------------------------------- - * Change State Event Request IN (in run state) - */ - { - .capwap_state=CW_STATE_RUN, - .msg_id = CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .end = cw_in_check_chng_state_evnt_req - } - , - - /* Result Code - Change State Event Req */ - { - .capwap_state = CW_STATE_RUN, - .msg_id= CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CW_ELEM_RESULT_CODE, - .item_id = CW_ITEM_RESULT_CODE, - .start = cw_in_generic2, - .min_len=4, - .max_len=4, - .mand = 1 - } - , - - /* Radio Operational State - Change State Event Req */ - { - .capwap_state = CW_STATE_RUN, - .msg_id= CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CW_ELEM_RADIO_OPERATIONAL_STATE, - .item_id = CW_RADIOITEM_OPER_STATE, -// .start = cw_in_radio_operational_state, - .start = cw_in_radio_generic, - .min_len=3, - .max_len=3, - .mand = 0 - } - , - - - /* Vendor Specific Payload - Change State Req*/ - { - .capwap_state = CW_STATE_RUN, - .msg_id = CW_MSG_CHANGE_STATE_EVENT_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - .min_len=7 - } - , - - - - - /* -------------------------------------------------------------------------- - * Echo Request - */ - { - .capwap_state = CW_STATE_RUN, - .msg_id = CW_MSG_ECHO_REQUEST, - .item_id = "echoreq" - } - , - - /* Vendor Specific Payload - Echo Request*/ - { - .capwap_state = CW_STATE_RUN, - .msg_id = CW_MSG_ECHO_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - } - , - - - /* -------------------------------------------------------------------------- - * WTP Event Request IN (run state) - */ - { - .capwap_state=CW_STATE_RUN, - .msg_id = CW_MSG_WTP_EVENT_REQUEST, - .end = cw_in_check_chng_state_evnt_req - } - , - - /* Vendor Specific Payload - WTP Event Request*/ - { - .capwap_state = CW_STATE_RUN, - .msg_id = CW_MSG_WTP_EVENT_REQUEST, - .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, - .start = cw_in_vendor_specific_payload, - } - , - - /* -------------------------------------------------------------------------- - * Configuration Update Response - */ - { - .capwap_state=CW_STATE_RUN, - .msg_id = CW_MSG_CONFIGURATION_UPDATE_RESPONSE, - } - , - - - - /* End of list */ - {0, 0} -}; - -static cw_action_out_t actions_out[]={ - - /* -------------------------------------------------------------------------- - * Discovery Response Message - */ - - /* AC Descriptor - Discovery Response */ - { - .msg_id = CAPWAP_MSG_DISCOVERY_RESPONSE, - .item_id = CW_ITEM_AC_DESCRIPTOR, - .elem_id = CAPWAP_ELEM_AC_DESCRIPTOR, - .out = capwap_out_ac_descriptor, - .mand = 1 - } - , - - /* AC Name - Discovery Response */ - { - .msg_id = CAPWAP_MSG_DISCOVERY_RESPONSE, - .elem_id = CW_ELEM_AC_NAME, - .item_id = CW_ITEM_AC_NAME, - .out = cw_out_generic, - .get = cw_out_get_local, - .mand = 1 - } - , - - /* List of CAPWAP Control IPv4 and IPv6 addresses - * The handler cw_out_capwap_control_ip_addr_list puts - * ipv4 and ipv6 message elements, so the definition - * of .elem_id isn't needed. - */ - { - .msg_id = CAPWAP_MSG_DISCOVERY_RESPONSE, - .item_id = CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, - .out = cw_out_capwap_control_ip_addr_list, - .get = cw_out_get_outgoing, - .mand = 1 - } - , - - - - - - /* -------------------------------------------------------------------------- - * Join Response Message - */ - - /* Result Code - Join Response */ - - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .elem_id = CW_ELEM_RESULT_CODE, - .item_id = CW_ITEM_RESULT_CODE, - .out = cw_out_generic, - .get = cw_out_get_outgoing, - .mand = 1 - } - , - - /* AC Name - Join Response */ - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .elem_id = CW_ELEM_AC_NAME, - .item_id = CW_ITEM_AC_NAME, - .out = cw_out_generic, - .get = cw_out_get_local, - .mand = 1 - } - , - - /* AC Descriptor - Join Response */ - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .item_id = CW_ITEM_AC_DESCRIPTOR, - .elem_id = CAPWAP_ELEM_AC_DESCRIPTOR, - .out = capwap_out_ac_descriptor, - .mand = 1 - } - , - - - /* Capwap Local IPv4/IPv6 Address - Join Response */ - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .item_id = CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, - .out = cw_out_capwap_control_ip_addr_list, - .get = cw_out_get_outgoing, - .mand = 1 - } - , - - /* ECN Support - Join Response */ - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .elem_id = CW_ELEM_ECN_SUPPORT, - .item_id = CW_ITEM_ECN_SUPPORT, - .out = cw_out_generic, - .get = cw_out_get_config, - .mand = 1 - } - , - - - - { - .msg_id = CAPWAP_MSG_JOIN_RESPONSE, - .elem_id = CW_ELEM_AC_IPV4_LIST, - .out = capwap_out_ac_ip_list - - } - , - - /* -------------------------------------------------------------------------- - * Configuration Status Response Message - OUT - */ - - { - .msg_id = CW_MSG_CONFIGURATION_STATUS_RESPONSE, - .elem_id = CW_ELEM_IDLE_TIMEOUT, - .item_id = CW_ITEM_IDLE_TIMEOUT, - .out = cw_out_generic, - .get = capwap_out_get_idle_timeout, - .mand = 1 - } - , - - { - .msg_id = CW_MSG_CONFIGURATION_STATUS_RESPONSE, - .elem_id = CW_ELEM_CAPWAP_TIMERS, - .item_id = CW_ITEM_CAPWAP_TIMERS, - .out = cw_out_generic, - .get = capwap_out_get_capwap_timers, - .mand = 1 - } - , - - { - .msg_id = CW_MSG_CONFIGURATION_STATUS_RESPONSE, - .elem_id = CW_ELEM_AC_IPV4_LIST, - .out = capwap_out_ac_ip_list - - } - , - - - - /* Change State Event Response */ - - { - .msg_id = CW_MSG_CHANGE_STATE_EVENT_RESPONSE, - .elem_id = CW_ELEM_RESULT_CODE, - .item_id = CW_ITEM_RESULT_CODE, - .out = cw_out_generic, - .get = cw_out_get_outgoing, - .mand = 1 - } - , - - - /* ECHO Response */ - - { - .msg_id = CW_MSG_ECHO_RESPONSE, - } - , - - /* Change State Event Response */ - - { - .msg_id = CW_MSG_WTP_EVENT_RESPONSE, - .elem_id = CW_ELEM_RESULT_CODE, - .item_id = CW_ITEM_RESULT_CODE, - .out = cw_out_generic, - .get = cw_out_get_outgoing, - .mand = 1 - } - , - - - /* -------------------------------------------------------------------------- - * Configuration Update Request - OUT - */ - - /* Location Data */ - { - .msg_id = CW_MSG_CONFIGURATION_UPDATE_REQUEST, - .elem_id = CW_ELEM_LOCATION_DATA, - .item_id = CW_ITEM_LOCATION_DATA, - .out = cw_out_generic, - .get = cw_out_get_outgoing, - .mand = 0 - } - , - - /* WTP Name */ - { - .msg_id = CW_MSG_CONFIGURATION_UPDATE_REQUEST, - .elem_id = CW_ELEM_WTP_NAME, - .item_id = CW_ITEM_WTP_NAME, - .out = cw_out_generic, - .get = cw_out_get_outgoing, - .mand = 0 - } - , - - /* Radio Administrative State - OUT */ - { - .msg_id = CW_MSG_CONFIGURATION_UPDATE_REQUEST, - .elem_id = CW_ELEM_RADIO_ADMINISTRATIVE_STATE, - .item_id = CW_RADIOITEM_ADMIN_STATE, - .out = cw_out_radio_generic, - .mand = 0 - } - , - - - - - {0,0} -}; - - -#include "cw/item.h" - -/* -static struct cw_itemdef _capwap_itemdefs[] = { - - {"wtp_name",CW_ITEM_NONE,MBAG_STR}, - {"wtp_mac_type",CW_ITEM_NONE,MBAG_BYTE}, - {"discovery_type",CW_ITEM_NONE,MBAG_BYTE}, - {"wtp_frame_tunnel_mode",CW_ITEM_NONE,MBAG_BYTE}, - { CW_ITEM_LOCATION_DATA, CW_ITEM_NONE,MBAG_STR}, - { CW_ITEM_SESSION_ID,CW_ITEM_NONE,MBAG_BSTR}, - {CW_ITEM_NONE} - -}; */ -int capwap_register_actions_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(); - def->wbids = intavltree_create(); - def->items = cw_itemdefheap_create(); - def->radioitems = cw_itemdefheap_create(); - - int rc; - rc = cw_actionlist_in_register_actions(def->in, actions_in); - rc += cw_actionlist_out_register_actions(def->out, actions_out); - - rc += cw_strheap_register_strings(def->strmsg, capwap_strings_msg); - rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem); - - rc += cw_itemdefheap_register(def->items, capwap_itemdefs); - rc += cw_itemdefheap_register(def->radioitems, capwap_radioitemdefs); - - intavltree_add(def->wbids, 0); - return rc; -} diff --git a/src/mod/capwap/mod_capwap_ac.c b/src/mod/capwap/mod_capwap_ac.c index f1ae89b7..23cf2ecf 100644 --- a/src/mod/capwap/mod_capwap_ac.c +++ b/src/mod/capwap/mod_capwap_ac.c @@ -18,6 +18,10 @@ extern int capwap_register_actions_ac(struct cw_actiondef *def); static int init() { cw_dbg(DBG_MOD, "Initialiazing mod_capwap."); + + test_sets(); + + exit(0); return 0; } @@ -35,7 +39,7 @@ static int register_actions(struct cw_actiondef *def, int mode) { if (mode != CW_MOD_MODE_CAPWAP) return 0; - return capwap_register_actions_ac(def); + return 0; //capwap_register_actions_ac(def); }