json stuff added.
FossilOrigin-Name: 018a7253083e6a480bfcf282d892d13707f49353136106b336ec1ffbf3747614
This commit is contained in:
parent
57cd0a11b1
commit
8eeaa28ffb
@ -71,6 +71,13 @@ UTILOBJS= \
|
|||||||
cw_format_version.o \
|
cw_format_version.o \
|
||||||
send.o
|
send.o
|
||||||
|
|
||||||
|
MAVLOBJS= \
|
||||||
|
mavl.o \
|
||||||
|
mavl_del.o \
|
||||||
|
mavl_add.o \
|
||||||
|
mavl_create.o\
|
||||||
|
utf8.o
|
||||||
|
|
||||||
# cw_foreach_msgelem.o \
|
# cw_foreach_msgelem.o \
|
||||||
|
|
||||||
|
|
||||||
@ -318,7 +325,8 @@ OBJS=$(CONNOBJS) $(FRAGOBJS) $(SOCKOBJS) $(CAPWAPOBJS) $(WTPINFOOBJS) \
|
|||||||
$(LOGOBJS) $(UTILOBJS) $(DTLSOBJS) $(BSTROBJS) \
|
$(LOGOBJS) $(UTILOBJS) $(DTLSOBJS) $(BSTROBJS) \
|
||||||
$(LWAPPOBJS) \
|
$(LWAPPOBJS) \
|
||||||
$(LWAPPCISCOOBJS) \
|
$(LWAPPCISCOOBJS) \
|
||||||
$(CWACTION)
|
$(CWACTION) \
|
||||||
|
$(MAVLOBJS)
|
||||||
|
|
||||||
#include $(OBJS:.o=.d)
|
#include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
@ -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_send_request(struct conn *conn, int msg_id);
|
||||||
|
int cw_is_utf8(unsigned char *str, size_t len);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Binary file not shown.
@ -20,8 +20,8 @@ ifndef ARCH
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
#CFLAGS += -O0 -Wall -g
|
CFLAGS += -O0 -Wall -g
|
||||||
CFLAGS += -Os -Wall
|
#CFLAGS += -Os -Wall
|
||||||
LDFLAGS += -L../contrib/jsmn -L../../src/capwap/$(ARCH)
|
LDFLAGS += -L../contrib/jsmn -L../../src/capwap/$(ARCH)
|
||||||
|
|
||||||
|
|
||||||
|
179
src/wtp/cfg.c
Normal file
179
src/wtp/cfg.c
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
#include "capwap/itemstore.h"
|
||||||
|
#include "capwap/capwap_items.h"
|
||||||
|
#include "capwap/conn.h"
|
||||||
|
#include "capwap/bstr.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
55
src/wtp/image_update.c
Normal file
55
src/wtp/image_update.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#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;
|
||||||
|
}
|
@ -66,7 +66,7 @@ int main()
|
|||||||
conn->local = cw_itemstore_create();
|
conn->local = cw_itemstore_create();
|
||||||
|
|
||||||
|
|
||||||
// setup_conf(conn);
|
setup_conf(conn);
|
||||||
|
|
||||||
|
|
||||||
cw_itemstore_t board_data = cw_itemstore_create();
|
cw_itemstore_t board_data = cw_itemstore_create();
|
||||||
|
Loading…
Reference in New Issue
Block a user