From fdc6b0e4a0b027ac5b022861a95f37eeef3b746f Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 19 Apr 2015 14:44:20 +0000 Subject: [PATCH] Some work on WTP. FossilOrigin-Name: 6ec1370311c5b83dc78adbfb75f8241e0916b171a9c0f939d24ec28ebdf908c8 --- doc/capwap_cisco.txt | 2 +- src/ac/ac_main.c | 18 ++++++ src/ac/wtpman.c | 4 +- src/capwap/Makefile | 11 +++- src/capwap/capwap.h | 14 ++++- src/capwap/capwap_80211.h | 21 ++++--- src/capwap/capwap_80211_actions_wtp.c | 12 +++- src/capwap/capwap_action_helpers.c | 2 +- src/capwap/capwap_actions_wtp.c | 66 ++++++++++++++++++++ src/capwap/capwap_cisco.h | 7 +++ src/capwap/capwap_items.h | 6 +- src/capwap/capwap_strings_elem.c | 2 +- src/capwap/capwap_strings_elem80211.c | 9 +-- src/capwap/cipwap_actions_ac.c | 2 +- src/capwap/cipwap_strings_elem.c | 4 ++ src/capwap/conn.h | 4 ++ src/capwap/conn_process_packet.c | 7 ++- src/capwap/cw_cisco_id_to_str.c | 2 + src/capwap/cw_in_check_img_data_req_ac.c | 4 +- src/capwap/cw_in_check_img_data_req_wtp.c | 4 +- src/capwap/cw_out_generic.c | 12 +++- src/capwap/cw_out_wtp_descriptor.c | 14 ++++- src/capwap/dbg.c | 40 ++++++++++++ src/capwap/itemstore.h | 35 ++++++++++- src/capwap/lwapp.h | 7 +++ src/capwap/mavl.h | 34 +++++++++-- src/capwap/mavl_del.c | 2 +- src/capwap/mavl_get.c | 2 +- src/capwap/timer.h | 8 ++- src/wtp/Makefile | 1 + src/wtp/cfg.c | 72 +++++++++++++++++++++- src/wtp/cfg.json | 27 ++++++--- src/wtp/configure.c | 1 - src/wtp/discovery.c | 2 +- src/wtp/run.c | 74 +++++++++++++++++++++++ src/wtp/wtp_main.c | 25 +++++++- 36 files changed, 496 insertions(+), 61 deletions(-) diff --git a/doc/capwap_cisco.txt b/doc/capwap_cisco.txt index 33f0edf3..6f055cbf 100644 --- a/doc/capwap_cisco.txt +++ b/doc/capwap_cisco.txt @@ -43,7 +43,7 @@ AP = RAD = WTP +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Radio ID | CFG Type | Occupancy Limit | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | CFP Per | CFP Maximum Duration | BSS ID | + | CFP Period | CFP Maximum Duration | BSS ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | BSS ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index 09af81bf..5ab0def7 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -103,10 +103,28 @@ int readelem_cisco_rad_name(struct conn *conn,struct cw_action * a,uint8_t *data #include "capwap/capwap_crypto.h" +#include "capwap/mbag.h" int main (int argc, const char * argv[]) { + mbag_t data = mbag_create(); + + mbag_set_byte(data,1,25); + mbag_set_byte(data,7,125); + + int b = mbag_get_byte(data,1,255); + printf("Result: %d\n",b); + + mbag_del(data,1); + b = mbag_get_byte(data,1,255); + printf("Result: %d\n",b); + + //return 0; + + + + /* intavltree_t t = intavltree_create(); diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index 3b6b7c5c..2666d5f7 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -437,7 +437,7 @@ static void wtpman_run(void *arg) if (conn->capwap_state == CW_STATE_IMAGE_DATA) { /* Image upload */ const char *filename = - cw_itemstore_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME); + cw_itemstore_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME,NULL); if (!filename) { cw_log(LOG_ERR, "Can't send image to %s. No Image Filename Item found.", @@ -455,7 +455,7 @@ static void wtpman_run(void *arg) - DEFINE_CLOCK(clk); + CLOCK_DEFINE(clk); cw_clock_start(&clk); cw_item_t *eof = cw_itemstore_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE, diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 73c171c0..98970c61 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -76,6 +76,10 @@ MAVLOBJS= \ mavl_del.o \ mavl_add.o \ mavl_create.o\ + mavl_get.o\ + mavl_del_all.o\ + mavliter_seek.o \ + mavliter_next.o \ utf8.o # cw_foreach_msgelem.o \ @@ -316,7 +320,12 @@ CWACTION=action.o \ capwap_strings_result.o\ cw_put_msg.o \ capwap_action_helpers.o \ - cw_put_image_data.o + cw_put_image_data.o \ + cisco.o \ + item_strings.o \ + mbag.o\ + radio.o \ + cw_out_radio_info.o # cw_process_msg.o \ diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index dd55e786..449f8e84 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -132,14 +132,14 @@ struct capwap_ctrlhdr //extern int capwap_parse_ctrlhdr(struct capwap_ctrlhdr * ch,uint8_t * msg, int len); /** - *@defgroup CAPWAPMessages CAPWAP Messages + *@addtogroup CAPWAPConstants *@{ */ /** * CAPWAP message types as defined in RFC 5416 */ -typedef enum { +enum cw_message_types{ /**Discovery Request */ CW_MSG_DISCOVERY_REQUEST = 1, @@ -183,7 +183,9 @@ CW_STATION_CONFIGURATION_RESPONSE = 26, CW_MSG_MAXMSG = 26 -}cw_msg_t; +}; + +//cw_msg_t; /**@}*/ @@ -590,6 +592,7 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le #define cw_put_dword lw_put_dword #define cw_put_data lw_put_data #define cw_put_bstr lw_put_bstr +#define cw_put_bstr16 lw_put_bstr16 #define cw_set_dword lw_set_dword @@ -929,6 +932,9 @@ extern struct cw_str capwap_strings_state[]; extern struct cw_str capwap_strings_vendor[]; extern struct cw_str capwap_strings_elem[]; extern struct cw_str capwap_strings_result[]; +extern struct cw_str cw_item_strings[]; + + #define cw_strmsg(id) cw_strlist_get_str(capwap_strings_msg,id) @@ -937,6 +943,8 @@ extern struct cw_str capwap_strings_result[]; #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_stritem(id) cw_strlist_get_str(cw_item_strings,(id)) + /* #define cw_strrc(rc) \ ((rc)<0 ? ((rc)!=EAGAIN ? strerror(errno):"Timed out"): cw_strresult(rc)) diff --git a/src/capwap/capwap_80211.h b/src/capwap/capwap_80211.h index baa7e0c9..329089d2 100644 --- a/src/capwap/capwap_80211.h +++ b/src/capwap/capwap_80211.h @@ -13,10 +13,12 @@ #define CWMSG_80211_WLAN_CONFIGURATION_REQUEST 3398913 #define CWMSG_80211_WLAN_CONFIGURATION_REPONSE 3398914 - - -#define CW_ELEM80211_ADD_WLAN 1024 -#define CW_ELEM80211_ANTENNA 1025 +/** 802.11 Message Elements */ +enum radioelems { + /** Add WLAN Message element */ + CW_ELEM80211_ADD_WLAN =1024, + /** Antenna Message element */ + CW_ELEM80211_ANTENNA =1025, /* IEEE 802.11 Assigned WTP BSSID 1026 IEEE 802.11 Delete WLAN 1027 @@ -26,8 +28,10 @@ IEEE 802.11 MIC Countermeasures 1031 IEEE 802.11 Multi-Domain Capability 1032 IEEE 802.11 OFDM Control 1033 - IEEE 802.11 Rate Set 1034 - IEEE 802.11 RSNA Error Report From Station 1035 +*/ + /** Supported WLAN Rates */ + CW_ELEM80211_RATE_SET=1034, +/* IEEE 802.11 RSNA Error Report From Station 1035 IEEE 802.11 Station 1036 IEEE 802.11 Station QoS Profile 1037 IEEE 802.11 Station Session Key 1038 @@ -42,7 +46,9 @@ IEEE 802.11 WTP Radio Fail Alarm Indication 1047 */ -#define CW_ELEM80211_WTP_RADIO_INFORMATION 1048 + /** Radio Information Message Element */ + CW_ELEM80211_WTP_RADIO_INFORMATION=1048 +}; @@ -80,6 +86,7 @@ struct cw_wlan { +int cw_out_radio_infos(struct conn *conn, struct cw_action_out *a, uint8_t * dst); extern int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def); diff --git a/src/capwap/capwap_80211_actions_wtp.c b/src/capwap/capwap_80211_actions_wtp.c index e8e45352..57c97915 100644 --- a/src/capwap/capwap_80211_actions_wtp.c +++ b/src/capwap/capwap_80211_actions_wtp.c @@ -2,6 +2,7 @@ #include "action.h" #include "capwap_80211_actions.h" +#include "capwap_80211.h" #include "capwap.h" @@ -21,11 +22,20 @@ cw_action_in_t capwap_80211_actions_wtp_in[] = { }; +cw_action_out_t capwap_80211_actions_wtp_out[]={ + /* Session ID */ + {CW_MSG_JOIN_REQUEST, CW_ELEM80211_WTP_RADIO_INFORMATION, 0, + CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} + + +}; + + int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def) { cw_actionlist_in_register_actions(def->in, capwap_80211_actions_wtp_in); -// cw_actionlist_out_register_actions(def->out, capwap_actions_wtp_out); + cw_actionlist_out_register_actions(def->out, capwap_80211_actions_wtp_out); int rc; rc = cw_strheap_register_strings(def->strelem, capwap_strings_elem80211); diff --git a/src/capwap/capwap_action_helpers.c b/src/capwap/capwap_action_helpers.c index 244184ba..969f4fb6 100644 --- a/src/capwap/capwap_action_helpers.c +++ b/src/capwap/capwap_action_helpers.c @@ -41,7 +41,7 @@ struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * int slen; if ( conn->capwap_mode == CW_MODE_CISCO){ - slen=4; + slen=2; } else slen=16; diff --git a/src/capwap/capwap_actions_wtp.c b/src/capwap/capwap_actions_wtp.c index 487f86ce..7e490de7 100644 --- a/src/capwap/capwap_actions_wtp.c +++ b/src/capwap/capwap_actions_wtp.c @@ -91,6 +91,50 @@ cw_action_in_t capwap_actions_wtp_in[] = { + /* ------------------------------------------------------------------------------- */ + + /* Message Config Status Response IN */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_RESPONSE, 0, + 0,0 } + , + + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_RESPONSE, + CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD, 0} + , + + /* ------------------------------------------------------------------------------- */ + + /* Message Change State Response IN */ + {0, 0, CW_STATE_CONFIGURE, CW_MSG_CHANGE_STATE_EVENT_RESPONSE, 0, + 0,0 } + , + + + /* Message Change State Response IN */ + {0, 0, CW_STATE_RUN, CW_MSG_CONFIGURATION_UPDATE_REQUEST, + 0, 0,0 } + , + + /* Element: Vendor Specific */ + {0, 0, CW_STATE_RUN, CW_MSG_CONFIGURATION_UPDATE_REQUEST, + CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD, 0} + , + + + + /* Echo Response Response IN */ + {0, 0, CW_STATE_RUN, CW_MSG_ECHO_RESPONSE, 0, + 0,0 } + , + + /* Element: Vendor Specific */ + {0, 0, CW_STATE_RUN, CW_MSG_ECHO_RESPONSE, + CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD, 0} + , + + + + {0, 0, 0} }; @@ -202,11 +246,33 @@ cw_action_out_t capwap_actions_wtp_out[] = { */ {CW_MSG_CONFIGURATION_STATUS_REQUEST, CW_ITEM_NONE} , + /* AC Name */ + {CW_MSG_CONFIGURATION_STATUS_REQUEST, CW_ITEM_AC_NAME, 0, + CW_ELEM_AC_NAME, NULL, cw_out_generic, cw_out_get_local,1} + , + /* ------------------------------------------------------------------------------- + * Configuration Status Request OUT + */ + {CW_MSG_CHANGE_STATE_EVENT_REQUEST, CW_ITEM_NONE} + , + + /* ------------------------------------------------------------------------------- + * Echo Request Request OUT + */ + {CW_MSG_ECHO_REQUEST, CW_ITEM_NONE} + , + + /* ------------------------------------------------------------------------------- + * Echo Request Request OUT + */ + {CW_MSG_CONFIGURATION_UPDATE_RESPONSE, CW_ITEM_NONE} + , + {0, 0} }; diff --git a/src/capwap/capwap_cisco.h b/src/capwap/capwap_cisco.h index 599463c6..2f54cd41 100644 --- a/src/capwap/capwap_cisco.h +++ b/src/capwap/capwap_cisco.h @@ -63,6 +63,7 @@ #define CW_CISCO_AP_STATIC_IP_ADDR 83 #define CW_CISCO_AC_NAME_WITH_INDEX 91 +#define CW_CISCO_SPAM_DOMAIN_SECRET 96 #define CW_CISCO_SPAM_VENDOR_SPECIFIC 104 @@ -203,6 +204,8 @@ int cw_in_check_cipwap_join_req(struct conn *conn, struct cw_action_in *a, uint8 +int cw_out_cisco_wtp_radio_cfg(struct conn *conn, struct cw_action_out *a, uint8_t * dst); + /* #define cw_addelem_cisco_rad(dst,acinfo)\ @@ -213,6 +216,8 @@ int cw_in_check_cipwap_join_req(struct conn *conn, struct cw_action_in *a, uint8 /* cwmsg methods */ + +/* #define cwmsg_addelem_cisco_ap_timesync(cwmsg,time,type)\ (cwmsg)->pos+=cw_addelem_cisco_ap_timesync(((cwmsg)->msgelems+(cwmsg)->pos),time,type) @@ -234,5 +239,7 @@ int cw_in_check_cipwap_join_req(struct conn *conn, struct cw_action_in *a, uint8 #define cwmsg_addelem_cisco_wtp_radio_cfg(cwmsg,radioinfo)\ (cwmsg)->pos+=cw_addelem_cisco_wtp_radio_cfg(((cwmsg)->msgelems+(cwmsg)->pos),radioinfo) +*/ + #endif diff --git a/src/capwap/capwap_items.h b/src/capwap/capwap_items.h index ed722528..35140a8f 100644 --- a/src/capwap/capwap_items.h +++ b/src/capwap/capwap_items.h @@ -56,7 +56,11 @@ enum capwap_items { CW_ITEM_IMAGE_FILENAME, /* Full path of image filename */ CW_ITEM_DISCOVERIES, CW_ITEM_AC_PRIO_LIST, /* AC Name with Priority list */ - CW_ITEM_IMAGE_FILEHANDLE /* FILE handle for uploading and downloading images */ + + /** FILE handle for uploading and downloading images */ + CW_ITEM_IMAGE_FILEHANDLE, + + CW_ITEM_RADIO_CFG }; diff --git a/src/capwap/capwap_strings_elem.c b/src/capwap/capwap_strings_elem.c index 328504e4..163f24f1 100644 --- a/src/capwap/capwap_strings_elem.c +++ b/src/capwap/capwap_strings_elem.c @@ -21,7 +21,7 @@ struct cw_str capwap_strings_elem[] = { {CW_ELEM_DATA_TRANSFER_DATA, "Data Transfer Data"}, {CW_ELEM_DATA_TRANSFER_MODE, "Data Transfer Mode"}, {CW_ELEM_DECRYPTION_ERROR_REPORT, "Encryption Error Report"}, - {CW_ELEM_DECRYPTION_ERROR_REPORT_PERIOD, "Encryption Error Report Period"}, + {CW_ELEM_DECRYPTION_ERROR_REPORT_PERIOD, "Decryption Error Report Period"}, {CW_ELEM_DELETE_MAC_ACL_ENTRY, "Delete MAC ACL Entry"}, {CW_ELEM_DELETE_STATION, "Delete Station"}, {CW_ELEM_RESERVED_19, "Reserved 19"}, diff --git a/src/capwap/capwap_strings_elem80211.c b/src/capwap/capwap_strings_elem80211.c index dd72f44c..c81cea1b 100644 --- a/src/capwap/capwap_strings_elem80211.c +++ b/src/capwap/capwap_strings_elem80211.c @@ -3,9 +3,10 @@ struct cw_str capwap_strings_elem80211[] = { - {CW_ELEM80211_WTP_RADIO_INFORMATION, "802.11 WTP Radio Information"}, - {CW_STR_STOP,"Unknown"} - + {CW_ELEM80211_ADD_WLAN, "802.11 Add WLAN"}, + {CW_ELEM80211_ANTENNA, "802.11 Antenna"}, + {CW_ELEM80211_RATE_SET, " 802.11 Rate Set"}, + {CW_ELEM80211_WTP_RADIO_INFORMATION, " 802.11 WTP Radio Information"}, + {CW_STR_STOP, " Unknown "} }; - diff --git a/src/capwap/cipwap_actions_ac.c b/src/capwap/cipwap_actions_ac.c index b1c3a6d4..8a4bb5bc 100644 --- a/src/capwap/cipwap_actions_ac.c +++ b/src/capwap/cipwap_actions_ac.c @@ -30,7 +30,7 @@ cw_in_generic, 0, /* start/end callback */ \ CW_ITEMTYPE_BSTR, /* Type of element */ \ CW_ITEM_SESSION_ID, /* ID to use store */ \ - 4, 16 /* min/max length */ + 2, 16 /* min/max length */ #define CW_ACTION_IN_CIPWAP_AC_NAME \ CW_ELEM_AC_NAME, /* Element ID*/ \ diff --git a/src/capwap/cipwap_strings_elem.c b/src/capwap/cipwap_strings_elem.c index 370b0d1b..714a3da1 100644 --- a/src/capwap/cipwap_strings_elem.c +++ b/src/capwap/cipwap_strings_elem.c @@ -1,12 +1,16 @@ #include "capwap.h" #include "cipwap.h" +#include "capwap_cisco.h" struct cw_str cipwap_strings_elem[] = { {CW_ELEM_WTP_IPV4_IP_ADDRESS, "WTP IPv4 IP Address"}, {CW_ELEM_WTP_IPV6_IP_ADDRESS, "WTP IPv6 IP Address"}, + + {CW_CISCO_AP_GROUP_NAME, "WTP Group Name" }, + {0,"Unknown Element"} }; diff --git a/src/capwap/conn.h b/src/capwap/conn.h index 01a102cd..fa9ca508 100644 --- a/src/capwap/conn.h +++ b/src/capwap/conn.h @@ -40,6 +40,8 @@ #include "itemstore.h" #include "intavltree.h" +#include "mbag.h" + /** * Connection Object */ @@ -53,6 +55,8 @@ struct conn { cw_itemstore_t remote; cw_itemstore_t local; + mbag_t radios; + /** base_mac */ bstr_t base_rmac; diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index 2538e5f3..93a6dce5 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -444,9 +444,12 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sock /* fragmented, add the packet to fragman */ uint8_t *f; f = fragman_add(conn->fragman, packet, offs, payloadlen); - if (f == NULL) - return 0; + if (f == NULL){ + errno=EAGAIN; + return -1; + } + cw_dbg_pkt(DBG_PKT_IN, conn, f+4, *(uint32_t*)f,from); cw_dbg_msg(DBG_MSG_IN, conn, f+4, *(uint32_t*)f,from); int rc = process_message(conn, f + 4, *(uint32_t *) f, from); diff --git a/src/capwap/cw_cisco_id_to_str.c b/src/capwap/cw_cisco_id_to_str.c index 50c0555d..e9b89315 100644 --- a/src/capwap/cw_cisco_id_to_str.c +++ b/src/capwap/cw_cisco_id_to_str.c @@ -105,6 +105,8 @@ const char * cw_cisco_id_to_str(int elem_id) return "Antenna Payload"; case CW_CISCO_SUPPORTED_RATES: return "Supported Rates"; + case CW_CISCO_SPAM_DOMAIN_SECRET: + return "SPAM Domain Secret"; default: diff --git a/src/capwap/cw_in_check_img_data_req_ac.c b/src/capwap/cw_in_check_img_data_req_ac.c index 9dffd3eb..7c3e09b4 100644 --- a/src/capwap/cw_in_check_img_data_req_ac.c +++ b/src/capwap/cw_in_check_img_data_req_ac.c @@ -25,9 +25,7 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8 uint32_t vendor_id = vendorstr_get_vendor_id(i->data); const char * image_dir; - image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR); - if ( !image_dir ) - image_dir="./img/"; //XXX + image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img"); char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir)); if (!image_filename) diff --git a/src/capwap/cw_in_check_img_data_req_wtp.c b/src/capwap/cw_in_check_img_data_req_wtp.c index 684a1c4e..39784e32 100644 --- a/src/capwap/cw_in_check_img_data_req_wtp.c +++ b/src/capwap/cw_in_check_img_data_req_wtp.c @@ -36,9 +36,7 @@ int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint uint32_t vendor_id = vendorstr_get_vendor_id(i->data); const char * image_dir; - image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR); - if ( !image_dir ) - image_dir="./img/"; //XXX + image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR,"./img"); char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir)); if (!image_filename) diff --git a/src/capwap/cw_out_generic.c b/src/capwap/cw_out_generic.c index 3355ccd1..15da59da 100644 --- a/src/capwap/cw_out_generic.c +++ b/src/capwap/cw_out_generic.c @@ -21,6 +21,8 @@ int cw_put_item(uint8_t * dst, struct cw_item *item) return cw_put_dword(dst, item->dword); case CW_ITEMTYPE_BSTR: return cw_put_bstr(dst, item->data); + case CW_ITEMTYPE_BSTR16: + return cw_put_bstr16(dst,item->data); case CW_ITEMTYPE_VENDORSTR: { int l=0; @@ -54,15 +56,21 @@ int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // int len; if (!item) { + const char *vendor=""; + if ( a->vendor_id ) { + vendor=cw_strvendor(a->vendor_id); + } if (a->mand) { cw_log(LOG_ERR, - "Can't put mandatory element %d - (%s) into %s. No value found.", + "Can't put mandatory element %s%d - (%s) into %s. No value found.", + vendor, a->elem_id, cw_strelemp(conn->actions, a->elem_id) , cw_strmsg(a->msg_id) ); } else{ - cw_dbg(DBG_WARN,"No output for element %d -(%s) in %s. Item %d not found.", + cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %d not found.", + vendor, a->elem_id, cw_strelemp(conn->actions, a->elem_id) , cw_strmsg(a->msg_id),a->item_id); diff --git a/src/capwap/cw_out_wtp_descriptor.c b/src/capwap/cw_out_wtp_descriptor.c index c3cbe40d..f55ccb4a 100644 --- a/src/capwap/cw_out_wtp_descriptor.c +++ b/src/capwap/cw_out_wtp_descriptor.c @@ -32,16 +32,24 @@ int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * uint8_t *d = dst+4; d+=cw_put_byte(d,2); //max radios - d+=cw_put_byte(d,0); //radios in use + d+=cw_put_byte(d,2); //radios in use d+=cw_put_encryption_subelems(d); cw_item_t * i; - i = cw_itemstore_get(conn->outgoing,CW_ITEM_WTP_HARDWARE_VERSION); + i = cw_itemstore_get(conn->local,CW_ITEM_WTP_HARDWARE_VERSION); if ( i ) { d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->data); } else { - cw_log(LOG_ERR, "Can't send hard version in WTP descriptor, not set."); + cw_log(LOG_ERR, "Can't send Hardware Version in WTP Descriptor, not set."); + } + + i = cw_itemstore_get(conn->local,CW_ITEM_WTP_SOFTWARE_VERSION); + if ( i ) { + d += cw_put_version(d,CW_SUBELEM_WTP_SOFTWARE_VERSION,i->data); + } + else { + cw_log(LOG_ERR, "Can't send Software Version in WTP descriptor, not set."); } diff --git a/src/capwap/dbg.c b/src/capwap/dbg.c index 7cbf133f..95bdae89 100644 --- a/src/capwap/dbg.c +++ b/src/capwap/dbg.c @@ -495,5 +495,45 @@ void cw_dbg_colored(int level, const char *file, int line, const char *format, . } +int cw_is_utf8(unsigned char *str, size_t len); + + +int cw_format_item(char *dst,cw_item_t * item) +{ + *dst=0; + switch (item->type) { + case CW_ITEMTYPE_BSTR16: + strncpy(dst,bstr16_data(item->data),bstr16_len(item->data)); + *(dst+bstr16_len(item->data))=0; + return bstr16_len(item->data); + + + } +} + +void dbg_istore_dmp(cw_itemstore_t s) +{ + DEFINE_AVLITER(it,s); + avliter_foreach(&it) { + + cw_item_t *i = avliter_get(&it); + + char buffer[1000]; + + struct cw_str * strings = cw_item_strings; + + const char * in = cw_strlist_get_str(strings,i->id); + + cw_format_item(buffer,i); + printf("Item ID %d-%s: %s\n",i->id,in,buffer); + + + } + + +} + + + /**@}*/ diff --git a/src/capwap/itemstore.h b/src/capwap/itemstore.h index 4da6d719..78bdf83d 100644 --- a/src/capwap/itemstore.h +++ b/src/capwap/itemstore.h @@ -88,15 +88,17 @@ int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int extern int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t * data, int len); -static inline char *cw_itemstore_get_str(cw_itemstore_t s, uint32_t id) +static inline char *cw_itemstore_get_str(cw_itemstore_t s, uint32_t id, char *def) { struct cw_item *i = cw_itemstore_get(s, id); if (!i) - return NULL; + return def; return i->data; }; + + static inline struct avltree *cw_itemstore_get_avltree(cw_itemstore_t s, uint32_t id) { struct cw_item *i = cw_itemstore_get(s, id); @@ -139,5 +141,34 @@ int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, struct cw_item *cw_item_create(cw_itemstore_t s, uint32_t id); +static inline void * cw_istore_get_data(cw_itemstore_t s,int id,void *def) +{ + struct cw_item *i = cw_itemstore_get(s, id); + if (!i) + return def; + return i->data; +} + + + +static inline uint8_t cw_istore_get_byte(cw_itemstore_t s, uint32_t id, uint8_t def) +{ + struct cw_item *i = cw_itemstore_get(s, id); + if (!i) + return def; + return i->byte; +} + +static inline uint16_t cw_istore_get_word(cw_itemstore_t s, uint32_t id, uint8_t def) +{ + struct cw_item *i = cw_itemstore_get(s, id); + if (!i) + return def; + return i->word; +} + +#define cw_istore_get_bstr(s,id,def) cw_istore_get_data(s,id,def) + + #endif diff --git a/src/capwap/lwapp.h b/src/capwap/lwapp.h index d7e1ecf7..a9933b8c 100644 --- a/src/capwap/lwapp.h +++ b/src/capwap/lwapp.h @@ -226,6 +226,13 @@ static inline int lw_put_bstr(uint8_t * dst, const bstr_t b){ return bstr_len(b); } +static inline int lw_put_bstr16(uint8_t * dst, const bstr16_t b){ + lw_put_data(dst,bstr16_data(b),bstr16_len(b)); + return bstr16_len(b); +} + + + static inline int lw_put_str(uint8_t*dst,const uint8_t *str) { return lw_put_data(dst,str,strlen((char*)str)); } diff --git a/src/capwap/mavl.h b/src/capwap/mavl.h index 1d67a6f9..212b84ab 100644 --- a/src/capwap/mavl.h +++ b/src/capwap/mavl.h @@ -21,8 +21,15 @@ * @brief Yet another avl tree implementation! */ -#ifndef __AVLTREE_H -#define __AVLTREE_H + +/** + * @defgroup MavlFunctions MAVL Functions + * @{ + */ + + +#ifndef __MAVL_H +#define __MAVL_H #include #include @@ -34,7 +41,7 @@ The number of nodes is calculated by 2^depth. So a value of 32 should be enough for around 4 billion nodes. */ -#define AVLTREE_MAX_DEPTH 32 +#define MAVL_MAX_DEPTH 32 /** * Defines the structure of an AVL Node. @@ -50,12 +57,19 @@ struct mavlnode { * AVL Tree */ struct mavl { + /** Pointer to root node */ struct mavlnode *root; + /** Compare function */ int (*cmp) (const void *, const void *); + /** Delete element function */ void (*del) (void *); + /** Number of elements currently stored in the tree */ int count; }; +/** + * MAVL AVL Tree type + */ typedef struct mavl * mavl_t; @@ -64,6 +78,7 @@ typedef struct mavl * mavl_t; struct mavl *mavl_create(int (*cmp) (const void *, const void *), void (*del) (void *)); //void mavl_destroy(struct mavl *t); +void mavlnode_destroy(struct mavl *t, struct mavlnode *n); void mavl_del_all(struct mavl *t); void *mavl_del(struct mavl *t, void *data); @@ -120,7 +135,7 @@ static inline void mavl_destroy(struct mavl *t) struct mavliter{ - struct mavlnode *stack[AVLTREE_MAX_DEPTH*2]; + struct mavlnode *stack[MAVL_MAX_DEPTH*2]; struct mavlnode *cur; int stack_ptr; @@ -171,11 +186,17 @@ static inline void * mavliter_get(mavliter_t *i){ extern void * mavliter_seek(mavliter_t *i,void *d); - -#define DEFINE_MAVLITER(i,t)\ +/** + * Define a AVL Iterator Varialble and acciciate it with + * an AVL Tree. + * @param i Name of Variable to define + * @param t #mavl_t Tree to associate. + */ +#define MAVLITER_DEFINE(i,t)\ mavliter_t i; mavliter_init(&i,t) + #define mavliter_foreach(i)\ for (mavliter_seek_set(i); NULL != mavliter_get(i); mavliter_next(i)) @@ -186,6 +207,7 @@ extern void * mavliter_seek(mavliter_t *i,void *d); while(NULL != (val = mavliter_next(iter))) +/** @} */ #endif diff --git a/src/capwap/mavl_del.c b/src/capwap/mavl_del.c index 8c38482e..9a35b752 100644 --- a/src/capwap/mavl_del.c +++ b/src/capwap/mavl_del.c @@ -1,6 +1,6 @@ #include "mavl.h" -static void mavlnode_destroy(struct mavl *t, struct mavlnode *n) +void mavlnode_destroy(struct mavl *t, struct mavlnode *n) { if (t->del) { t->del(n->data); diff --git a/src/capwap/mavl_get.c b/src/capwap/mavl_get.c index de0f82f3..fe88d672 100644 --- a/src/capwap/mavl_get.c +++ b/src/capwap/mavl_get.c @@ -31,7 +31,7 @@ */ void * mavl_get(struct mavl *t ,void *data) { - struct avlnode *n = t->root; + struct mavlnode *n = t->root; while(n){ int rc=t->cmp(data,n->data); if (rc==0) diff --git a/src/capwap/timer.h b/src/capwap/timer.h index aefffa3c..3e1ed7e7 100644 --- a/src/capwap/timer.h +++ b/src/capwap/timer.h @@ -28,6 +28,12 @@ * @{ */ +/** + * CAPWAP timer type, used in #cw_timer_start and #cw_timer_timeout. + */ +typedef time_t cw_timer_t; + + /** * Start a timer. * @param t number of seconds until the timer expires @@ -55,7 +61,7 @@ * * @param c name of the variable */ -#define DEFINE_CLOCK(c)\ +#define CLOCK_DEFINE(c)\ struct timeval c; /** diff --git a/src/wtp/Makefile b/src/wtp/Makefile index ff6e77ae..4abc2374 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -95,6 +95,7 @@ OBJS += join.o OBJS += run.o OBJS += sulking.o OBJS += configure.o +OBJS += changestate.o OBJS += $(CONFOBJS) diff --git a/src/wtp/cfg.c b/src/wtp/cfg.c index 616a8e05..c3edfaa8 100644 --- a/src/wtp/cfg.c +++ b/src/wtp/cfg.c @@ -9,6 +9,7 @@ #include "jsmn.h" #include "wtp.h" #include "capwap/bstr.h" +#include "capwap/radio.h" struct cw_itemdef { int item_id; @@ -95,6 +96,41 @@ printf("GET BYTE\n"); } +int vendorstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t) +{ + int item_id = idef->item_id; + struct conn * conn = get_conn(); + + *(js+t->end)=0; + char *str = js+t->start; + if (t->type != JSMN_ARRAY || t->type!=2){ + printf("Error: No ARRAY or to short: %s\n",str); + exit(1); + + } +// *(js+t->end)=0; + + char * val = js+(t+1)->start; + *(js+(t+1)->end)=0; + printf("Val: %s\n",val); + + uint32_t vendor_id = atoi(val); + + str = (uint8_t*)js+(t+2)->start; + + *((t+2)->end+js)=0; + bstr16_t v = bstr16cfgstr(str); + +printf("Vendor: %d %s\n",vendor_id,str); + + cw_itemstore_set_vendorstr(conn->local,item_id,vendor_id,bstr16_data(v),bstr16_len(v)); + free(v); + + + + return 0; +} + @@ -116,6 +152,31 @@ int bstr16_local(struct cw_itemdef *idef,char *js, jsmntok_t *t) return 0; } +int bstr_local(struct cw_itemdef *idef,char *js, jsmntok_t *t) +{ + int item_id = idef->item_id; + struct conn * conn = get_conn(); + + *(js+t->end)=0; + char *str = js+t->start; + if (t->type != JSMN_STRING){ + printf("Error: No Str: %s\n",str); + return 1; + + } +// *(js+t->end)=0; + printf("Set str: %d %s\n", item_id,str); + + bstr16_t v = bstr16cfgstr(str); + + cw_itemstore_set_bstrn(conn->local,item_id,bstr16_data(v),bstr16_len(v)); //(uint8_t*)js+t->start,t->end-t->start); + free (v); + return 0; +} + + + + int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t); @@ -123,13 +184,17 @@ int wtp_board_data_local(struct cw_itemdef *idef,char *js, jsmntok_t *t); struct cw_itemdef general_cfg[] = { - {CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",bstr16_local}, - {CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",bstr16_local}, + {CW_ITEM_AC_NAME, "ac_name",bstr16_local}, + {CW_ITEM_WTP_NAME, "wtp_name",bstr16_local}, + {CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",vendorstr_local}, + {CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",vendorstr_local}, {CW_ITEM_WTP_BOARD_MODELNO, "modelno",bstr16_local}, {CW_ITEM_WTP_BOARD_DATA,"wtp_board_data",wtp_board_data_local}, {CW_ITEM_WTP_FRAME_TUNNEL_MODE,"frame_tunnel_mode",byte_local}, {CW_ITEM_WTP_MAC_TYPE,"mac_type",byte_local}, {CW_ITEM_LOCATION_DATA,"location_data",bstr16_local}, + {CW_ITEM_WTP_GROUP_NAME,"group_name",bstr16_local}, + {CW_RADIO_BSSID,"bssid",bstr_local}, {0, 0, 0} }; @@ -289,8 +354,9 @@ int setup_conf(struct conn *conn) +void dbg_istore_dmp(cw_itemstore_t s); - +dbg_istore_dmp(conn->local); diff --git a/src/wtp/cfg.json b/src/wtp/cfg.json index 2e68e2f5..0440a097 100644 --- a/src/wtp/cfg.json +++ b/src/wtp/cfg.json @@ -2,22 +2,27 @@ "dbg":[o1,o2,o3], - "Tube" : "tabbe", - "hardware_version": "12345", - "software_version": "98765", + "hardware_version": ["4232704",".x01000000"], + "software_version": ["4232704",".x08006E00"], + "comment": "** The following is debug info **", - "location_data": "Berlin", + "location_data": "China", "frame_tunnel_mode": "4", "mac_type": 2, - + "group_name" : "XGroup", + + "wtp_name" : "TubeWTP", + "ac_name" : "LAC_AC", + + "bssid": ".x003a9902fac0", "wtp_board_data" : { - "vendor_id": 4232704, - "model_no": "Moodle", - "serial_no": "2045", + "vendor_id": "4232704", + "model_no": "AIR-LAP1131AG-E-K9", + "serial_no": "2045" }, @@ -36,6 +41,12 @@ } } + "radios": { + "1": { + "domain" + + } + } } diff --git a/src/wtp/configure.c b/src/wtp/configure.c index 015dbe0a..fc04d2bc 100644 --- a/src/wtp/configure.c +++ b/src/wtp/configure.c @@ -1,4 +1,3 @@ -#include //Tube #include "capwap/capwap.h" #include "capwap/conn.h" diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 511a3c5a..4f6c14eb 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -64,7 +64,7 @@ cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis) avliter_foreach(&i){ cw_itemstore_t ac = ((cw_item_t *) (avliter_get(&i)))->data; - char *ac_name = cw_itemstore_get_str(ac, CW_ITEM_AC_NAME); + char *ac_name = cw_itemstore_get_str(ac, CW_ITEM_AC_NAME,NULL); int prio = 256; if (ac_name) { diff --git a/src/wtp/run.c b/src/wtp/run.c index ad6280a1..135b9965 100644 --- a/src/wtp/run.c +++ b/src/wtp/run.c @@ -14,6 +14,80 @@ #include "wtp_conf.h" + +#include "capwap/timer.h" + + + +#include "capwap/capwap.h" +#include "capwap/conn.h" +#include "wtp_interface.h" + + +int run() +{ + + + + struct conn *conn = get_conn(); + conn->capwap_state = CW_STATE_RUN; + + do { + time_t timer = cw_timer_start(25); + int rc; + + + + + while (!cw_timer_timeout(timer) && conn->capwap_state == CW_STATE_RUN) { + rc = cw_read_messages(conn); + if (rc < 0 && errno == EAGAIN) { + continue; + } + + if ( !cw_rcok(rc)) + break; + + } + if (rc<0 && errno == EAGAIN){ + rc = cw_send_request(conn,CW_MSG_ECHO_REQUEST); + + if (!cw_rcok(rc)) { + cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc)); + break; + } + continue; + } + + if (!cw_rcok(rc)) { + cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc)); + break; + } + + + + + } while (conn->capwap_state == CW_STATE_RUN); + + + +// int rc = cw_send_request(conn,CW_MSG_CHANGE_STATE_EVENT_REQUEST); + +// if ( !cw_rcok(rc) ) { +// cw_strresult(rc); +// } + + +} + + + + + + + + + /* static int echo_interval_timer; diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index a926dbf4..8dd4c0ca 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -10,6 +10,8 @@ #include "capwap/log.h" #include "capwap/dtls.h" #include "capwap/acpriolist.h" +#include "capwap/capwap_80211.h" +#include "capwap/radio.h" #include "wtp.h" #include "wtp_conf.h" @@ -63,8 +65,26 @@ int main() the_conn = conn_create_noq(-1, NULL); struct conn *conn = the_conn; + conn->radios = mbag_create(); + mbag_set_mbag(conn->radios,0,mbag_create()); + mbag_set_mbag(conn->radios,1,mbag_create()); +// mbag_set_mbag(conn->radios,0xff,mbag_create()); + + + mbag_t r; + r = mbag_get_mbag(conn->radios,0,NULL); + mbag_set_dword(r,CW_RADIO_TYPE,1); + r = mbag_get_mbag(conn->radios,1,NULL); + mbag_set_dword(r,CW_RADIO_TYPE,2); +// r = mbag_get_mbag(conn->radios,1,NULL); +// mbag_set_dword(r,CW_RADIO_TYPE,1); + + + cw_register_actions_cipwap_wtp(&capwap_actions); + cw_register_actions_capwap_80211_wtp(&capwap_actions); + ////cw_register_actions_capwap_80211_wtp(&capwap_actions); conn->actions = &capwap_actions; @@ -101,7 +121,7 @@ int main() cw_itemstore_set_avltree(conn->local,CW_ITEM_AC_PRIO_LIST,acprios); cw_itemstore_set_str(conn->local,CW_ITEM_LOCATION_DATA,"Berlin"); - cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube"); +// cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube"); cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_MAC_TYPE,0); cw_itemstore_set_byte(conn->local,CW_ITEM_WTP_FRAME_TUNNEL_MODE,0); @@ -111,6 +131,9 @@ int main() discovery(); join(); configure(); + changestate(); + run(); + //image_update();