Can send WTP images now and handle erros.

FossilOrigin-Name: 2b5d9206c2287a0e22f48c6c4f12407ebc07b1b2b03f38be46a1c47d92127950
This commit is contained in:
7u83@mail.ru
2015-03-17 00:10:08 +00:00
parent 17bb8697eb
commit 982fcf93a2
17 changed files with 233 additions and 128 deletions

View File

@ -51,7 +51,11 @@
# image_dir
# Directorie where firmware images are stored
#
# Default
# image_dir=/tftpboot

View File

@ -104,6 +104,8 @@ int conf_lwapp=1;
char * conf_lw_control_port=0;
#endif
char * conf_image_dir=0;
char * conf_control_port=0;
@ -271,10 +273,11 @@ static int init_version()
bstr_replace(&conf_cisco_hardware_version,bstr_create_from_cfgstr((char*)conf_cisco_hardware_version));
/* Cisco software version */
/*
if (!conf_cisco_software_version)
conf_cisco_software_version=(bstr_t)strdup(CONF_DEFAULT_CISCO_SOFTWARE_VERSION);
bstr_replace(&conf_cisco_software_version,bstr_create_from_cfgstr((char*)conf_cisco_software_version));
*/
@ -595,11 +598,10 @@ int read_config(const char * filename){
CFG_SIMPLE_STR("dtls_psk",&conf_dtls_psk),
CFG_SIMPLE_BOOL("dtls_verify_peer",&conf_dtls_verify_peer),
CFG_SIMPLE_BOOL("ipv4",&conf_ipv4),
CFG_SIMPLE_BOOL("ipv6",&conf_ipv6),
CFG_SIMPLE_STR("db_file",conf_db_file),
CFG_SIMPLE_STR("image_dir",&conf_image_dir),
CFG_END()
};
@ -663,6 +665,9 @@ int read_config(const char * filename){
if (!conf_sslcipher)
conf_sslcipher=CAPWAP_CIPHER;
if (!conf_image_dir)
conf_image_dir=CONF_DEFAULT_IMAGE_DIR;
init_listen_addrs();
init_mcast_groups();

View File

@ -60,6 +60,7 @@
#define CONF_DEFAULT_CISCO_HARDWARE_VERSION ".x01000001"
#define CONF_DEFAULT_CISCO_SOFTWARE_VERSION ".x06006E00"
#define CONF_DEFAULT_IMAGE_DIR "/tftpboot"
#ifndef CONF_DEFAULT_CONTROL_PORT
@ -111,7 +112,7 @@ extern char * conf_dtls_psk;
extern int conf_dtls_verify_peer;
char * conf_sslcipher;
extern char *conf_image_dir;
extern char ** conf_mcast_groups;

View File

@ -35,7 +35,10 @@
/* macro to convert our client ip to a string */
#define CLIENT_IP (sock_addrtostr((struct sockaddr*)&wtpman->conn->addr, (char[64]){0},64))
//#define CLIENT_IP (sock_addrtostr((struct sockaddr*)&wtpman->conn->addr, (char[64]){0},64))
#define CLIENT_IP (sock_addr2str(&wtpman->conn->addr))
/*
int conn_handle_echo_request(void * d)
@ -216,7 +219,7 @@ int wtpman_handle_request(void *p)
}
void send_image_file(struct conn * conn,const char * filename)
void usend_image_file(struct conn * conn,const char * filename)
{
FILE * infile;
infile = fopen(filename,"rb");
@ -234,7 +237,7 @@ void send_image_file(struct conn * conn,const char * filename)
struct cwrmsg * cwrmsg;
uint8_t buffer[1024];
struct image_data data;
struct cwimage_data data;
data.data = buffer;
@ -441,7 +444,7 @@ static void wtpman_run_run(void *arg)
cwmsg_addelem(&conn->req_msg,CWMSGELEM_WTP_NAME,(uint8_t*)"Tube7u83",strlen("Tube7u83")+1);
cwmsg_addelem(&conn->req_msg,CWMSGELEM_LOCATION_DATA,(uint8_t*)"Berlin",strlen("Berlin")+1);
cwmsg_addelem_vendor_specific_payload(&conn->req_msg,CW_VENDOR_ID_CISCO,CWVENDOR_CISCO_RAD_NAME,(uint8_t*)"NudelSuppe",strlen("NudelSuppe"));
// cwmsg_addelem_vendor_specific_payload(&conn->req_msg,CW_VENDOR_ID_CISCO,CWVENDOR_CISCO_RAD_NAME,(uint8_t*)"Schlumpf",strlen("Schlumpf"));
cwrmsg = conn_send_request(conn);
@ -580,6 +583,42 @@ printf("Slept befor join resp\n");
}
static int wtpman_send_image_file(struct wtpman * wtpman,struct cwrmsg * cwrmsg)
{
struct cwimage_data data;
memset(&data,0,sizeof(struct cwimage_data));
uint8_t id [1025];
data.identifier=id;
char filename[2048];
id[0]=0;
cw_read_image_data_request(&data,cwrmsg->msgelems,cwrmsg->msgelems_len);
if (!strlen(id)){
cw_dbg(DBG_CW_MSG_ERR, "No image identifier in image data request");
cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_FAILURE);
return 0;
}
sprintf(filename,"%s/%s",conf_image_dir,id);
FILE *infile;
infile = fopen(filename, "rb");
if (infile) {
cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS);
cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&wtpman->conn->addr));
cw_send_image_file(wtpman->conn, infile);
return 1;
}
cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno));
cw_send_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_FAILURE);
return 0;
}
static void wtpman_run(void *arg)
{
struct wtpman * wtpman = (struct wtpman *)arg;
@ -613,17 +652,36 @@ static void wtpman_run(void *arg)
/* here the WTP has joined, now image update or change state event */
/* here the WTP has joined, now we assume an image data request
or an configuration status request. Nothing else. i
State is Image update
*/
do {
int cfg_status_msgs[] = { CWMSG_IMAGE_DATA_REQUEST, CWMSG_CONFIGURATION_STATUS_REQUEST, -1 };
cwrmsg = conn_wait_for_request(wtpman->conn, cfg_status_msgs, timer);
if (!cwrmsg){
cw_dbg(DBG_CW_MSG_ERR,"No conf status or img data request from %s after %d seconds, WTP died.",
sock_addr2str(&wtpman->conn->addr),wtpman->conn->wait_join);
wtpman_remove(wtpman);
return;
}
/* Image data request, the WTP wants an update */
if (cwrmsg->type==CWMSG_IMAGE_DATA_REQUEST){
int rc = wtpman_send_image_file(wtpman,cwrmsg);
if (rc ){
wtpman_remove(wtpman);
return;
}
}
} while (cwrmsg->type != CWMSG_CONFIGURATION_STATUS_REQUEST);
int cfg_status_msgs[] = { CWMSG_IMAGE_DATA_REQUEST, CWMSG_CONFIGURATION_STATUS_REQUEST, -1 };
cwrmsg = conn_wait_for_request(wtpman->conn, cfg_status_msgs, timer);
if (!cwrmsg){
cw_dbg(DBG_CW_MSG_ERR,"No config uration status request from %s after %d seconds, WTP died.",
sock_addr2str(&wtpman->conn->addr),wtpman->conn->wait_join);
wtpman_remove(wtpman);
return;
}
printf("Have Masseg %d\n",cwrmsg->type);
cwread_configuration_status_request(&wtpman->wtpinfo,cwrmsg->msgelems, cwrmsg->msgelems_len);
int result_code=0;
@ -655,12 +713,12 @@ printf("Done\n");
break;
case CWMSG_IMAGE_DATA_REQUEST:
printf("Image update\n!");
cwread_image_data_request(0,cwrmsg->msgelems,cwrmsg->msgelems_len);
//cwread_image_data_request(0,cwrmsg->msgelems,cwrmsg->msgelems_len);
cwsend_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS);
//cwsend_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS);
send_image_file(wtpman->conn,"/tftpboot/c1130-k9w7-tar.default");
//send_image_file(wtpman->conn,"/tftpboot/c1130-k9w7-tar.default");
// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w7-tar.123-8.JEA3.tar");
// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w8-tar.124-25e.JAP.tar");