Inital ...
FossilOrigin-Name: 6a4d9c2728a7eaff7122cf7ef069b90fe4c75ad863d2b38b6eaffc91bef55a92
This commit is contained in:
parent
73aba62d2b
commit
befb69ea2b
66
src/capwap/cw_in_check_img_data_req_wtp.c
Normal file
66
src/capwap/cw_in_check_img_data_req_wtp.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "capwap.h"
|
||||
#include "dbg.h"
|
||||
#include "log.h"
|
||||
#include "capwap_items.h"
|
||||
|
||||
|
||||
int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
int len)
|
||||
{
|
||||
|
||||
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
|
||||
conn->capwap_state=CW_STATE_IMAGE_DATA;
|
||||
return 0;
|
||||
|
||||
return CW_RESULT_IMAGE_DATA_ERROR;
|
||||
return 0;
|
||||
|
||||
|
||||
/* Check for mandatory elements */
|
||||
cw_action_in_t * mlist[60];
|
||||
int n = cw_check_missing_mand(mlist,conn,a);
|
||||
if (n) {
|
||||
cw_dbg_missing_mand(DBG_ELEM,conn,mlist,n,a);
|
||||
conn->capwap_state=CW_STATE_JOIN;
|
||||
return CW_RESULT_MISSING_MAND_ELEM;
|
||||
}
|
||||
|
||||
|
||||
struct cw_item *i = cw_itemstore_get(conn->incomming,CW_ITEM_IMAGE_IDENTIFIER);
|
||||
if (i) {
|
||||
uint32_t vendor_id = vendorstr_get_vendor_id(i->data);
|
||||
|
||||
const char * image_dir;
|
||||
image_dir = cw_itemstore_get_str(conn->local,CW_ITEM_AC_IMAGE_DIR);
|
||||
if ( !image_dir )
|
||||
image_dir="./img/"; //XXX
|
||||
|
||||
char * image_filename = malloc(6+vendorstr_len(i->data)+1+strlen(image_dir));
|
||||
if (!image_filename)
|
||||
return CW_RESULT_IMAGE_DATA_ERROR;
|
||||
|
||||
sprintf(image_filename,"%s%04X/%s",image_dir,vendor_id,vendorstr_data(i->data));
|
||||
|
||||
|
||||
FILE *infile = fopen(image_filename,"rb");
|
||||
if (!infile){
|
||||
cw_log(LOG_WARNING,"Can't open image file: %s - %s - requestet by WTP",
|
||||
image_filename,strerror(errno));
|
||||
free(image_filename);
|
||||
return CW_RESULT_IMAGE_DATA_ERROR;
|
||||
}
|
||||
|
||||
cw_itemstore_set_str(conn->outgoing,CW_ITEM_IMAGE_FILENAME,image_filename);
|
||||
cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
|
||||
conn->capwap_state=CW_STATE_IMAGE_DATA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return CW_RESULT_IMAGE_DATA_ERROR;
|
||||
|
||||
}
|
34
src/capwap/cw_in_check_img_data_resp.c
Normal file
34
src/capwap/cw_in_check_img_data_resp.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "capwap.h"
|
||||
#include "dbg.h"
|
||||
#include "log.h"
|
||||
#include "capwap_items.h"
|
||||
|
||||
|
||||
int cw_in_check_img_data_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
||||
int len)
|
||||
{
|
||||
cw_action_in_t * mlist[60];
|
||||
|
||||
/* Check for mandatory elements */
|
||||
int n = cw_check_missing_mand(mlist,conn,a);
|
||||
if (n) {
|
||||
cw_dbg_missing_mand(DBG_ELEM,conn,mlist,n,a);
|
||||
conn->capwap_state=CW_STATE_JOIN;
|
||||
errno=EAGAIN;
|
||||
return -1; //CW_RESULT_MISSING_MAND_ELEM;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cw_item_t * iresult = cw_itemstore_get(conn->incomming, CW_ITEM_RESULT_CODE);
|
||||
|
||||
if ( iresult ) {
|
||||
return iresult->dword;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
49
src/capwap/cw_out_image_data.c
Normal file
49
src/capwap/cw_out_image_data.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "capwap.h"
|
||||
#include "capwap_items.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
|
||||
#define BLOCK_SIZE 1024
|
||||
|
||||
|
||||
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst) // ,struct cw_item * item)
|
||||
{
|
||||
cw_item_t * item = cw_itemstore_get(conn->outgoing,CW_ITEM_IMAGE_FILEHANDLE);
|
||||
if (!item) {
|
||||
cw_log(LOG_ERR,"Can't put element Image Data, no image filehandle found");
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *infile = item->data;
|
||||
|
||||
|
||||
int bytes = fread(dst+5,1,BLOCK_SIZE,infile);
|
||||
|
||||
if (feof(infile)){
|
||||
if (ferror(infile)){
|
||||
cw_log(LOG_ERROR,"Aborting image data transfer: %s",strerror(errno));
|
||||
bytes=1;
|
||||
cw_put_byte(dst+4,5);
|
||||
bytes=0;
|
||||
|
||||
}
|
||||
else{
|
||||
/* Last image block */
|
||||
cw_put_byte(dst+4,2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
cw_put_byte(dst+4,1);
|
||||
}
|
||||
|
||||
|
||||
return bytes+1 + cw_put_elem_hdr(dst,a->elem_id,bytes+1);
|
||||
|
||||
}
|
||||
|
49
src/capwap/cw_out_wtp_descriptor.c
Normal file
49
src/capwap/cw_out_wtp_descriptor.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "log.h"
|
||||
#include "conn.h"
|
||||
|
||||
#include "itemstore.h"
|
||||
#include "capwap_items.h"
|
||||
#include "capwap.h"
|
||||
|
||||
|
||||
static int cw_put_enc_subelems(uint8_t *dst)
|
||||
{
|
||||
int n=2;
|
||||
|
||||
dst+=cw_put_byte(dst,n);
|
||||
|
||||
int i;
|
||||
for (i=0; i<n; i++){
|
||||
dst+=cw_put_byte(dst,0);
|
||||
dst+=cw_put_byte(dst,0);
|
||||
dst+=cw_put_byte(dst,0);
|
||||
}
|
||||
|
||||
return 3*n+1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
|
||||
{
|
||||
// XXX Dummy WTP Descriptor Header
|
||||
uint8_t *d = dst+4;
|
||||
|
||||
d+=cw_put_byte(d,2);
|
||||
d+=cw_put_byte(d,0);
|
||||
d+=cw_put_enc_subelems(dst);
|
||||
|
||||
cw_item_t * i;
|
||||
i = cw_itemstore_get(conn->outgoing,CW_ITEM_WTP_HARDWARE_VERSION);
|
||||
if ( i ) {
|
||||
d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->data);
|
||||
}
|
||||
else {
|
||||
cw_log(LOG_ERR, "Can't send hard version in WTP descriptor, not set.");
|
||||
}
|
||||
|
||||
|
||||
int len = d-dst-4;
|
||||
return len + cw_put_elem_hdr(dst,a->elem_id,len);
|
||||
|
||||
}
|
13
src/capwap/cw_strlist_get_id.c
Normal file
13
src/capwap/cw_strlist_get_id.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "strlist.h"
|
||||
|
||||
int cw_strlist_get_id(struct cw_str *s,const char *str)
|
||||
{
|
||||
while ( s->id!=CW_STR_STOP){
|
||||
if (strcmp(s->str,str)==0)
|
||||
break;
|
||||
s++;
|
||||
}
|
||||
return s->id;
|
||||
}
|
Loading…
Reference in New Issue
Block a user