Work on State machine
FossilOrigin-Name: 87d98b73010c7316cb9b53b5ba8c3dfdddca06042630cf8437ea506e1c424c70
This commit is contained in:
@ -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
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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" },
|
||||
|
||||
};
|
||||
|
||||
|
@ -115,7 +115,7 @@ struct conn {
|
||||
|
||||
/** Current CAPWAP state */
|
||||
|
||||
uint8_t capwap_state;
|
||||
uint16_t capwap_transition;
|
||||
|
||||
|
||||
/** The framgent manager used on this connection */
|
||||
|
@ -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 {
|
||||
|
@ -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 );
|
||||
|
||||
|
||||
|
8
src/cw/cw_strtransition.c
Normal file
8
src/cw/cw_strtransition.c
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
const char * cw_strtransition(uint16_t state)
|
||||
{
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user