Work on state machine

shell
7u83 6 months ago
parent bf8a8c6d53
commit e5f5687b2b
  1. 19
      Makefile
  2. 2
      src/ac/Makefile
  3. 7
      src/ac/ac_main.c
  4. 33
      src/ac/wtpman.c
  5. 6
      src/ac/wtpman.h
  6. 12
      src/cw/capwap.h
  7. 20
      src/cw/capwap_strings_state.c
  8. 11
      src/cw/cfg.c
  9. 1
      src/cw/cfg.h
  10. 6
      src/cw/conn.c
  11. 2
      src/cw/conn.h
  12. 1
      src/cw/conn_process_packet.c
  13. 9
      src/cw/dbg.c
  14. 2
      src/cw/dbg.h
  15. 10
      src/cw/msgset.c
  16. 2
      src/cw/msgset.h
  17. 28
      src/mod/cisco/cisco_out_ac_descriptor.c

@ -1,10 +1,6 @@
.OBJDIR: ./
all:
$(MAKE) -C src/cw -j16
$(MAKE) -C src/mod -j16
$(MAKE) -C src/ac -j16
$(MAKE) -C src/wtp -j16
all: ac wtp
clean:
@ -12,5 +8,16 @@ clean:
$(MAKE) -C src/mod clean
$(MAKE) -C src/ac clean
$(MAKE) -C src/wtp clean
cw:
$(MAKE) -C src/cw
ac: cw mod
$(MAKE) -C src/ac
wtp: cw mod
$(MAKE) -C src/wtp
mod: cw
$(MAKE) -C src/mod

@ -9,6 +9,8 @@ OBJS = \
socklist.o \
discovery_cache.o\
shell.o\
statemachine.o\
PRG=actube
LIBPATH=-L../../lib/$(KERNEL)/$(ARCH)/ -L/usr/local/lib -L/usr/lib

