diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 8cfc60b6..a3bcc74a 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -71,6 +71,13 @@ UTILOBJS= \ cw_format_version.o \ send.o +MAVLOBJS= \ + mavl.o \ + mavl_del.o \ + mavl_add.o \ + mavl_create.o\ + utf8.o + # cw_foreach_msgelem.o \ @@ -318,7 +325,8 @@ OBJS=$(CONNOBJS) $(FRAGOBJS) $(SOCKOBJS) $(CAPWAPOBJS) $(WTPINFOOBJS) \ $(LOGOBJS) $(UTILOBJS) $(DTLSOBJS) $(BSTROBJS) \ $(LWAPPOBJS) \ $(LWAPPCISCOOBJS) \ - $(CWACTION) + $(CWACTION) \ + $(MAVLOBJS) #include $(OBJS:.o=.d) diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index 6b6795d3..95e1d805 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -1062,5 +1062,7 @@ struct cw_item *cw_out_get_session_id(struct conn *conn, struct cw_action_out *a int cw_send_request(struct conn *conn, int msg_id); +int cw_is_utf8(unsigned char *str, size_t len); + #endif diff --git a/src/contrib/jsmn/example/.simple.c.swp b/src/contrib/jsmn/example/.simple.c.swp deleted file mode 100644 index 5b6aa972..00000000 Binary files a/src/contrib/jsmn/example/.simple.c.swp and /dev/null differ diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 51e1aae0..ff6e77ae 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -20,8 +20,8 @@ ifndef ARCH endif -#CFLAGS += -O0 -Wall -g -CFLAGS += -Os -Wall +CFLAGS += -O0 -Wall -g +#CFLAGS += -Os -Wall LDFLAGS += -L../contrib/jsmn -L../../src/capwap/$(ARCH) diff --git a/src/wtp/cfg.c b/src/wtp/cfg.c new file mode 100644 index 00000000..0f3b436a --- /dev/null +++ b/src/wtp/cfg.c @@ -0,0 +1,179 @@ +#include "capwap/itemstore.h" +#include "capwap/capwap_items.h" +#include "capwap/conn.h" +#include "capwap/bstr.h" + +#include +#include + +#include "jsmn.h" +#include "wtp.h" + +struct cw_itemdef { + int item_id; + const char *cfgname; + int (*setfun) (struct cw_itemdef *,char *js,jsmntok_t *t); + +}; +typedef struct cw_itemdef cfg_item_t; + +enum { + CW_ITEMSPACE_DBG, + CW_ITEMSPACE_WTP +}; + + +int bstr16_local(struct cw_item_def *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); + cw_itemstore_set_bstr16n(conn->local,item_id,js+t->start,t->end-t->start); +} + + +struct cw_itemdef cfg[] = { + {CW_ITEM_WTP_HARDWARE_VERSION, "hardware_version",bstr16_local}, + {CW_ITEM_WTP_SOFTWARE_VERSION, "software_version",bstr16_local}, + {CW_ITEM_WTP_BOARD_MODELNO, "modelno",bstr16_local}, + + {0, 0, 0} +}; + + + + + + +struct cw_itemdef * get_cfg(const char *key){ + int i=0; + for (i=0; cfg[i].item_id; i++){ + if ( !strcmp(key,cfg[i].cfgname )) { + return &cfg[i]; + } + } + return NULL; +} + + +int scn_obj(jsmntok_t *t, int i) +{ + + + +} + + +static int set_cfg(char *js,jsmntok_t *t){ + + *(js+t->end)=0; + const char * key = js+t->start; + + if ( t->type != JSMN_STRING ) { + printf("Error - No String: %s\n",key); + return 0; + } + + struct cw_itemdef * idef = get_cfg(key); + if(!idef){ + printf("Error - not found: %s\n",key); + return 0; + } + + if ( !idef->setfun) { + printf("Error no setfun: %s\n",key); + + } + else{ + idef->setfun(idef->item_id,js,t+1); + } + + return 1; + +} + +static int read_obj(char *js, jsmntok_t *t ) { + int i; + + if (t->type!=JSMN_OBJECT){ + return 0; + } + + if (t->size<3) { + return 0; + } + + for (i = 1; i < t->size; i++) { + i+=set_cfg(js,t+i); + continue; + + } + + return 0; + +} + + + + +int setup_conf(struct conn *conn) +{ + FILE * infile = fopen("cfg.json","rb"); + if ( !infile ){ + perror("Can't open cfg.json"); + return 0; + } + + fseek(infile,0,SEEK_END); + int size = ftell(infile); + + + char *jstr = malloc(size); + if ( jstr==NULL){ + perror("Can't allocate memory"); + return 0; + + } + + fseek(infile,0,SEEK_SET); + fread(jstr,1,size,infile); + + jsmn_parser p; + jsmntok_t t[1200]; + jsmn_init(&p); + + int rc = jsmn_parse(&p,jstr,size, t,sizeof(t)/sizeof(t[0])); + if (rc<0) { + printf("Parser failed\n"); + } + + read_obj(jstr, t); + + + + + + int i; + + + + + + + + for (i = 0; cfg[i].item_id != CW_ITEM_NONE; i++) { + printf("ItemName: %s\n", cfg[i].cfgname); //.cfgname) + + } + + return 0; +} diff --git a/src/wtp/image_update.c b/src/wtp/image_update.c new file mode 100644 index 00000000..848ac3b4 --- /dev/null +++ b/src/wtp/image_update.c @@ -0,0 +1,55 @@ +#include +#include "wtp.h" + +#include "capwap/log.h" +#include "capwap/dbg.h" +#include "capwap/capwap.h" +#include "capwap/capwap_items.h" + + +int image_update() +{ + struct conn *conn = get_conn(); + if (conn->capwap_state != CW_STATE_CONFIGURE) { + cw_log(LOG_ERR, "Current state not image update"); + return 0; + } + + + const char *ii = "/c1130"; + cw_itemstore_set_vendorstr(conn->outgoing, CW_ITEM_IMAGE_IDENTIFIER, + CW_VENDOR_ID_CISCO, (uint8_t *) ii, strlen(ii)); + + + int rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST); + + if (rc < 0) { + } + + if (rc != 0) { + cw_log(LOG_ERR, "AC rejected Image Data Request with code: %d - %s", rc, + cw_strresult(rc)); + return 0; + } + + cw_dbg(DBG_ELEM,"Ready to receive image ...\n"); + + conn->capwap_state=CW_STATE_IMAGE_DATA; + rc=-11; + while (conn->capwap_state == CW_STATE_IMAGE_DATA) { + rc = cw_read_messages(conn); + if (rc < 0) { + if (errno != EAGAIN) + break; + } + } + + + printf("RC: %d %s\n",rc,strerror(errno)); + + + + + + return 1; +} diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 2e00a984..eff6a9f1 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -66,7 +66,7 @@ int main() conn->local = cw_itemstore_create(); -// setup_conf(conn); + setup_conf(conn); cw_itemstore_t board_data = cw_itemstore_create();