Inital commit

FossilOrigin-Name: 003aa54730314aa816e353aa0643bedce00f79ef60dc8baeb346611481a74d8e
This commit is contained in:
7u83@mail.ru 2015-03-16 20:41:24 +00:00
parent 615d98aaee
commit e8723340c8
4 changed files with 209 additions and 0 deletions

View File

@ -0,0 +1,38 @@
/**
*@file
*@brief conn_send_request
*/
#include "capwap.h"
#include "cw_util.h"
#include "cw_log.h"
/**
* Send a request message and wait for response
*/
struct cwrmsg * conn_send_request(struct conn * conn)
{
int i;
struct cwrmsg * cwrmsg;
struct cwmsg * cwmsg = &conn->req_msg;
for (i=0; i<conn->max_retransmit; i++) {
time_t r_timer = cw_timer_start(conn->retransmit_interval);
if (i!=0)
cw_dbg(DBG_CW_MSG_ERR,"Retransmitting message, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum);
conn_send_cwmsg(conn,&conn->req_msg);
cwrmsg = conn_wait_for_message(conn,r_timer);
if (cwrmsg){
if (cwrmsg->type == conn->req_msg.type+1){
return cwrmsg;
}
}
}
cw_dbg(DBG_CW_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum);
return 0;
}

View File

@ -0,0 +1,37 @@
#include "conn.h"
#include "cw_util.h"
struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer)
{
struct cwrmsg * cwrmsg;
while (!cw_timer_timeout(timer)){
cwrmsg = conn_get_message(conn);
if (!cwrmsg){
if (!conn_is_error(conn))
continue;
return 0;
}
if (cwrmsg->type & 1){
if (conn->request_handler){
if (conn->request_handler(conn->request_handler_param))
continue;
}
}
return cwrmsg;
}
return 0;
}

View File

@ -0,0 +1,43 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief: Generic handler for echo requests
*/
#include "capwap.h"
/**
* Handles an echo request
* @param d points to a #conn structure
* @return 0=ok\nother Error code.
*
* This function is used as callback function in conjunction
* with cw_wait_for_request
*/
int cw_handle_echo_request(void * d)
{
struct conn * conn = (struct conn *)d;
struct cwrmsg * cwrmsg = &conn->cwrmsg;
cw_send_echo_response(conn,cwrmsg->seqnum,0);
return 0;
}

View File

@ -0,0 +1,91 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @breif send image file
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "capwap.h"
#include "lwapp.h"
#include "sock.h"
#include "cw_log.h"
/**
* Send an image file to an AP
*
*/
void cw_send_image_file(struct conn *conn, const char *filename)
{
FILE *infile;
infile = fopen(filename, "rb");
if (!infile) {
cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno));
return;
}
cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&conn->addr));
struct cwrmsg *cwrmsg;
uint8_t buffer[1024]; /* buffer MUST be 1024 */
struct image_data data;
data.data = buffer;
conn->request_handler = cw_handle_echo_request;
conn->request_handler_param = conn;
int bl = 0;
do {
data.len = fread(buffer, 1, sizeof(buffer), infile);
if (feof(infile))
data.type = 2;
else
data.type = 1;
cw_dbg(DBG_CW_IMG_DTL, "Sending img data request, block=%d, len=%d, ch=%d\n", bl,
data.len, lw_checksum(data.data, data.len));
bl++;
conn_prepare_image_data_request(conn, &data, 0);
cwrmsg = conn_send_request(conn);
if (!cwrmsg) {
cw_log(LOG_ERR,"Error sneding image file to %s",sock_addr2str(&conn->addr));
break;
}
} while (!feof(infile));
fclose(infile);
}