@ -50,7 +50,7 @@
int ac_run(cw_Cfg_t * cfg);
#include "statemachine.h"
#include <getopt.h>
@ -184,6 +184,11 @@ int main (int argc, char *argv[])
/* parse arguments */
parse_args (argc, argv, &bootcfg);
cw_statemachine_run(NULL);
exit(0);
global_cfg=cw_cfg_create();
if (!global_cfg){
fprintf(stderr,"Can't create global_cfg: %s\n",strerror(errno));

@ -86,6 +86,10 @@ static void wtpman_remove(struct wtpman *wtpman)
static void wtpman_run_discovery(void *arg)
{
cw_dbg(DBG_STATE,"Run discovery");
exit(0);
struct wtpman *wtpman = (struct wtpman *) arg;
time_t timer = cw_timer_start(10);
@ -270,6 +274,8 @@ void *wtpman_run_data(void *wtpman_arg)
}
int cw_run_state_machine(struct cw_Conn *conn, time_t * timer)
{
@ -280,7 +286,7 @@ int cw_run_state_machine(struct cw_Conn *conn, time_t * timer)
while (1) {
search.state = conn->capwap_state;
search.prevstate = conn->capwap_prevstate;
result = mavl_get(conn->msgset->state_machine, &search);
result = mavl_get(conn->msgset->statemachine_states, &search);
cw_dbg(DBG_STATE, "State transition: [%s -> %s]",
cw_strstate(conn->capwap_prevstate),
@ -655,7 +661,8 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
wtpman = malloc(sizeof(struct wtpman));
if (!wtpman)
return 0;
memset(wtpman, 0, sizeof(struct wtpman));
if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
@ -676,11 +683,6 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
sockfd = replyfd; /*//socklist[socklistindex].reply_sockfd; */
dbgaddrl = sizeof(dbgaddr);
getsockname(sockfd, &dbgaddr, &dbgaddrl);
@ -688,26 +690,25 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
sock_addr2str(&dbgaddr, sock_buf), sock_getport(&dbgaddr));
memset(wtpman, 0, sizeof(struct wtpman));
wtpman->conn = cw_conn_create(sockfd, srcaddr, 5);
wtpman->conn->role = CW_ROLE_AC;
wtpman->conn->data_sock = socklist[socklistindex].data_sockfd;
sock_copyaddr(&wtpman->conn->data_addr,
(struct sockaddr *) &wtpman->conn->addr);
wtpman->global_cfg = global_cfg;
wtpman->conn = cw_conn_create(sockfd, srcaddr, 5);
if (!wtpman->conn) {
wtpman_destroy(wtpman);
return NULL;
}
wtpman->conn->role = CW_ROLE_AC;
wtpman->conn->data_sock = socklist[socklistindex].data_sockfd;
sock_copyaddr(&wtpman->conn->data_addr,
(struct sockaddr *) &wtpman->conn->addr);
wtpman->conn->mods = conf_mods;
// wtpman->conn->mods = conf_mods;
wtpman->conn->strict_capwap = conf_strict_capwap;
wtpman->conn->strict_hdr = conf_strict_headers;

@ -31,6 +31,12 @@ struct wtpman {
cw_timer_t echointerval_timer;
cw_Cfg_t * global_cfg; /**< contains the cfg of AC,
visible to all wtpman threads.
The global cfg was initally read
from a .ckv file on startup.
*/
};

@ -641,14 +641,10 @@ struct cw_ac_status {
*/
enum capwap_states {
CW_STATE_NONE = 0,
/** Discovery State */
CAPWAP_STATE_DISCOVERY,
/** Join State */
CAPWAP_STATE_JOIN,
CAPWAP_STATE_JOIN_COMPLETE,
/** Config State */
CAPWAP_STATE_CONFIGURE,
CAPWAP_STATE_DISCOVERY, /**< Discovery State */
CAPWAP_STATE_JOIN, /**< Join State */
CAPWAP_STATE_JOIN_COMPLETE,
CAPWAP_STATE_CONFIGURE, /**< Config State */
CAPWAP_STATE_DTLS_SETUP, /**< DTLS Setup */
/** Image Data Upload */
CW_STATE_IMAGE_DATA,

@ -2,15 +2,15 @@
#include "capwap.h"
struct cw_StrListElem capwap_strings_state[] = {
{ CAPWAP_STATE_DISCOVERY, "Discovery" },
{ CAPWAP_STATE_JOIN,"Join" },
{ CAPWAP_STATE_RUN,"Run" },
{ CAPWAP_STATE_CONFIGURE,"Configure" },
{ CW_STATE_IMAGE_DATA,"Image Data" },
{ CAPWAP_STATE_DTLS_SETUP, "DTLS Setup" },
{ CAPWAP_STATE_DATA_CHECK, "Data Check" },
{ CAPWAP_STATE_TIMEOUT, "Timeout"},
{ CW_STR_STOP,"Undefined" },
{ CW_STATE_NONE, "None"},
{ CAPWAP_STATE_DISCOVERY, "Discovery" },
{ CAPWAP_STATE_JOIN,"Join" },
{ CAPWAP_STATE_RUN,"Run" },
{ CAPWAP_STATE_CONFIGURE,"Configure" },
{ CW_STATE_IMAGE_DATA,"Image Data" },
{ CAPWAP_STATE_DTLS_SETUP, "DTLS Setup" },
{ CAPWAP_STATE_DATA_CHECK, "Data Check" },
{ CAPWAP_STATE_TIMEOUT, "Timeout"},
{ CW_STR_STOP,"Undefined" },
};

@ -491,6 +491,17 @@ int cw_cfg_get_bool(cw_Cfg_t * cfg, const char * key, const char *def)
return v.val.boolean;
}
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, const char * def)
{
struct cw_Val v;
const char *s = cw_cfg_get(cfg,key,def);
CW_TYPE_BYTE->from_str(&v,s);
return v.val.word;
}
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, const char * def)
{
struct cw_Val v;

@ -32,6 +32,7 @@ void cw_cfg_iter_init(cw_Cfg_t * cfg, struct cw_Cfg_iter *cfi, const char *base)
int cw_cfg_get_bool(cw_Cfg_t * cfg, const char * key, const char *def);
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, const char * def);
void cw_cfg_set_int(cw_Cfg_t * cfg, const char * key, int val);
uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, const char * def);
#endif

@ -93,6 +93,7 @@ printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name
continue;
}
cw_dbg(DBG_X,"Hello!");
if (handler->put == NULL){
if (data->mand){
@ -122,9 +123,12 @@ printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name
cisco/ap-led-flash-config/flash-enable
}*/
cw_dbg(DBG_X,"Calling Handler put for %s",handler->name);
l = handler->put(handler,&params,dst+len);
cw_dbg(DBG_X,"L = %d",l);
/* if(l>0)
cw_dbg_elem(DBG_ELEM_OUT,conn,type,handler,dst+len,l);
* if (strlen(details)){

@ -235,7 +235,7 @@ struct cw_Conn {
int detected;
void * mods;
// void * mods;
int (*msg_start)(struct cw_Conn*conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);

@ -660,6 +660,7 @@ int cw_read_messages(struct cw_Conn *conn)
{
uint8_t buf[2024];
int len = 2024;
cw_dbg(DBG_X,"Conn cw_read_messages from dsco request");
int n = conn->read(conn, buf, len);
if (n < 0)

@ -55,7 +55,7 @@ uint32_t cw_dbg_opt_level = 0;
static struct cw_StrListElem color_on[] = {
static struct cw_StrListElem theme0[] = {
{DBG_PKT_IN, ANSI_YELLOW},
{DBG_PKT_OUT, ANSI_YELLOW ANSI_ITALIC},
@ -86,7 +86,7 @@ static struct cw_StrListElem color_on[] = {
{DBG_INFO, ANSI_DEFAULT},
{DBG_STATE, ANSI_BBLACK ANSI_BOLD },
{DBG_STATE, ANSI_GREEN ANSI_BOLD},
{DBG_RFC, ANSI_BRED},
{DBG_X, "\x1b[31m"},
@ -98,6 +98,9 @@ static struct cw_StrListElem color_on[] = {
{CW_STR_STOP, ""}
};
static struct cw_StrListElem * color_on = theme0;
struct cw_StrListElem color_ontext[] = {
/* {DBG_ELEM_DMP, "\x1b[37m"},*/
@ -132,7 +135,7 @@ static struct cw_StrListElem prefix[] = {
{DBG_DTLS_DETAIL, " DTLS - "},
{DBG_WARN, " Warning - "},
{DBG_MOD, " Mod - "},
{DBG_STATE, " State Machine - "},
{DBG_STATE, " STATEMACHINE - "},
{DBG_CFG_SET, " Cfg Set - "},

@ -120,7 +120,7 @@ enum cw_dbg_levels{
/** Debug Mods */
DBG_MOD,
DBG_STATE, /**<Debug State machein */
DBG_STATE, /**<Debug State machine */
DBG_ALL,

@ -103,8 +103,8 @@ void cw_msgset_destroy(struct cw_MsgSet *set)
mavl_destroy(set->handlers_by_id);
if (set->handlers_by_key)
mavl_destroy(set->handlers_by_key);
if (set->state_machine)
mavl_destroy(set->state_machine);
if (set->statemachine_states)
mavl_destroy(set->statemachine_states);
free(set);
}
@ -160,8 +160,8 @@ struct cw_MsgSet *cw_msgset_create()
}
set->state_machine = mavl_create(cmp_machinestate,NULL,sizeof(cw_StateMachineState_t));
if (set->state_machine == NULL)
set->statemachine_states = mavl_create(cmp_machinestate,NULL,sizeof(cw_StateMachineState_t));
if (set->statemachine_states == NULL)
{
cw_msgset_destroy(set);
return NULL;
@ -359,7 +359,7 @@ int cw_msgset_add_states(struct cw_MsgSet * set, cw_StateMachineState_t * states
s=states;
while (s->state != 0){
const char * repstr;
mavl_replace(set->state_machine,s,&replaced);
mavl_replace(set->statemachine_states,s,&replaced);
if (replaced){
repstr = "Replacing";

@ -68,7 +68,7 @@ struct cw_MsgSet {
mavl_t handlers_by_id;
mavl_t handlers_by_key;
mavl_t types_tree;
mavl_t state_machine;
mavl_t statemachine_states;
int (*write_header)(struct cw_ElemHandler * handler, uint8_t * dst, int len);
int (*header_len)(struct cw_ElemHandler *handler);
};

@ -9,23 +9,23 @@
#include "cw/cw.h"
#include "cw/val.h"
#include "cw/keys.h"
#include "cw/cfg.h"
static int put_ac_status(mavl_t global, mavl_t local, uint8_t *dst, const char * parent_key){
static int put_ac_status(cw_Cfg_t * cfg, cw_Cfg_t * default_cfg, uint8_t *dst, const char * parent_key){
uint8_t *d = dst;
uint8_t security;
char key[CW_KTV_MAX_KEY_LEN];
char key[CW_CFG_MAX_KEY_LEN];
d += cw_put_word(d,cw_ktv_get_word(local,"ac-descriptor/stations",0));
d += cw_put_word(d,cw_ktv_get_word(local,"ac-descriptor/station-limit",0));
d += cw_put_word(d,cw_ktv_get_word(local,"ac-descriptor/active-wtps",0));
d += cw_put_word(d,cw_ktv_get_word(local,"ac-descriptor/max-wtps",0));
d += cw_put_word(d,cw_cfg_get_word(cfg,"ac-descriptor/stations","0"));
d += cw_put_word(d,cw_cfg_get_word(cfg,"ac-descriptor/station-limit","0"));
d += cw_put_word(d,cw_cfg_get_word(cfg,"ac-descriptor/active-wtps","0"));
d += cw_put_word(d,cw_cfg_get_word(cfg,"ac-descriptor/max-wtps","0"));
d += cw_put_byte(d,cw_ktv_get_byte(local,"ac-descriptor/security",0));
d += cw_put_byte(d,cw_cfg_get_byte(cfg,"ac-descriptor/security",0));
/*
security = 0;
if (cw_ktv_get(local,"dtls-cert-file",CW_TYPE_BSTR16))
@ -40,14 +40,14 @@ static int put_ac_status(mavl_t global, mavl_t local, uint8_t *dst, const char *
d += cw_put_byte(dst,security);
*/
sprintf(key,"%s/%s",parent_key,"ac-descriptor/r-mac-field");
d += cw_put_byte(d,cw_ktv_get_byte(local,"ac-descriptor/r-mac-field",0));
d += cw_put_byte(d,cw_cfg_get_byte(cfg,"ac-descriptor/r-mac-field",0));
/*d += cw_put_byte(d,3);*/
d += cw_put_byte(d,0);
sprintf(key,"%s/%s",parent_key,CW_SKEY_DTLS_POLICY);
d += cw_put_byte(d,cw_ktv_get_byte(local,"ac-descriptor/dtls-policy",0));
d += cw_put_byte(d,cw_cfg_get_byte(cfg,"ac-descriptor/dtls-policy",0));
return d - dst;
}
@ -58,10 +58,12 @@ int cisco_out_ac_descriptor(struct cw_ElemHandler * eh,
{
int len,l;
uint8_t *d = dst+4;
char key[CW_KTV_MAX_KEY_LEN];
char key[CW_CFG_MAX_KEY_LEN];
cw_dbg(DBG_X,"Putting AC TATUS WIITH KEY: %s",eh->key);
d+=put_ac_status(params->local_cfg,
params->global_cfg,
d+=put_ac_status(params->cfg,
params->default_cfg,
d, eh->key);
/* it is important to send software version first,

Loading…
Cancel
Save