From 8eeaa28ffb9dcb2e38f442277caabe6220ed50da Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Fri, 17 Apr 2015 05:38:44 +0000 Subject: [PATCH] json stuff added. FossilOrigin-Name: 018a7253083e6a480bfcf282d892d13707f49353136106b336ec1ffbf3747614 --- src/capwap/Makefile | 10 +- src/capwap/capwap.h | 2 + src/contrib/jsmn/example/.simple.c.swp | Bin 12288 -> 0 bytes src/wtp/Makefile | 4 +- src/wtp/cfg.c | 179 +++++++++++++++++++++++++ src/wtp/image_update.c | 55 ++++++++ src/wtp/wtp_main.c | 2 +- 7 files changed, 248 insertions(+), 4 deletions(-) delete mode 100644 src/contrib/jsmn/example/.simple.c.swp create mode 100644 src/wtp/cfg.c create mode 100644 src/wtp/image_update.c 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 5b6aa972568ee3bae361134638b3f7ed24f0c263..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2&yN&E6vqog#6eLb7mtrtH}m@k7=c}uWJM*Qu#si`k)3hVGhMS&vol?7b@jr! zAkpaAgo793#fv9TMocg!CK3)3{{Rw?M!gv0Q7`zd>Khr-PK*M-}}CL zud>;0*WWmHg7#ORXZStI*!FsP@$im!wq46Jwm&(r&kWz~r;|3XoLH#r-}l17J3afp zF<4ux`5iN(7OPIJBSWo3yVj3~VU3^lhtU8xggI0@ce3T~IR%^oTUB5e+qbt-H?yAc z_R#L97Po4^J?|873OEIv0!{&^fK$LJ;1qBQJirR*XdAl#{~yX?cr`n2yXBZ&x`R`| zDc}@v3OEIv0!{&^fK$LJ;1qBQI0c*n51;~mz}WP|jD5HR&g1|8qrd)^&?jQtI+ zg3I7ra0z@2mcSuU2Nh5THy&l|SMW8s0FHw^An^N6#y$fa904<6JGh!->>`Lj4^+Xk zU?=$P5yrj*Uw{qJ0#Ae8;9qF-7q|pI1sB05;3Hsk`vAC~Q@|dE%he2gLvuunLAH-wd=E&HCXRFv;yxIRODIyC7E21=zu z>SyYX`BqSb37?@_k>2E##!V|qCQ(dUQk#<>lCPA%PO?iezAOw^Vk*{btX;}yq3ZRB z)1F!Qed6Tu+^JJ@Z)firX#a<|m>r+wfXt@=~X~ z0?i_}%(^I*Y|yvKtWCiGb6cUsV=rw^sd+L>>di?et+`Z_Awoan!&%4?NF#xkgM5K{ zTyZnD!Zn4-kSo!lHGh!sRGoW_DiOi`hcp)qMY!dl{2&lo$j~1Q)~VCuomD~(bdP6Y zh?uy*r6NzOgnNXQ<#l~5b#F@{`o_Ea4{|Z)YRfSus7qul43Y>bL$ zRv!$h$rx;z36xo5h6Kt?;gA&o~EWK4`&J^xneuh*fL84`JH(w~VffM)SG zC~5^;Cfqi8#M+G%4@5`%ZG6>k?#xj +#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();