From 9d3e24df52d4497d993d6be8e33f7f445d0854d3 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 4 May 2018 22:36:19 +0000 Subject: [PATCH] Work on State machine FossilOrigin-Name: 87d98b73010c7316cb9b53b5ba8c3dfdddca06042630cf8437ea506e1c424c70 --- actube.workspace | 4 +- libcw.project | 1 + src/ac/config.ktv | 5 + src/ac/wtpman.c | 227 +++++++++++------- src/cw/capwap.h | 15 +- src/cw/capwap_strings_state.c | 4 +- src/cw/conn.h | 2 +- src/cw/conn_process_packet.c | 32 ++- src/cw/cw.h | 3 + src/cw/cw_strtransition.c | 8 + src/cw/msgset.c | 6 +- src/cw/msgset.h | 6 +- src/mod/capwap/capwap_actions_ac.c | 105 ++++---- src/mod/capwap/capwap_actions_wtp.c | 20 +- .../capwap_in_vendor_specific_payload.c | 2 +- src/mod/capwap80211/capwap80211_messages.c | 39 +-- src/mod/cisco/cisco_actions_ac.c | 36 +-- src/mod/cisco/cisco_actions_wtp.c | 10 +- src/mod/cisco/cisco_in_spam_vendor_specific.c | 2 +- src/mod/fortinet/fortinet_actions_ac.c | 2 +- src/wtp/changestate.c | 1 - src/wtp/discovery.c | 4 +- src/wtp/image_update.c | 2 +- src/wtp/join.c | 2 +- src/wtp/run.c | 6 +- 25 files changed, 317 insertions(+), 227 deletions(-) create mode 100644 src/cw/cw_strtransition.c diff --git a/actube.workspace b/actube.workspace index b21adfd1..b8870938 100644 --- a/actube.workspace +++ b/actube.workspace @@ -1,9 +1,9 @@ - + - + diff --git a/libcw.project b/libcw.project index bf6d41d6..55f0cd00 100644 --- a/libcw.project +++ b/libcw.project @@ -295,6 +295,7 @@ + diff --git a/src/ac/config.ktv b/src/ac/config.ktv index 9c8a4cdc..2a24996b 100644 --- a/src/ac/config.ktv +++ b/src/ac/config.ktv @@ -69,3 +69,8 @@ psk/ap1:Bstr16:hallo actube/listen:Bstr16:192.168.0.1 + +wait-dtls:Word:12 +wait-join:Word:3 + +capwap-timers/change-state-pending-timer: Word: 3 diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index 66918f18..3ec00ad3 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -90,15 +90,15 @@ static void wtpman_run_discovery(void *arg) time_t timer = cw_timer_start(10); - wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY; + wtpman->conn->capwap_transition = CAPWAP_STATE_DISCOVERY; while (!cw_timer_timeout(timer) - && wtpman->conn->capwap_state == CAPWAP_STATE_DISCOVERY) { + && wtpman->conn->capwap_transition == CAPWAP_STATE_DISCOVERY) { int rc; rc = cw_read_messages(wtpman->conn); if (cw_result_is_ok(rc)){ - wtpman->conn->capwap_state=CAPWAP_STATE_JOIN; + wtpman->conn->capwap_transition=CAPWAP_STATE_JOIN; cw_dbg(DBG_INFO,"Discovery has detected mods: %s %s", wtpman->conn->cmod->name,wtpman->conn->bmod->name); @@ -131,44 +131,13 @@ int xprocess_message(struct conn *conn, uint8_t * rawmsg, int rawlen, */ -static int wtpman_establish_dtls(void *arg) +static int wtpman_dtls_setup(void *arg) { char cipherstr[512]; - int dtls_ok; + char sock_buf[SOCK_ADDR_BUFSIZE]; struct wtpman *wtpman = (struct wtpman *) arg; - - /* setup cipher */ -/* wtpman->conn->dtls_cipher = conf_sslcipher;*/ - - /* setup DTSL certificates */ -/* dtls_ok = 0; - if (conf_sslkeyfilename && conf_sslcertfilename) { - - - wtpman->conn->dtls_key_file = conf_sslkeyfilename; - wtpman->conn->dtls_cert_file = conf_sslcertfilename; - wtpman->conn->dtls_key_pass = conf_sslkeypass; - wtpman->conn->dtls_verify_peer = conf_dtls_verify_peer; - cw_dbg(DBG_DTLS, "Using key file %s", wtpman->conn->dtls_key_file); - cw_dbg(DBG_DTLS, "Using cert file %s", wtpman->conn->dtls_cert_file); - dtls_ok = 1; - } -*/ - /* setup DTLS psk */ -/* if (conf_dtls_psk) { - wtpman->conn->dtls_psk = conf_dtls_psk; - wtpman->conn->dtls_psk_len = strlen(conf_dtls_psk); - dtls_ok = 1; - } - - if (!dtls_ok) { - cw_log(LOG_ERR, - "Can't establish DTLS session, neither psk nor certs set in config file."); - return 0; - } -*/ /* try to accept the connection */ if (!dtls_accept(wtpman->conn)) { cw_dbg(DBG_DTLS, "Error establishing DTLS session with %s", @@ -182,35 +151,22 @@ static int wtpman_establish_dtls(void *arg) return 1; } -static int wtpman_join(void *arg, time_t timer) +static int wtpman_join(void *arg) { int rc; char sock_buf[SOCK_ADDR_BUFSIZE]; struct wtpman *wtpman = (struct wtpman *) arg; struct conn *conn = wtpman->conn; - -/* -// wtpman->conn->outgoing = mbag_create(); -// wtpman->conn->incomming = mbag_create(); -// conn->config = conn->incomming; -// wtpman->conn->local = ac_config; - -// mbag_set_str(conn->local, CW_ITEM_AC_NAME, conf_acname); - -*/ - - wtpman->conn->capwap_state = CAPWAP_STATE_JOIN; - -/* -// wtpman->conn->actions = &capwap_actions; - -// wtpman->conn->itemstore = mbag_create(); -*/ + time_t timer, wait_join; cw_dbg(DBG_INFO, "Join State - %s", sock_addr2str(&conn->addr,sock_buf)); - - while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CAPWAP_STATE_JOIN) { + wait_join = cw_ktv_get_word(conn->global_cfg,"wait-join",CAPWAP_WAIT_JOIN); + + timer = cw_timer_start(wait_join); + + + while (!cw_timer_timeout(timer) && wtpman->conn->capwap_transition == CAPWAP_STATE_JOIN) { rc = cw_read_messages(wtpman->conn); if (rc < 0) { if (errno == EAGAIN) @@ -218,19 +174,20 @@ static int wtpman_join(void *arg, time_t timer) break; } -cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,"-------------dump------------","DMP","---------end dump --------"); + cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO, + "-------------dump------------", + "DMP","---------end dump --------"); } if (rc != 0) { cw_log(LOG_ERR, "Error joining WTP %s", cw_strerror(rc)); return 0; - } - if (wtpman->conn->capwap_state == CAPWAP_STATE_JOIN) { + if (wtpman->conn->capwap_transition != CAPWAP_STATE_JOIN_COMPLETE) { cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.", - sock_addr2str(&wtpman->conn->addr,sock_buf), wtpman->conn->wait_dtls); + sock_addr2str(&wtpman->conn->addr,sock_buf), wait_join); return 0; } @@ -323,15 +280,16 @@ void * wtpman_run_data(void *wtpman_arg) } +/*#define CW_TRANSITION(prestate,state) (prestate<<16|state)*/ - -static void * wtpman_run(void *arg) +static void * wtpman_main(void *arg) { mavl_t r; int rc ; time_t timer; char sock_buf[SOCK_ADDR_BUFSIZE]; struct conn *conn; + int last_state; struct wtpman *wtpman = (struct wtpman *) arg; @@ -339,6 +297,7 @@ static void * wtpman_run(void *arg) conn = wtpman->conn; wtpman->conn->remote_cfg = cw_ktv_create(); + /* We were invoked with an unencrypted packet, * so assume, it is a discovery request */ @@ -352,26 +311,124 @@ static void * wtpman_run(void *arg) /* reject connections to our multi- or broadcast sockets */ if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) { cw_dbg(DBG_DTLS,"Reject multi"); -/* cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.", - CLIENT_IP); -*/ wtpman_remove(wtpman); - - return NULL; - } - - - timer = cw_timer_start(wtpman->conn->wait_dtls); - - - /* establish dtls session */ - if (!wtpman_establish_dtls(wtpman)) { wtpman_remove(wtpman); return NULL; } + + conn->capwap_transition = CAPWAP_STATE_DTLS_SETUP; + /* establish dtls session */ + if (!wtpman_dtls_setup(wtpman)) { + wtpman_remove(wtpman); + return NULL; + } + + /*last_state = conn->capwap_state; + conn->capwap_state = CAPWAP_STATE_JOIN; +*/ + conn->capwap_transition = CW_TRANSITION(CAPWAP_STATE_DTLS_SETUP, CAPWAP_STATE_JOIN); + rc = 0; + + while (1){ + + int wait_join; + int wait_change_state; + + + + switch (conn->capwap_transition){ + case CW_TRANSITION(CAPWAP_STATE_DTLS_SETUP, CAPWAP_STATE_JOIN): + { + + wait_join = cw_ktv_get_word(conn->global_cfg,"wait-join",CAPWAP_WAIT_JOIN); + timer = cw_timer_start(wait_join); + break; + } + case CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_JOIN): + { + char wtpname[CAPWAP_MAX_WTP_NAME_LEN]; + cw_KTV_t * result; + result = cw_ktv_get(conn->remote_cfg,"wtp-name",NULL); + result->type->to_str(result,wtpname,CAPWAP_MAX_WTP_NAME_LEN); + cw_dbg(DBG_INFO, "WTP joined: '%s', IP %s.", + wtpname, + sock_addr2str(&conn->addr,sock_buf) + ); + break; + } + case CW_TRANSITION(CAPWAP_STATE_JOIN,CAPWAP_STATE_TIMEOUT): + { + cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.", + sock_addr2str(&wtpman->conn->addr,sock_buf), wait_join); + wtpman_remove(wtpman); + return NULL; + break; + } + case CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_CONFIGURE): + { + + wait_change_state = cw_ktv_get_word(conn->global_cfg, + "capwap-timers/change-state-pending-timer", + CAPWAP_TIMER_CHANGE_STATE_PENDING_TIMER); + + /* printf("Capwap state configure\n"); + exit(0); + */ + break; + } + case CW_TRANSITION(CAPWAP_STATE_CONFIGURE,CAPWAP_STATE_TIMEOUT): + { + cw_dbg(DBG_MSG_ERR, "No Change State Event Request %s after %d seconds, WTP died.", + sock_addr2str(&wtpman->conn->addr,sock_buf), wait_change_state); + wtpman_remove(wtpman); + return NULL; + break; + } + + } + + + + while (!cw_timer_timeout(timer)) { + rc = cw_read_messages(wtpman->conn); + if (rc < 0) { + if (errno == EAGAIN) + continue; + } + break; + } + + if(rc<0){ + conn->capwap_transition = + CW_TRANSITION(conn->capwap_transition,CAPWAP_STATE_TIMEOUT); + } + + } + + + + + + + + + + + + + + + + + + + + /* dtls is established, goto join state */ - if (!wtpman_join(wtpman, timer)) { + + conn->capwap_transition = CAPWAP_STATE_JOIN; + if (!wtpman_join(wtpman)) { wtpman_remove(wtpman); return NULL; } @@ -383,7 +440,7 @@ static void * wtpman_run(void *arg) format_bin2hex(conn->session_id,16)); - +exit(0); /* // cw_dbg(DBG_INFO, "Creating data thread"); @@ -397,7 +454,7 @@ static void * wtpman_run(void *arg) rc = 0; while (!cw_timer_timeout(timer) - && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { + && wtpman->conn->capwap_transition == CAPWAP_STATE_CONFIGURE) { rc = cw_read_messages(wtpman->conn); if (rc < 0) { if (errno != EAGAIN) @@ -415,14 +472,14 @@ cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,"-------------dump------------","DMP", } - if (conn->capwap_state == CW_STATE_IMAGE_DATA) { + if (conn->capwap_transition == CW_STATE_IMAGE_DATA) { wtpman_image_data(wtpman); return NULL; } - conn->capwap_state = CAPWAP_STATE_RUN; + conn->capwap_transition = CAPWAP_STATE_RUN; /* // XXX testing ... // DBGX("Cofig to sql", ""); @@ -435,7 +492,7 @@ cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,"-------------dump------------","DMP", reset_echointerval_timer(wtpman); rc = 0; - while (wtpman->conn->capwap_state == CAPWAP_STATE_RUN) { + while (wtpman->conn->capwap_transition == CAPWAP_STATE_RUN) { rc = cw_read_messages(wtpman->conn); if (rc < 0) { if (errno != EAGAIN) @@ -540,12 +597,12 @@ static void wtpman_run_dtls(void *arg) /*// time_t timer = cw_timer_start(wtpman->conn->wait_dtls);*/ /* establish dtls session */ - if (!wtpman_establish_dtls(wtpman)) { + if (!wtpman_dtls_setup(wtpman)) { wtpman_remove(wtpman); return; } - wtpman_run(arg); + wtpman_main(arg); } @@ -667,7 +724,7 @@ void wtpman_start(struct wtpman *wtpman, int dtlsmode) { cw_dbg(DBG_INFO, "Starting wtpman, DTLS mode = %d",dtlsmode); wtpman->dtlsmode=dtlsmode; - pthread_create(&wtpman->thread, NULL, wtpman_run, + pthread_create(&wtpman->thread, NULL, wtpman_main, (void *) wtpman); return; } diff --git a/src/cw/capwap.h b/src/cw/capwap.h index 5389bb1e..caac52be 100644 --- a/src/cw/capwap.h +++ b/src/cw/capwap.h @@ -378,6 +378,8 @@ #define CAPWAP_WAIT_DTLS 60 #define CAPWAP_WAIT_JOIN 60 +#define CAPWAP_TIMER_CHANGE_STATE_PENDING_TIMER 25 + #define CAPWAP_IDLE_TIMEOUT 300 @@ -589,7 +591,9 @@ extern struct cw_StrListElem capwap_strings_board[]; #define cw_strmsg(id) cw_strlist_get_str(capwap_strings_msg,id) #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_strprestate(id) cw_strlist_get_str(capwap_strings_state,id >> 8) +#define cw_strstate(id) cw_strlist_get_str(capwap_strings_state,id & 0xff) #define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id) #define cw_strresult(id) cw_strlist_get_str(capwap_strings_result,id) @@ -642,13 +646,18 @@ enum capwap_states { CAPWAP_STATE_DISCOVERY, /** Join State */ CAPWAP_STATE_JOIN, + CAPWAP_STATE_JOIN_COMPLETE, + /** Config State */ - CW_STATE_CONFIGURE, + CAPWAP_STATE_CONFIGURE, + CAPWAP_STATE_DTLS_SETUP, /**< DTLS Setup */ /** Image Data Upload */ CW_STATE_IMAGE_DATA, CW_STATE_UPDATE, /** Run State */ - CAPWAP_STATE_RUN + CAPWAP_STATE_RUN, + + CAPWAP_STATE_TIMEOUT }; /** diff --git a/src/cw/capwap_strings_state.c b/src/cw/capwap_strings_state.c index efdae495..02519f75 100644 --- a/src/cw/capwap_strings_state.c +++ b/src/cw/capwap_strings_state.c @@ -5,8 +5,10 @@ struct cw_StrListElem capwap_strings_state[] = { { CAPWAP_STATE_DISCOVERY, "Discovery" }, { CAPWAP_STATE_JOIN,"Join" }, { CAPWAP_STATE_RUN,"Run" }, -{ CW_STATE_CONFIGURE,"Configure" }, +{ CAPWAP_STATE_CONFIGURE,"Configure" }, { CW_STATE_IMAGE_DATA,"Image Data" }, +{ CAPWAP_STATE_DTLS_SETUP, "DTLS Setup" }, { CW_STR_STOP,"Undefined" }, + }; diff --git a/src/cw/conn.h b/src/cw/conn.h index e423ed32..631dc2df 100644 --- a/src/cw/conn.h +++ b/src/cw/conn.h @@ -115,7 +115,7 @@ struct conn { /** Current CAPWAP state */ - uint8_t capwap_state; + uint16_t capwap_transition; /** The framgent manager used on this connection */ diff --git a/src/cw/conn_process_packet.c b/src/cw/conn_process_packet.c index d5ae821c..dd751f32 100644 --- a/src/cw/conn_process_packet.c +++ b/src/cw/conn_process_packet.c @@ -219,7 +219,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, struct cw_MsgData search; struct cw_MsgData * message; int result_code; - int *i; + uint16_t *ui; uint8_t *elems_ptr; uint8_t *elem; @@ -299,7 +299,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, cw_dbg(DBG_MSG_ERR, "Message type %d [%s] unrecognized, sending response.", search.type, cw_strmsg(search.type), - cw_strstate(conn->capwap_state)); + cw_strstate(conn->capwap_transition)); + result_code = CAPWAP_RESULT_MSG_UNRECOGNIZED; cw_send_error_response(conn, rawmsg, result_code); errno = EAGAIN; @@ -308,7 +309,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, cw_dbg(DBG_MSG_ERR, "Message type %d [%s] unrecognized, discarding.", search.type, cw_strmsg(search.type), - cw_strstate(conn->capwap_state)); + cw_strstate(conn->capwap_transition)); errno = EAGAIN; return -1; @@ -320,25 +321,29 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, * */ if (!(message->receiver & conn->role)) { cw_dbg(DBG_MSG_ERR, - "Message type %d (%s) unexpected/illegal in %s State, discarding.", + "Message type %d (%s) unexpected/illegal in %s->%s State, discarding.", search.type, cw_strmsg(search.type), - cw_strstate(conn->capwap_state)); + cw_strprestate(conn->capwap_transition), + cw_strstate(conn->capwap_transition)); errno = EAGAIN; return -1; } /* Check if current state is in state of message */ - i = message->states; - for (i=message->states; *i; i++){ - if(*i==conn->capwap_state) + ui = message->states; + for (ui=message->states; *ui; ui++){ + printf("Comparing %d and %d\n", conn->capwap_transition, *ui); + if(*ui==conn->capwap_transition) break; } - if (!*i){ + if (!*ui){ /* Message found, but it was in wrong state */ cw_dbg(DBG_MSG_ERR, - "Message type %d (%s) not allowed in %s State, sending response.", - search.type,cw_strmsg(search.type), cw_strstate(conn->capwap_state)); + "Message type %d (%s) not allowed in %s->%s State, sending response.", + search.type,cw_strmsg(search.type), + cw_strprestate(conn->capwap_transition), + cw_strstate(conn->capwap_transition)); result_code = CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE; cw_send_error_response(conn, rawmsg, result_code); errno = EAGAIN; @@ -444,7 +449,12 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, cw_send_error_response(conn, rawmsg, result_code); } else if (result_code == 0) { cw_ktv_set_dword(conn->local_cfg,"result-code",result_code); + if (message->next_state){ + conn->capwap_transition = + CW_TRANSITION(conn->capwap_transition,message->next_state); + } + /* All is ok, send regular response message */ cw_send_response(conn, rawmsg, len); } else { diff --git a/src/cw/cw.h b/src/cw/cw.h index f571e203..43c59e34 100644 --- a/src/cw/cw.h +++ b/src/cw/cw.h @@ -340,6 +340,9 @@ struct cw_DescriptorSubelemDef { #define CW_IGNORE 5 +#define CW_TRANSITION(prestate,state) (prestate<<8|state) + + int cw_check_missing_mand(struct cw_MsgData *msgdata, mavl_t keys ); diff --git a/src/cw/cw_strtransition.c b/src/cw/cw_strtransition.c new file mode 100644 index 00000000..283a114b --- /dev/null +++ b/src/cw/cw_strtransition.c @@ -0,0 +1,8 @@ + + + + +const char * cw_strtransition(uint16_t state) +{ + +} \ No newline at end of file diff --git a/src/cw/msgset.c b/src/cw/msgset.c index 1942ecdf..65123ccc 100644 --- a/src/cw/msgset.c +++ b/src/cw/msgset.c @@ -284,14 +284,16 @@ int cw_msgset_add(struct cw_MsgSet *set, } /* Overwrite the found message */ - if (msgdef->name) + if (msgdef->name != NULL) msg->name = msgdef->name; - if (msgdef->states) + if (msgdef->states != NULL) msg->states = msgdef->states; if (msgdef->postprocess != NULL) msg->postprocess = msgdef->postprocess; if (msgdef->preprocess != NULL) msg->preprocess = msgdef->preprocess; + if (msgdef->next_state) + msg->next_state=msgdef->next_state; msg->receiver = msgdef->receiver; diff --git a/src/cw/msgset.h b/src/cw/msgset.h index 0de3472c..3b7ae301 100644 --- a/src/cw/msgset.h +++ b/src/cw/msgset.h @@ -66,19 +66,20 @@ 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 */ + uint16_t * states; /**< states in wich the message is allowed */ struct cw_ElemDef * elements; int (*preprocess)(struct conn * conn); int (*postprocess)(struct conn * conn); + uint8_t next_state; }; struct cw_MsgData{ int type; const char * name; - int * states; + uint16_t * states; int receiver; mavl_t elements_tree; mlist_t elements_list; @@ -86,6 +87,7 @@ struct cw_MsgData{ int (*preprocess)(struct conn * conn); int (*postprocess)(struct conn * conn); + uint8_t next_state; }; diff --git a/src/mod/capwap/capwap_actions_ac.c b/src/mod/capwap/capwap_actions_ac.c index 9f679361..ed20b482 100644 --- a/src/mod/capwap/capwap_actions_ac.c +++ b/src/mod/capwap/capwap_actions_ac.c @@ -27,6 +27,10 @@ #include "mod_capwap.h" + +static int postprocess_join_request(struct conn *conn); + + static cw_KTVStruct_t wtp_reboot_statistics[] = { {CW_TYPE_WORD, "reboot-count", 2,-1}, {CW_TYPE_WORD, "ac-initiated-count", 2,-1}, @@ -397,7 +401,7 @@ static struct cw_ElemHandler handlers[] = { }; -static int discovery_request_states[] = {CAPWAP_STATE_DISCOVERY,0}; +static uint16_t discovery_request_states[] = {CAPWAP_STATE_DISCOVERY,0}; static struct cw_ElemDef discovery_request_elements[] ={ {0,0,CAPWAP_ELEM_DISCOVERY_TYPE, 1, 0}, {0,0,CAPWAP_ELEM_WTP_BOARD_DATA, 1, 0}, @@ -410,7 +414,7 @@ static struct cw_ElemDef discovery_request_elements[] ={ }; -static int discovery_response_states[] = {CAPWAP_STATE_DISCOVERY,0}; +static uint16_t discovery_response_states[] = {CAPWAP_STATE_DISCOVERY,0}; static struct cw_ElemDef discovery_response_elements[] ={ {0,0,CAPWAP_ELEM_AC_DESCRIPTOR, 1, 0}, {0,0,CAPWAP_ELEM_AC_NAME, 1, 0}, @@ -421,7 +425,9 @@ static struct cw_ElemDef discovery_response_elements[] ={ }; -static int join_request_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t join_request_states[] = { + CW_TRANSITION(CAPWAP_STATE_DTLS_SETUP,CAPWAP_STATE_JOIN), + 0}; static struct cw_ElemDef join_request_elements[] ={ {0,0,CAPWAP_ELEM_LOCATION_DATA, 1, 0}, {0,0,CAPWAP_ELEM_WTP_BOARD_DATA, 1, 0}, @@ -440,7 +446,7 @@ static struct cw_ElemDef join_request_elements[] ={ {0,0,0,0,0} }; -static int join_response_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t join_response_states[] = {CAPWAP_STATE_JOIN,0}; static struct cw_ElemDef join_response_elements[] ={ {0,0,CAPWAP_ELEM_RESULT_CODE, 1, 0}, {0,0,CAPWAP_ELEM_AC_DESCRIPTOR, 1, 0}, @@ -459,7 +465,9 @@ static struct cw_ElemDef join_response_elements[] ={ }; -static int configuration_status_request_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t configuration_status_request_states[] = { + CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_JOIN), + 0}; static struct cw_ElemDef configuration_status_request_elements[] ={ {0,0,CAPWAP_ELEM_AC_NAME, 1, 0}, {0,0,CAPWAP_ELEM_RADIO_ADMINISTRATIVE_STATE, 1, 0}, @@ -471,7 +479,7 @@ static struct cw_ElemDef configuration_status_request_elements[] ={ {0,0,0,0,0} }; -static int configuration_status_response_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t configuration_status_response_states[] = {CAPWAP_STATE_JOIN,0}; static struct cw_ElemDef configuration_status_response_elements[] ={ {0,0,CAPWAP_ELEM_CAPWAP_TIMERS, 1, 0}, {0,0,CAPWAP_ELEM_DECRYPTION_ERROR_REPORT_PERIOD, 1, 0}, @@ -483,7 +491,7 @@ static struct cw_ElemDef configuration_status_response_elements[] ={ }; -static int configuration_update_request_states[] = {CAPWAP_STATE_RUN,0}; +static uint16_t configuration_update_request_states[] = {CAPWAP_STATE_RUN,0}; static struct cw_ElemDef configuration_update_request_elements[] ={ {0,0,CAPWAP_ELEM_RADIO_ADMINISTRATIVE_STATE, 0, 0}, @@ -497,14 +505,16 @@ static struct cw_ElemDef configuration_update_request_elements[] ={ -static int configuration_update_response_states[] = {CAPWAP_STATE_RUN,0}; +static uint16_t configuration_update_response_states[] = {CAPWAP_STATE_RUN,0}; static struct cw_ElemDef configuration_update_response_elements[] ={ {0,0,CAPWAP_ELEM_RESULT_CODE, 1, 0}, {0,0,0,0,0} }; -static int change_state_event_request_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t change_state_event_request_states[] = { + CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_CONFIGURE), + 0}; static struct cw_ElemDef change_state_event_request_elements[] ={ {0,0,CAPWAP_ELEM_RADIO_OPERATIONAL_STATE, 1,0}, @@ -514,7 +524,7 @@ static struct cw_ElemDef change_state_event_request_elements[] ={ {0,0,0,0,0} }; -static int change_state_event_response_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t change_state_event_response_states[] = {CAPWAP_STATE_JOIN,0}; static struct cw_ElemDef change_state_event_response_elements[] ={ {0,0,CAPWAP_ELEM_RESULT_CODE, 1, 0}, @@ -522,14 +532,14 @@ static struct cw_ElemDef change_state_event_response_elements[] ={ }; -static int wtp_event_request_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t wtp_event_request_states[] = {CAPWAP_STATE_JOIN,0}; static struct cw_ElemDef wtp_event_request_elements[] ={ {0,0,CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, 0, CW_IGNORE}, {0,0,0,0,0} }; -static int wtp_event_response_states[] = {CAPWAP_STATE_JOIN,0}; +static uint16_t wtp_event_response_states[] = {CAPWAP_STATE_JOIN,0}; static struct cw_ElemDef wtp_event_response_elements[] ={ {0,0,CAPWAP_ELEM_RESULT_CODE, 1, 0}, @@ -537,13 +547,13 @@ static struct cw_ElemDef wtp_event_response_elements[] ={ }; -static int echo_request_states[] = {CAPWAP_STATE_RUN,0}; +static uint16_t echo_request_states[] = {CAPWAP_STATE_RUN,0}; static struct cw_ElemDef echo_request_elements[] ={ {0,0,CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, 0, CW_IGNORE}, {0,0,0,0,0} }; -static int echo_response_states[] = {CAPWAP_STATE_RUN,0}; +static uint16_t echo_response_states[] = {CAPWAP_STATE_RUN,0}; static struct cw_ElemDef echo_response_elements[] ={ {0,0,CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, 0, CW_IGNORE}, {0,0,0,0,0} @@ -574,7 +584,11 @@ static struct cw_MsgDef messages[] = { CAPWAP_MSG_JOIN_REQUEST, CW_ROLE_AC, join_request_states, - join_request_elements + join_request_elements, + NULL, + postprocess_join_request, + CAPWAP_STATE_JOIN, + }, { @@ -590,7 +604,10 @@ static struct cw_MsgDef messages[] = { CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, /* msg type */ CW_ROLE_AC, /* role */ configuration_status_request_states, /* allowed states */ - configuration_status_request_elements /* msg elements */ + configuration_status_request_elements, /* msg elements */ + NULL, + NULL, + CAPWAP_STATE_CONFIGURE }, { @@ -623,6 +640,9 @@ static struct cw_MsgDef messages[] = { CW_ROLE_AC, /* role */ change_state_event_request_states, /* allowed states */ change_state_event_request_elements /* msg elements */ + NULL, + NULL, + CAPWAP_STATE_DATA_CHECK }, { @@ -667,54 +687,19 @@ static struct cw_MsgDef messages[] = { }, + {0,0,0,0} - - -/* { - "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, - .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_ElemDef_t []){ - {&_DISCOVERY_TYPE,1}, - {&_WTP_BOARD_DATA,1}, - {&_WTP_DESCRIPTOR,1}, - {&_WTP_FRAME_TUNNEL_MODE,1}, - {&_WTP_MAC_TYPE,1}, - {&_MTU_DISCOVERY_PADDING,0}, - {&_VENDOR_SPECIFIC_PAYLOAD,0}, - {0,0}, - } - }, -*/ - /* Discovery Request Response */ -/* { - .name = "Discovery Response", - .type = CAPWAP_MSG_DISCOVERY_RESPONSE, - .receiver = CW_RECEIVER_WTP, - .states = (int[]){CAPWAP_STATE_DISCOVERY,0}, - .elements = (cw_ElemDef_t[]){ - {&_AC_DESCRIPTOR,1}, - {0,0}, - } - }, -*/ {0,0,0,0} - - - }; +static int postprocess_join_request(struct conn *conn) +{ + return 1; +} + + + + struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){ if (mode != CW_MOD_MODE_CAPWAP) return NULL; diff --git a/src/mod/capwap/capwap_actions_wtp.c b/src/mod/capwap/capwap_actions_wtp.c index 2aed1d9c..14911da5 100644 --- a/src/mod/capwap/capwap_actions_wtp.c +++ b/src/mod/capwap/capwap_actions_wtp.c @@ -203,7 +203,7 @@ static cw_action_in_t actions_in[] = { * Message Configuration Status Response - IN */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .end = cw_in_check_generic_resp } @@ -212,7 +212,7 @@ static cw_action_in_t actions_in[] = { /* Capwap Timers - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_CAPWAP_TIMERS, .item_id = CW_ITEM_CAPWAP_TIMERS, @@ -225,7 +225,7 @@ static cw_action_in_t actions_in[] = { /* Decryption Error Report - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_DECRYPTION_ERROR_REPORT_PERIOD, .item_id = CW_RADIOITEM_DECRYPTION_ERROR_REPORT_PERIOD, @@ -239,7 +239,7 @@ static cw_action_in_t actions_in[] = { /* Idle Timeout - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_IDLE_TIMEOUT, .item_id = CW_ITEM_IDLE_TIMEOUT, @@ -253,7 +253,7 @@ static cw_action_in_t actions_in[] = { /* WTP Fallback - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_WTP_FALLBACK, .item_id = CW_ITEM_WTP_FALLBACK, @@ -269,7 +269,7 @@ static cw_action_in_t actions_in[] = { /* Result Code - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_RESULT_CODE, .item_id = CW_ITEM_RESULT_CODE, @@ -283,7 +283,7 @@ static cw_action_in_t actions_in[] = { /* AC IPv4 List - Config Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_AC_IPV4_LIST, .item_id = CW_ITEM_AC_IP_LIST, @@ -297,7 +297,7 @@ static cw_action_in_t actions_in[] = { /* Vendor Specific Payload - Cponfig Status Resp */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, .elem_id = CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, .start = cw_in_vendor_specific_payload @@ -312,14 +312,14 @@ static cw_action_in_t actions_in[] = { */ { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CHANGE_STATE_EVENT_RESPONSE, .end = cw_in_check_cfg_update_req } , { - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CAPWAP_MSG_CHANGE_STATE_EVENT_RESPONSE, .elem_id = CAPWAP_ELEM_RESULT_CODE, .item_id = CW_ITEM_RESULT_CODE, diff --git a/src/mod/capwap/capwap_in_vendor_specific_payload.c b/src/mod/capwap/capwap_in_vendor_specific_payload.c index eb156d0e..4b5052bb 100644 --- a/src/mod/capwap/capwap_in_vendor_specific_payload.c +++ b/src/mod/capwap/capwap_in_vendor_specific_payload.c @@ -29,7 +29,7 @@ int capwap_in_vendor_specific_payload(struct cw_ElemHandler *handler, cw_dbg(DBG_WARN, "Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.", cw_strvendor(vendor_id), elem_id, params->msgdata->type, - params->msgdata->name, cw_strstate(params->conn->capwap_state)); + params->msgdata->name, cw_strstate(params->conn->capwap_transition)); return 0; } diff --git a/src/mod/capwap80211/capwap80211_messages.c b/src/mod/capwap80211/capwap80211_messages.c index f899d4af..cebb09ce 100644 --- a/src/mod/capwap80211/capwap80211_messages.c +++ b/src/mod/capwap80211/capwap80211_messages.c @@ -10,9 +10,10 @@ #include "mod_capwap80211.h" -static int capwap80211_in_crate_set(struct cw_ElemHandler *eh, +/*static int capwap80211_in_crate_set(struct cw_ElemHandler *eh, struct cw_ElemHandlerParams *params, uint8_t * data, int len); +*/ static struct cw_ElemHandler handlers[] = { { @@ -33,8 +34,8 @@ static struct cw_ElemHandler handlers[] = { 3, 0, /* min/max length */ CW_TYPE_BSTR16, /* type */ "rate_set", /* Key */ - cw_in_radio_generic, /* get */ - cw_out_radio_generic /* put */ + cw_in_radio_generic, /* get */ + cw_out_radio_generic /* put */ } , {NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL} @@ -42,7 +43,7 @@ static struct cw_ElemHandler handlers[] = { }; -static int discovery_request_states[] = { CAPWAP_STATE_DISCOVERY, 0 }; +/*static int discovery_request_states[] = { CAPWAP_STATE_DISCOVERY, 0 };*/ static struct cw_ElemDef discovery_request_elements[] = { {0, 0, CAPWAP80211_ELEM_WTP_RADIO_INFORMATION, 1, 0}, {0, 0, 0, 0, 0} @@ -50,21 +51,21 @@ static struct cw_ElemDef discovery_request_elements[] = { }; -static int join_request_states[] = { CAPWAP_STATE_JOIN, 0 }; +/*static int join_request_states[] = { CAPWAP_STATE_JOIN, 0 };*/ static struct cw_ElemDef join_request_elements[] = { {0, 0, CAPWAP80211_ELEM_WTP_RADIO_INFORMATION, 1, 0}, {0, 0, 0, 0, 0} }; -static int join_response_states[] = { CAPWAP_STATE_JOIN, 0 }; +/*static int join_response_states[] = { CAPWAP_STATE_JOIN, 0 };*/ static struct cw_ElemDef join_response_elements[] = { {0, 0, CAPWAP80211_ELEM_WTP_RADIO_INFORMATION, 1, 0}, {0, 0, 0, 0, 0} }; -static int configuration_status_response_states[] = { CAPWAP_STATE_JOIN, 0 }; +/*static int configuration_status_response_states[] = { CAPWAP_STATE_JOIN, 0 };*/ static struct cw_ElemDef configuration_status_response_elements[] = { {0, 0, CAPWAP80211_ELEM_RATE_SET , 1, 0}, {0, 0, 0, 0, 0} @@ -75,23 +76,23 @@ static struct cw_MsgDef messages[] = { NULL, CAPWAP_MSG_DISCOVERY_REQUEST, CW_ROLE_AC, - discovery_request_states, + NULL, /* states */ discovery_request_elements } , { - NULL, - CAPWAP_MSG_JOIN_REQUEST, - CW_ROLE_AC, - join_request_states, - join_request_elements + NULL, /* name */ + CAPWAP_MSG_JOIN_REQUEST, /* type */ + CW_ROLE_AC, /* role */ + NULL, /* states */ + join_request_elements /* elements */ } , { NULL, CAPWAP_MSG_JOIN_RESPONSE, CW_ROLE_AC, - join_response_states, + NULL, join_response_elements } , @@ -99,7 +100,7 @@ static struct cw_MsgDef messages[] = { NULL, CAPWAP_MSG_CONFIGURATION_STATUS_RESPONSE, CW_ROLE_WTP, - configuration_status_response_states, + NULL, configuration_status_response_elements } , @@ -121,19 +122,19 @@ int mode; } - +/* static int capwap80211_in_crate_set(struct cw_ElemHandler *eh, struct cw_ElemHandlerParams *params, uint8_t * data, int len) { -/* int radio; + int radio; int i; radio = cw_get_byte(data); for (i=0; imsgdata->type, - params->msgdata->name, cw_strstate(params->conn->capwap_state)); + params->msgdata->name, cw_strstate(params->conn->capwap_transition)); return 0; } diff --git a/src/mod/fortinet/fortinet_actions_ac.c b/src/mod/fortinet/fortinet_actions_ac.c index 11110163..36ad01e2 100644 --- a/src/mod/fortinet/fortinet_actions_ac.c +++ b/src/mod/fortinet/fortinet_actions_ac.c @@ -152,7 +152,7 @@ static cw_action_in_t actions_in[] = { /* AC Name - Config Status Request */ { /* We have to deal with zero-length strings */ - .capwap_state = CW_STATE_CONFIGURE, + .capwap_state = CAPWAP_STATE_CONFIGURE, .msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST, .elem_id = CAPWAP_ELEM_AC_NAME, .item_id = CW_ITEM_AC_NAME, diff --git a/src/wtp/changestate.c b/src/wtp/changestate.c index cb70a82f..c79e2ebf 100644 --- a/src/wtp/changestate.c +++ b/src/wtp/changestate.c @@ -10,7 +10,6 @@ int changestate(struct conn * conn) { - /* Update operational states, so they will be included in the change Change State Event Request message. */ /*// cw_radio_update_oper_states(conn->radios,0);*/ diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index b2c82c73..aa9b2352 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -148,7 +148,7 @@ static int run_discovery(struct conn *conn, struct cw_DiscoveryResult * dis) } - conn->capwap_state = CAPWAP_STATE_DISCOVERY; + conn->capwap_transition = CAPWAP_STATE_DISCOVERY; /* create and send a discovery request message */ @@ -164,7 +164,7 @@ static int run_discovery(struct conn *conn, struct cw_DiscoveryResult * dis) while (!cw_timer_timeout(timer) - && conn->capwap_state == CAPWAP_STATE_DISCOVERY) { + && conn->capwap_transition == CAPWAP_STATE_DISCOVERY) { int rc; char addr_str[SOCK_ADDR_BUFSIZE]; diff --git a/src/wtp/image_update.c b/src/wtp/image_update.c index d29a2725..1da1cdf4 100644 --- a/src/wtp/image_update.c +++ b/src/wtp/image_update.c @@ -11,7 +11,7 @@ int image_update() { struct conn *conn = get_conn(); - if (conn->capwap_state != CW_STATE_CONFIGURE) { + if (conn->capwap_state != CAPWAP_STATE_CONFIGURE) { cw_log(LOG_ERR, "Current state not image update"); return 0; } diff --git a/src/wtp/join.c b/src/wtp/join.c index d137da91..07e5e6f5 100644 --- a/src/wtp/join.c +++ b/src/wtp/join.c @@ -116,7 +116,7 @@ int run_join_d(struct conn * conn, struct sockaddr *sa) } /* setup a socket */ - conn->capwap_state = CAPWAP_STATE_JOIN; + conn->capwap_transition = CAPWAP_STATE_JOIN; sockfd = socket(sa->sa_family, SOCK_DGRAM, 0); if (sockfd == -1) { cw_log(LOG_ERR, "Can't create socket: %s\n", strerror(errno)); diff --git a/src/wtp/run.c b/src/wtp/run.c index 376da582..220db50b 100644 --- a/src/wtp/run.c +++ b/src/wtp/run.c @@ -140,7 +140,7 @@ int run(struct conn * conn) - conn->capwap_state = CAPWAP_STATE_RUN; + conn->capwap_transition = CAPWAP_STATE_RUN; /* conn->msg_end=handle_update_req;*/ @@ -156,7 +156,7 @@ int run(struct conn * conn) - while (!cw_timer_timeout(timer) && conn->capwap_state == CAPWAP_STATE_RUN) { + while (!cw_timer_timeout(timer) && conn->capwap_transition == CAPWAP_STATE_RUN) { mavl_del_all(conn->remote_cfg); rc = cw_read_messages(conn); if (rc < 0 && errno == EAGAIN) { @@ -196,7 +196,7 @@ int run(struct conn * conn) - } while (conn->capwap_state == CAPWAP_STATE_RUN); + } while (conn->capwap_transition == CAPWAP_STATE_RUN); /*