From b9c5bdb2a85ef883e2db1b26f0f7837ffaf86163 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 26 Feb 2016 17:52:29 +0000 Subject: [PATCH] Work on mods. FossilOrigin-Name: dd9a471a2121d864295d81ab5c115a4995914e73f49481a80e2981b117860e0a --- src/ac/wtpman.c | 6 ++ src/capwap/Makefile | 1 + src/capwap/conn_process_packet.c | 8 ++- src/capwap/conn_process_packet2.c | 2 +- src/capwap/cw_check_missing_mand.c | 4 +- src/capwap/cw_in_generic2.c | 81 ++++++++++++----------- src/capwap/mod/capwap/Makefile | 4 +- src/capwap/mod/capwap/capwap_actions_ac.c | 69 ++++++++++++++++++- src/capwap/mod/capwap/mod_capwap.h | 8 +++ src/wtp/wtp_main.c | 3 +- 10 files changed, 137 insertions(+), 49 deletions(-) diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index b621436e..4c012b7b 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -519,7 +519,13 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr) cw_dbg(DBG_INFO,"Creating wtpman on socket %d, %s:%d",sockfd,sock_addr2str(&dbgaddr),sock_getport(&dbgaddr)); +extern int conn_process_packet2(struct conn *conn, uint8_t * packet, int len, + struct sockaddr *from); + wtpman->conn = conn_create(sockfd, srcaddr, 100); + +// wtpman->conn->process_packet = conn_process_packet2; + if (!wtpman->conn) { wtpman_destroy(wtpman); return NULL; diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 89cdcd64..a74cee72 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -189,6 +189,7 @@ DTLSOBJS+=dtls_bio.o CONNOBJS= conn_create.o \ conn_process_packet.o \ + conn_process_packet2.o \ conn_q_add_packet.o \ conn_q_get_packet.o \ conn_q_recv_packet.o \ diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index 63c32509..84cdeec6 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -30,6 +30,8 @@ #include "conn.h" #include "sock.h" +#include "stravltree.h" + int conn_send_msg(struct conn *conn, uint8_t * rawmsg); @@ -246,7 +248,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, uint8_t *elem; /* Create an avltree to catch the found mandatory elements */ - conn->mand = intavltree_create(); + conn->mand = stravltree_create(); /* iterate through message elements */ cw_foreach_elem(elem, elems_ptr, elems_len) { @@ -278,7 +280,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, if (af->mand && afrc) { /* add found mandatory message element to mand list */ - intavltree_add(conn->mand, (int) af->item_id); + stravltree_add(conn->mand, af->item_id); } } @@ -312,7 +314,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, */ } - intavltree_destroy(conn->mand); + stravltree_destroy(conn->mand); return result_code; diff --git a/src/capwap/conn_process_packet2.c b/src/capwap/conn_process_packet2.c index 63c32509..5b60d9ca 100644 --- a/src/capwap/conn_process_packet2.c +++ b/src/capwap/conn_process_packet2.c @@ -393,7 +393,7 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen, * @param packet pointer to packet data * @param len lenght of packet data */ -int conn_process_packet(struct conn *conn, uint8_t * packet, int len, +int conn_process_packet2(struct conn *conn, uint8_t * packet, int len, struct sockaddr *from) { /* show this packet in debug output */ diff --git a/src/capwap/cw_check_missing_mand.c b/src/capwap/cw_check_missing_mand.c index 4c217efd..2948f071 100644 --- a/src/capwap/cw_check_missing_mand.c +++ b/src/capwap/cw_check_missing_mand.c @@ -74,8 +74,8 @@ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_i if (!ai->mand) continue; - int i = (intptr_t)ai->item_id; - void * rc = mavl_get(conn->mand,&i); +// int i = (intptr_t)ai->item_id; + void * rc = mavl_get(conn->mand,(void*)ai->item_id); if (!rc) { out[n++]=ai; } diff --git a/src/capwap/cw_in_generic2.c b/src/capwap/cw_in_generic2.c index e54442c3..ef9b4d08 100644 --- a/src/capwap/cw_in_generic2.c +++ b/src/capwap/cw_in_generic2.c @@ -33,44 +33,6 @@ int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from) { - if (a->itemtype == MBAG_BYTE) { - mbag_set_byte(itemstore, a->item_id, *data); - return 1; - } - if (a->itemtype == MBAG_WORD) { - mbag_set_word(itemstore, a->item_id, cw_get_word(data)); - return 1; - } - if (a->itemtype == MBAG_DWORD) { - mbag_set_dword(itemstore, a->item_id, cw_get_dword(data)); - return 1; - } - if (a->itemtype == MBAG_STR) { - mbag_set_strn(itemstore, a->item_id, (char *) data, len); - return 1; - } - if (a->itemtype == MBAG_BSTR) { - mbag_set_bstrn(itemstore, a->item_id, data, len); - return 1; - } - - if (a->itemtype == MBAG_BSTR16) { - mbag_set_bstr16n(itemstore, a->item_id, data, len); - return 1; - } - -/* if (a->itemtype == MBAG_DATA) { - mbag_set_data(itemstore, a->item_id, data, len); - return 1; - } -*/ - if (a->itemtype == MBAG_VENDORSTR) { - mbag_set_vendorstr(itemstore, a->item_id, - cw_get_dword(data), data + 4, len - 4); - return 1; - } - - const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE); if (!idef) { @@ -79,13 +41,54 @@ int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a, } + + + if (idef->type == MBAG_BYTE) { + mbag_set_byte(itemstore, a->item_id, *data); + return 1; + } + if (idef->type == MBAG_WORD) { + mbag_set_word(itemstore, a->item_id, cw_get_word(data)); + return 1; + } + if (idef->type == MBAG_DWORD) { + mbag_set_dword(itemstore, a->item_id, cw_get_dword(data)); + return 1; + } + if (idef->type == MBAG_STR) { + mbag_set_strn(itemstore, a->item_id, (char *) data, len); + return 1; + } + if (idef->type == MBAG_BSTR) { + mbag_set_bstrn(itemstore, a->item_id, data, len); + return 1; + } + + if (idef->type == MBAG_BSTR16) { + mbag_set_bstr16n(itemstore, a->item_id, data, len); + return 1; + } + +/* if (idef->type == MBAG_DATA) { + mbag_set_data(itemstore, a->item_id, data, len); + return 1; + } +*/ + if (idef->type == MBAG_VENDORSTR) { + mbag_set_vendorstr(itemstore, a->item_id, + cw_get_dword(data), data + 4, len - 4); + return 1; + } + + + // printf("Idef: %s\n",idef->type->name); cw_log(LOG_ERR, "Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.", - a->itemtype, a->msg_id, cw_strmsg(a->msg_id), a->elem_id); + idef->type, a->msg_id, cw_strmsg(a->msg_id), a->elem_id); return 0; diff --git a/src/capwap/mod/capwap/Makefile b/src/capwap/mod/capwap/Makefile index 1056b428..0e5d477d 100644 --- a/src/capwap/mod/capwap/Makefile +++ b/src/capwap/mod/capwap/Makefile @@ -3,7 +3,9 @@ include ../../../Config.mak OBJS=\ mod_capwap_ac.o \ - capwap_actions_ac.o + capwap_actions_ac.o \ + capwap_in_wtp_descriptor.o \ + capwap_in_wtp_board_data.o OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS)) diff --git a/src/capwap/mod/capwap/capwap_actions_ac.c b/src/capwap/mod/capwap/capwap_actions_ac.c index 1af83b8c..97f7b37b 100644 --- a/src/capwap/mod/capwap/capwap_actions_ac.c +++ b/src/capwap/mod/capwap/capwap_actions_ac.c @@ -24,7 +24,7 @@ #include "capwap/strheap.h" #include "capwap/radio.h" - +#include "mod_capwap.h" cw_action_in_t _capwap_actions_ac_in[] = { @@ -51,6 +51,70 @@ cw_action_in_t _capwap_actions_ac_in[] = { } , + /* Element WTP Frame Tunnel Mode */ + { + .capwap_state = CW_STATE_DISCOVERY, + .msg_id = CW_MSG_DISCOVERY_REQUEST, + .elem_id = CW_ELEM_WTP_FRAME_TUNNEL_MODE, + .start = cw_in_generic2, + .item_id = "wtp_frame_tunnel_mode", + .mand = 1, + .min_len = 1, + .max_len = 1 + } + , + + /* Element WTP Mac Type */ + { + .capwap_state = CW_STATE_DISCOVERY, + .msg_id = CW_MSG_DISCOVERY_REQUEST, + .elem_id = CW_ELEM_WTP_MAC_TYPE, + .start = cw_in_generic2, + .item_id = "wtp_mac_type", + .mand = 1, + .min_len = 1, + .max_len = 1 + } + , + + + /* Element WTP Descriptor */ + { + .capwap_state = CW_STATE_DISCOVERY, + .msg_id = CW_MSG_DISCOVERY_REQUEST, + .elem_id = CW_ELEM_WTP_DESCRIPTOR, + .start = capwap_in_wtp_descriptor, + .item_id = "wtp_descriptor", + .mand = 1, + } + + , + + /* Element WTP Board Data */ + { + .capwap_state = CW_STATE_DISCOVERY, + .msg_id = CW_MSG_DISCOVERY_REQUEST, + .elem_id = CW_ELEM_WTP_BOARD_DATA, + .start = capwap_in_wtp_board_data, + .item_id = "wtp_board_data", + .mand = 1, + } +// , + + /* Element WTP Board Data */ +// {0, 0, CW_STATE_CONFIGURE, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA, +// 1} + , + + + /* Vendor Specific Payload */ + { + .capwap_state = CW_STATE_DISCOVERY, + .msg_id = CW_MSG_DISCOVERY_REQUEST, + .elem_id = CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, + }, + + /* Element WTP Name */ { .capwap_state = CW_STATE_DISCOVERY, @@ -58,7 +122,7 @@ cw_action_in_t _capwap_actions_ac_in[] = { .elem_id = CW_ELEM_WTP_NAME, .start = cw_in_generic2, .item_id = "wtp_name", - .mand = 1, + .mand = 0, .min_len = 1, .max_len = 1024 } @@ -76,6 +140,7 @@ 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_NONE} }; diff --git a/src/capwap/mod/capwap/mod_capwap.h b/src/capwap/mod/capwap/mod_capwap.h index c7e5988d..0ea9a94e 100644 --- a/src/capwap/mod/capwap/mod_capwap.h +++ b/src/capwap/mod/capwap/mod_capwap.h @@ -3,4 +3,12 @@ struct mod_ac * mod_capwap_ac(); + +extern int capwap_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len, struct sockaddr *from); + +int capwap_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len, struct sockaddr *from); + + #endif diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index aa5f6bda..3267cb4a 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -131,7 +131,8 @@ mavl_destroy(b); conn->local = mbag_create(); conn->base_rmac=get_base_rmac(); -conn->capwap_mode = CW_MODE_CISCO; +conn->capwap_mode = CW_MODE_CAPWAP; +//conn->capwap_mode = CW_MODE_CISCO; the_conn->strict_capwap=0;