From e8723340c80d10c61654ee15e602d6db9eaf6a15 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 16 Mar 2015 20:41:24 +0000 Subject: [PATCH] Inital commit FossilOrigin-Name: 003aa54730314aa816e353aa0643bedce00f79ef60dc8baeb346611481a74d8e --- src/capwap/conn_send_request.c | 38 ++++++++++++ src/capwap/conn_wait_for_message.c | 37 ++++++++++++ src/capwap/cw_handle_echo_request.c | 43 ++++++++++++++ src/capwap/cw_send_image_file.c | 91 +++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+) create mode 100644 src/capwap/conn_send_request.c create mode 100644 src/capwap/conn_wait_for_message.c create mode 100644 src/capwap/cw_handle_echo_request.c create mode 100644 src/capwap/cw_send_image_file.c diff --git a/src/capwap/conn_send_request.c b/src/capwap/conn_send_request.c new file mode 100644 index 00000000..085d02d9 --- /dev/null +++ b/src/capwap/conn_send_request.c @@ -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; imax_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; +} + diff --git a/src/capwap/conn_wait_for_message.c b/src/capwap/conn_wait_for_message.c new file mode 100644 index 00000000..7c00aa95 --- /dev/null +++ b/src/capwap/conn_wait_for_message.c @@ -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; +} + + diff --git a/src/capwap/cw_handle_echo_request.c b/src/capwap/cw_handle_echo_request.c new file mode 100644 index 00000000..fb3291df --- /dev/null +++ b/src/capwap/cw_handle_echo_request.c @@ -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 . + +*/ + + +/** + * @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; +} + + diff --git a/src/capwap/cw_send_image_file.c b/src/capwap/cw_send_image_file.c new file mode 100644 index 00000000..5ab77c33 --- /dev/null +++ b/src/capwap/cw_send_image_file.c @@ -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 . + +*/ + + +/** + * @file + * @breif send image file + */ + +#include +#include +#include + + +#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); +}