2016-03-27 09:55:49 +02:00
|
|
|
/*
|
|
|
|
This file is part of actube.
|
|
|
|
|
|
|
|
actube 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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2016-03-27 10:14:52 +02:00
|
|
|
#include <errno.h>
|
2018-04-01 18:32:13 +02:00
|
|
|
#include <unistd.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap.h"
|
|
|
|
#include "cw/sock.h"
|
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/timer.h"
|
2016-03-27 10:14:52 +02:00
|
|
|
#include "cw/cw.h"
|
2018-03-17 18:01:17 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dtls.h"
|
|
|
|
#include "cw/dbg.h"
|
2016-03-27 10:14:52 +02:00
|
|
|
#include "cw/conn.h"
|
2016-04-10 16:04:58 +02:00
|
|
|
#include "cw/format.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2016-03-27 10:14:52 +02:00
|
|
|
#include "ac.h"
|
|
|
|
#include "conf.h"
|
2016-03-27 04:32:36 +02:00
|
|
|
#include "db.h"
|
2016-03-27 10:14:52 +02:00
|
|
|
#include "socklist.h"
|
|
|
|
#include "wtpman.h"
|
|
|
|
#include "wtplist.h"
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "cw/ktv.h"
|
2014-08-24 15:07:30 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
#include "actube.h"
|
|
|
|
|
2016-03-27 09:55:49 +02:00
|
|
|
static void reset_echointerval_timer(struct wtpman *wtpman)
|
2014-08-24 15:07:30 +02:00
|
|
|
{
|
2018-04-02 01:39:08 +02:00
|
|
|
/* char sock_buf[SOCK_ADDR_BUFSIZE];*/
|
2018-03-17 18:01:17 +01:00
|
|
|
/* uint16_t ct = mbag_get_word(wtpman->conn->local, CW_ITEM_CAPWAP_TIMERS,
|
2018-02-22 23:04:15 +01:00
|
|
|
CW_MAX_DISCOVERY_INTERVAL << 8 |
|
2016-03-27 09:55:49 +02:00
|
|
|
CAPWAP_ECHO_INTERVAL);
|
2018-03-17 18:01:17 +01:00
|
|
|
*/
|
2016-03-27 16:44:50 +02:00
|
|
|
/* start echinterval timer and put 2 seconds for "safety" on it */
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// wtpman->echointerval_timer = cw_timer_start(2+ (ct & 0xff));
|
|
|
|
// db_ping_wtp(sock_addr2str_p(&wtpman->conn->addr,sock_buf), conf_acname);
|
2016-03-27 16:44:50 +02:00
|
|
|
// cw_dbg(DBG_X, "Starting capwap timer: %d", wtpman->echointerval_timer);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2015-03-16 02:41:35 +01:00
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
}
|
2015-03-16 02:41:35 +01:00
|
|
|
|
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
static int msg_start_handler(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
|
|
|
int len, struct sockaddr *from)
|
|
|
|
{
|
|
|
|
struct wtpman *wtpman = conn->data;
|
|
|
|
reset_echointerval_timer(wtpman);
|
|
|
|
return 0;
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-04-12 07:32:05 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
static void wtpman_remove(struct wtpman *wtpman)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
wtplist_lock();
|
|
|
|
wtplist_remove(wtpman);
|
|
|
|
wtplist_unlock();
|
|
|
|
wtpman_destroy(wtpman);
|
|
|
|
}
|
|
|
|
|
2014-08-16 16:09:24 +02:00
|
|
|
|
2015-10-18 10:15:30 +02:00
|
|
|
|
2014-08-16 16:09:24 +02:00
|
|
|
static void wtpman_run_discovery(void *arg)
|
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
time_t timer = cw_timer_start(10);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
|
2018-04-03 07:35:55 +02:00
|
|
|
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
while (!cw_timer_timeout(timer)
|
2018-05-07 10:57:12 +02:00
|
|
|
&& wtpman->conn->capwap_state == CAPWAP_STATE_DISCOVERY) {
|
2018-04-02 01:39:08 +02:00
|
|
|
int rc;
|
|
|
|
rc = cw_read_messages(wtpman->conn);
|
|
|
|
if (cw_result_is_ok(rc)){
|
2018-05-07 10:57:12 +02:00
|
|
|
wtpman->conn->capwap_state=CAPWAP_STATE_JOIN;
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
cw_dbg(DBG_INFO,"Discovery has detected mods: %s %s",
|
2018-04-03 07:35:55 +02:00
|
|
|
wtpman->conn->cmod->name,wtpman->conn->bmod->name);
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
wtplist_lock();
|
|
|
|
discovery_cache_add(discovery_cache,(struct sockaddr*)&wtpman->conn->addr,
|
2018-04-03 07:35:55 +02:00
|
|
|
wtpman->conn->cmod,wtpman->conn->bmod);
|
2018-04-02 21:00:37 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
|
2018-04-02 01:39:08 +02:00
|
|
|
}
|
2015-03-31 08:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2014-08-16 15:13:40 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-04-01 18:32:13 +02:00
|
|
|
/*
|
2016-03-17 01:26:12 +01:00
|
|
|
int xprocess_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
2016-03-27 04:32:36 +02:00
|
|
|
struct sockaddr *from)
|
2016-03-17 01:26:12 +01:00
|
|
|
{
|
|
|
|
uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
|
|
|
|
uint32_t type = cw_get_msg_type(msgptr);
|
2016-03-27 04:32:36 +02:00
|
|
|
cw_log(LOG_ERR, "Hey: %d", type);
|
2018-02-23 13:59:36 +01:00
|
|
|
if (type == CAPWAP_MSG_DISCOVERY_REQUEST)
|
2018-02-23 20:14:10 +01:00
|
|
|
conn->capwap_state = CAPWAP_STATE_DISCOVERY;
|
2016-03-17 01:26:12 +01:00
|
|
|
|
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
return process_message(conn, rawmsg, rawlen, from);
|
2016-03-17 01:26:12 +01:00
|
|
|
}
|
2014-07-19 12:36:43 +02:00
|
|
|
|
2018-04-01 18:32:13 +02:00
|
|
|
*/
|
2014-08-22 08:21:38 +02:00
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
static int wtpman_dtls_setup(void *arg)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-04-03 23:35:09 +02:00
|
|
|
char cipherstr[512];
|
2018-05-05 00:36:19 +02:00
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
/* try to accept the connection */
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!dtls_accept(wtpman->conn)) {
|
2016-03-27 09:55:49 +02:00
|
|
|
cw_dbg(DBG_DTLS, "Error establishing DTLS session with %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str_p(&wtpman->conn->addr,sock_buf));
|
2014-08-24 11:10:46 +02:00
|
|
|
return 0;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2014-07-19 12:36:43 +02:00
|
|
|
|
2018-04-03 23:35:09 +02:00
|
|
|
cw_dbg(DBG_DTLS, "DTLS session established with %s, %s",
|
|
|
|
sock_addr2str_p(&wtpman->conn->addr,sock_buf), dtls_get_cipher(wtpman->conn,cipherstr));
|
2018-04-04 19:23:40 +02:00
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
static int wtpman_join(void *arg)
|
2014-08-24 11:10:46 +02:00
|
|
|
{
|
2018-04-02 01:39:08 +02:00
|
|
|
int rc;
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
2016-02-16 08:13:34 +01:00
|
|
|
struct conn *conn = wtpman->conn;
|
2018-05-05 00:36:19 +02:00
|
|
|
time_t timer, wait_join;
|
2015-04-26 16:08:44 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
cw_dbg(DBG_INFO, "Join State - %s", sock_addr2str(&conn->addr,sock_buf));
|
|
|
|
|
|
|
|
wait_join = cw_ktv_get_word(conn->global_cfg,"wait-join",CAPWAP_WAIT_JOIN);
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
timer = cw_timer_start(wait_join);
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CAPWAP_STATE_JOIN) {
|
2015-04-13 11:00:46 +02:00
|
|
|
rc = cw_read_messages(wtpman->conn);
|
2015-04-07 07:42:36 +02:00
|
|
|
if (rc < 0) {
|
2018-04-08 16:48:13 +02:00
|
|
|
if (errno == EAGAIN)
|
|
|
|
continue;
|
|
|
|
|
2015-04-05 20:27:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-05-05 00:36:19 +02:00
|
|
|
cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,
|
|
|
|
"-------------dump------------",
|
|
|
|
"DMP","---------end dump --------");
|
2015-04-05 02:07:59 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
if (rc != 0) {
|
|
|
|
cw_log(LOG_ERR, "Error joining WTP %s", cw_strerror(rc));
|
2015-04-13 11:00:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
if (wtpman->conn->capwap_state != CAPWAP_STATE_JOIN_COMPLETE) {
|
2015-04-07 07:42:36 +02:00
|
|
|
cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.",
|
2018-05-05 00:36:19 +02:00
|
|
|
sock_addr2str(&wtpman->conn->addr,sock_buf), wait_join);
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
return 0;
|
2014-08-16 15:13:40 +02:00
|
|
|
}
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
return 1;
|
2014-08-16 10:10:00 +02:00
|
|
|
|
2014-08-16 15:13:40 +02:00
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
static void wtpman_image_data(struct wtpman *wtpman)
|
|
|
|
{
|
2018-03-17 18:01:17 +01:00
|
|
|
/* char sock_buf[SOCK_ADDR_BUFSIZE];
|
2016-02-16 08:13:34 +01:00
|
|
|
struct conn *conn = wtpman->conn;
|
|
|
|
|
2018-03-17 18:01:17 +01:00
|
|
|
// Image upload
|
2016-02-16 08:13:34 +01:00
|
|
|
const char *filename = mbag_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME, NULL);
|
|
|
|
if (!filename) {
|
|
|
|
cw_log(LOG_ERR,
|
|
|
|
"Can't send image to %s. No Image Filename Item found.",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr,sock_buf));
|
2016-02-16 08:13:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
cw_dbg(DBG_INFO, "Sending image file '%s' to '%s'.", filename,
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr,sock_buf));
|
2016-02-16 08:13:34 +01:00
|
|
|
FILE *infile = fopen(filename, "rb");
|
|
|
|
if (infile == NULL) {
|
|
|
|
cw_log(LOG_ERR, "Can't open image %s: %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr,sock_buf), strerror(errno));
|
2016-02-16 08:13:34 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-04-26 12:36:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
CW_CLOCK_DEFINE(clk);
|
|
|
|
cw_clock_start(&clk);
|
2015-04-26 12:36:53 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
mbag_item_t *eof = mbag_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE,
|
|
|
|
infile);
|
2015-04-26 12:36:53 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
int rc = 0;
|
|
|
|
while (conn->capwap_state == CW_STATE_IMAGE_DATA && rc == 0 && eof != NULL) {
|
2018-03-05 10:06:18 +01:00
|
|
|
rc = cw_send_request(conn, CAPWAP_MSG_IMAGE_DATA_REQUEST);
|
2016-02-16 08:13:34 +01:00
|
|
|
eof = mbag_get(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE);
|
|
|
|
}
|
2015-04-26 12:36:53 +02:00
|
|
|
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
if (rc) {
|
|
|
|
cw_log(LOG_ERR, "Error sending image to %s: %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&conn->addr,sock_buf), cw_strrc(rc));
|
2016-02-16 08:13:34 +01:00
|
|
|
} else {
|
|
|
|
cw_dbg(DBG_INFO, "Image '%s' sucessful sent to %s in %0.1f seconds.",
|
2018-03-05 12:23:16 +01:00
|
|
|
filename, sock_addr2str(&conn->addr,sock_buf), cw_clock_stop(&clk));
|
2016-02-16 08:13:34 +01:00
|
|
|
conn->capwap_state = CW_STATE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(infile);
|
|
|
|
wtpman_remove(wtpman);
|
2018-03-17 18:01:17 +01:00
|
|
|
*/
|
2015-04-26 12:36:53 +02:00
|
|
|
|
2016-04-02 10:23:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-12 07:32:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
void * wtpman_run_data(void *wtpman_arg)
|
2016-03-27 04:32:36 +02:00
|
|
|
{
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2018-04-02 01:39:08 +02:00
|
|
|
/*
|
2016-03-27 04:32:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) wtpman_arg;
|
|
|
|
struct conn *conn = wtpman->conn;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t data[1001];
|
|
|
|
memset(data, 0, 1000);
|
|
|
|
|
2016-04-02 09:05:07 +02:00
|
|
|
cw_log(LOG_ERR, "I am the data thread**********************************************************************\n");
|
2016-03-27 04:32:36 +02:00
|
|
|
while (1) {
|
|
|
|
sleep(5);
|
2018-04-02 01:39:08 +02:00
|
|
|
/ // conn->write_data(conn, data, 100); /
|
2016-04-02 09:05:07 +02:00
|
|
|
cw_log(LOG_ERR, "O was the data thread***********************************************************\n");
|
2016-03-27 04:32:36 +02:00
|
|
|
}
|
2018-04-02 01:39:08 +02:00
|
|
|
*/
|
2016-03-27 04:32:36 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
int cw_run_state_machine(struct conn * conn, time_t *timer)
|
|
|
|
{
|
|
|
|
|
|
|
|
int timerval;
|
|
|
|
cw_StateMachineState_t search, *result;
|
|
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
search.state = conn->capwap_state;
|
|
|
|
search.prevstate = conn->capwap_prevstate;
|
|
|
|
result = mavl_get(conn->msgset->state_machine,&search);
|
|
|
|
|
|
|
|
cw_dbg(DBG_STATE,"State transition: [%s -> %s]",
|
|
|
|
cw_strstate(conn->capwap_prevstate),
|
|
|
|
cw_strstate(conn->capwap_state)
|
|
|
|
);
|
|
|
|
if (result == NULL){
|
|
|
|
cw_log(LOG_ERR,"State not found");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (result->jump_state){
|
|
|
|
conn->capwap_state = result->jump_state;
|
|
|
|
conn->capwap_prevstate = result->jump_prevstate;
|
|
|
|
|
|
|
|
cw_dbg(DBG_STATE,"Jump to state: [%s->%s]",
|
|
|
|
cw_strstate(conn->capwap_prevstate),
|
|
|
|
cw_strstate(conn->capwap_state));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result->dbgmsg){
|
|
|
|
cw_dbg(DBG_STATE,"%s",result->dbgmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result->timer_key){
|
|
|
|
timerval = cw_ktv_get_word(conn->local_cfg,result->timer_key,result->timer_default);
|
|
|
|
*timer = cw_timer_start(timerval);
|
|
|
|
cw_dbg(DBG_STATE,"Starting timer: [%s] - %d seconds.",result->timer_key,timerval);
|
|
|
|
}
|
|
|
|
return result->retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
/*#define CW_TRANSITION(prestate,state) (prestate<<16|state)*/
|
2016-04-12 07:32:05 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
static void * wtpman_main(void *arg)
|
2014-08-24 15:07:30 +02:00
|
|
|
{
|
2018-04-03 07:35:55 +02:00
|
|
|
mavl_t r;
|
2018-04-02 01:39:08 +02:00
|
|
|
int rc ;
|
|
|
|
time_t timer;
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2018-04-02 01:39:08 +02:00
|
|
|
struct conn *conn;
|
2018-05-05 00:36:19 +02:00
|
|
|
int last_state;
|
2015-04-26 12:36:53 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
2014-08-25 07:56:14 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn->seqnum = 0;
|
2018-04-02 01:39:08 +02:00
|
|
|
conn = wtpman->conn;
|
2015-04-26 12:36:53 +02:00
|
|
|
|
2018-04-03 07:35:55 +02:00
|
|
|
wtpman->conn->remote_cfg = cw_ktv_create();
|
2018-05-05 00:36:19 +02:00
|
|
|
|
2018-04-03 07:35:55 +02:00
|
|
|
|
2018-04-02 01:39:08 +02:00
|
|
|
/* We were invoked with an unencrypted packet,
|
|
|
|
* so assume, it is a discovery request */
|
|
|
|
if (!wtpman->dtlsmode){
|
|
|
|
wtpman_run_discovery(arg);
|
2018-04-02 21:00:37 +02:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return NULL;
|
2018-04-02 01:39:08 +02:00
|
|
|
}
|
2016-04-12 07:32:05 +02:00
|
|
|
|
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
/* reject connections to our multi- or broadcast sockets */
|
2018-04-02 01:39:08 +02:00
|
|
|
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
|
|
|
cw_dbg(DBG_DTLS,"Reject multi");
|
2018-05-05 00:36:19 +02:00
|
|
|
wtpman_remove(wtpman);
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
2018-05-05 00:36:19 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_state = CAPWAP_STATE_DTLS_SETUP;
|
2018-05-05 00:36:19 +02:00
|
|
|
/* establish dtls session */
|
|
|
|
if (!wtpman_dtls_setup(wtpman)) {
|
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*last_state = conn->capwap_state;
|
|
|
|
conn->capwap_state = CAPWAP_STATE_JOIN;
|
|
|
|
*/
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_prevstate = CAPWAP_STATE_DTLS_SETUP;
|
|
|
|
conn->capwap_state = CAPWAP_STATE_JOIN;
|
2018-05-05 00:36:19 +02:00
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
|
|
|
|
int wait_join;
|
|
|
|
int wait_change_state;
|
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
|
|
|
|
if (!cw_run_state_machine(conn, &timer)){
|
|
|
|
cw_dbg(DBG_INFO,"WTP died");
|
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-07 23:29:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
/*
|
2018-05-05 00:36:19 +02:00
|
|
|
switch (conn->capwap_transition){
|
|
|
|
case CW_TRANSITION(CAPWAP_STATE_DTLS_SETUP, CAPWAP_STATE_JOIN):
|
|
|
|
{
|
2018-04-02 01:39:08 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
wait_join = cw_ktv_get_word(conn->global_cfg,"wait-join",CAPWAP_WAIT_JOIN);
|
|
|
|
timer = cw_timer_start(wait_join);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_JOIN):
|
|
|
|
{
|
|
|
|
char wtpname[CAPWAP_MAX_WTP_NAME_LEN];
|
|
|
|
cw_KTV_t * result;
|
|
|
|
result = cw_ktv_get(conn->remote_cfg,"wtp-name",NULL);
|
|
|
|
result->type->to_str(result,wtpname,CAPWAP_MAX_WTP_NAME_LEN);
|
|
|
|
cw_dbg(DBG_INFO, "WTP joined: '%s', IP %s.",
|
|
|
|
wtpname,
|
|
|
|
sock_addr2str(&conn->addr,sock_buf)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CW_TRANSITION(CAPWAP_STATE_JOIN,CAPWAP_STATE_TIMEOUT):
|
|
|
|
{
|
|
|
|
cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.",
|
|
|
|
sock_addr2str(&wtpman->conn->addr,sock_buf), wait_join);
|
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CW_TRANSITION(CAPWAP_STATE_JOIN, CAPWAP_STATE_CONFIGURE):
|
|
|
|
{
|
|
|
|
|
|
|
|
wait_change_state = cw_ktv_get_word(conn->global_cfg,
|
|
|
|
"capwap-timers/change-state-pending-timer",
|
|
|
|
CAPWAP_TIMER_CHANGE_STATE_PENDING_TIMER);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CW_TRANSITION(CAPWAP_STATE_CONFIGURE,CAPWAP_STATE_TIMEOUT):
|
|
|
|
{
|
|
|
|
cw_dbg(DBG_MSG_ERR, "No Change State Event Request %s after %d seconds, WTP died.",
|
|
|
|
sock_addr2str(&wtpman->conn->addr,sock_buf), wait_change_state);
|
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
}
|
2018-04-02 01:39:08 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
*/
|
2018-05-07 23:29:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
|
|
|
|
while (!cw_timer_timeout(timer)) {
|
2018-05-07 23:29:35 +02:00
|
|
|
if (conn->update_cfg != NULL){
|
|
|
|
mavl_t tmp;
|
2018-05-22 07:15:52 +02:00
|
|
|
|
|
|
|
|
2018-05-07 23:29:35 +02:00
|
|
|
tmp = conn->local_cfg;
|
|
|
|
|
2018-05-22 07:15:52 +02:00
|
|
|
mavl_merge(conn->default_cfg, conn->local_cfg);
|
|
|
|
mavl_merge(conn->default_cfg, conn->remote_cfg);
|
|
|
|
|
|
|
|
conn->local_cfg=conn->update_cfg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-07 23:29:35 +02:00
|
|
|
|
|
|
|
cw_dbg(DBG_INFO, "Updating WTP %s",sock_addr2str(&conn->addr,sock_buf));
|
|
|
|
|
|
|
|
rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST);
|
|
|
|
conn->update_cfg=NULL;
|
|
|
|
conn->local_cfg=tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
rc = cw_read_messages(wtpman->conn);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rc<0){
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_prevstate = conn->capwap_state;
|
|
|
|
conn->capwap_state = CAPWAP_STATE_TIMEOUT;
|
2018-05-05 00:36:19 +02:00
|
|
|
}
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
2018-05-05 00:36:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
|
|
|
|
/* dtls is established, goto join state */
|
2018-05-05 00:36:19 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_state = CAPWAP_STATE_JOIN;
|
2018-05-05 00:36:19 +02:00
|
|
|
if (!wtpman_join(wtpman)) {
|
2014-08-24 15:07:30 +02:00
|
|
|
wtpman_remove(wtpman);
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
cw_dbg(DBG_INFO, "WTP from %s has joined with session id: %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str_p(&conn->addr,sock_buf),
|
2016-04-10 16:04:58 +02:00
|
|
|
format_bin2hex(conn->session_id,16));
|
2018-04-08 16:48:13 +02:00
|
|
|
|
2016-04-10 16:04:58 +02:00
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
exit(0);
|
2016-04-10 16:04:58 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2016-04-12 07:32:05 +02:00
|
|
|
// cw_dbg(DBG_INFO, "Creating data thread");
|
|
|
|
// pthread_t thread;
|
|
|
|
// pthread_create(&thread, NULL, (void *) wtpman_run_data, (void *) wtpman);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2015-03-17 01:10:08 +01:00
|
|
|
/* here the WTP has joined, now we assume an image data request
|
2018-04-02 21:00:37 +02:00
|
|
|
or a configuration status request. Nothing else.
|
2015-04-07 07:42:36 +02:00
|
|
|
*/
|
|
|
|
|
2018-04-02 01:39:08 +02:00
|
|
|
rc = 0;
|
2015-04-11 19:00:51 +02:00
|
|
|
while (!cw_timer_timeout(timer)
|
2018-05-07 10:57:12 +02:00
|
|
|
&& wtpman->conn->capwap_state == CAPWAP_STATE_CONFIGURE) {
|
2015-04-11 19:00:51 +02:00
|
|
|
rc = cw_read_messages(wtpman->conn);
|
2015-04-07 07:42:36 +02:00
|
|
|
if (rc < 0) {
|
2015-04-11 19:00:51 +02:00
|
|
|
if (errno != EAGAIN)
|
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 07:45:45 +02:00
|
|
|
cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,"-------------dump------------","DMP","---------end dump --------");
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
if (!cw_result_is_ok(rc)) {
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc));
|
2015-04-26 12:36:53 +02:00
|
|
|
wtpman_remove(wtpman);
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2015-04-07 07:42:36 +02:00
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
|
2015-04-26 12:36:53 +02:00
|
|
|
wtpman_image_data(wtpman);
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2015-04-26 12:36:53 +02:00
|
|
|
}
|
2014-08-18 01:45:08 +02:00
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
|
2015-04-29 19:26:04 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_state = CAPWAP_STATE_RUN;
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2015-04-29 19:26:04 +02:00
|
|
|
// XXX testing ...
|
2016-03-27 16:44:50 +02:00
|
|
|
// DBGX("Cofig to sql", "");
|
2018-03-17 18:01:17 +01:00
|
|
|
// props_to_sql(conn,conn->incomming,0);
|
|
|
|
// radios_to_sql(conn);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2015-05-01 00:16:54 +02:00
|
|
|
|
2018-04-01 18:32:13 +02:00
|
|
|
/*conn->msg_end=msg_end_handler;*/
|
2016-03-27 10:14:52 +02:00
|
|
|
/* The main run loop */
|
2016-03-27 04:32:36 +02:00
|
|
|
reset_echointerval_timer(wtpman);
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
rc = 0;
|
2018-05-07 10:57:12 +02:00
|
|
|
while (wtpman->conn->capwap_state == CAPWAP_STATE_RUN) {
|
2015-04-26 12:36:53 +02:00
|
|
|
rc = cw_read_messages(wtpman->conn);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (errno != EAGAIN)
|
|
|
|
break;
|
2015-04-07 07:42:36 +02:00
|
|
|
}
|
2015-04-30 14:10:59 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// cw_dbg(DBG_X, "Time left: %d",
|
|
|
|
//*/
|
2018-04-02 21:00:37 +02:00
|
|
|
/*cw_timer_timeleft(wtpman->echointerval_timer);*/
|
|
|
|
|
2016-03-27 09:55:49 +02:00
|
|
|
if (cw_timer_timeout(wtpman->echointerval_timer)) {
|
2016-03-27 04:32:36 +02:00
|
|
|
|
2016-03-27 09:55:49 +02:00
|
|
|
cw_dbg(DBG_INFO, "Lost connection to WTP:%s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str_p(&conn->addr,sock_buf));
|
2016-03-27 04:32:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// mavl_del_all(conn->outgoing);
|
|
|
|
// conn_clear_upd(conn,1);
|
2016-04-12 07:32:05 +02:00
|
|
|
|
|
|
|
// props_to_sql(conn,conn->incomming,0);
|
|
|
|
// radios_to_sql(conn);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-04-12 07:32:05 +02:00
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
r = db_get_update_tasks(conn, sock_addr2str(&conn->addr,sock_buf));
|
2016-04-02 09:05:07 +02:00
|
|
|
if (r) {
|
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// if (!conn->outgoing->count)
|
|
|
|
// continue;
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2018-03-05 12:23:16 +01:00
|
|
|
cw_dbg(DBG_INFO, "Updating WTP %s",sock_addr2str(&conn->addr,sock_buf));
|
2016-04-02 09:05:07 +02:00
|
|
|
|
2018-03-05 07:24:48 +01:00
|
|
|
rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST);
|
2018-03-26 15:11:57 +02:00
|
|
|
|
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// mavl_merge(conn->config, conn->outgoing);
|
|
|
|
// mavl_destroy(conn->outgoing);
|
|
|
|
// conn->outgoing = mbag_create();
|
|
|
|
// props_to_sql(conn,conn->incomming,0);
|
|
|
|
// radios_to_sql(conn);
|
|
|
|
// mavl_destroy(r);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-04-02 09:05:07 +02:00
|
|
|
}
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
r = db_get_radio_tasks(conn, sock_addr2str(&conn->addr,sock_buf));
|
2016-04-02 09:05:07 +02:00
|
|
|
if (r) {
|
2016-03-27 16:44:50 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
|
|
|
// if (!conn->radios_upd->count)
|
2018-03-17 18:01:17 +01:00
|
|
|
// continue;
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2018-03-05 12:23:16 +01:00
|
|
|
cw_dbg(DBG_INFO, "Updating Radios for %s",sock_addr2str(&conn->addr,sock_buf));
|
2018-03-05 07:24:48 +01:00
|
|
|
rc = cw_send_request(conn, CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST);
|
2016-04-12 07:32:05 +02:00
|
|
|
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// conn_clear_upd(conn,1);
|
2016-04-12 07:32:05 +02:00
|
|
|
|
|
|
|
// mavl_destroy(conn->radios_upd);
|
|
|
|
// conn->radios_upd=mbag_i_create();
|
2016-04-02 09:05:07 +02:00
|
|
|
|
|
|
|
|
2018-03-17 18:01:17 +01:00
|
|
|
// radios_to_sql(conn);
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2016-04-02 09:05:07 +02:00
|
|
|
/*
|
|
|
|
rc = cw_send_request(conn, CW_MSG_CONFIGURATION_UPDATE_REQUEST);
|
|
|
|
mavl_merge(conn->config, conn->outgoing);
|
|
|
|
mavl_destroy(conn->outgoing);
|
|
|
|
conn->outgoing = mbag_create();
|
|
|
|
config_to_sql(conn);
|
|
|
|
radios_to_sql(conn);
|
|
|
|
mavl_destroy(r);
|
|
|
|
*/
|
|
|
|
}
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2016-03-27 16:44:50 +02:00
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-05 12:23:16 +01:00
|
|
|
db_ping_wtp(sock_addr2str_p(&conn->addr,sock_buf), "");
|
2015-04-29 19:26:04 +02:00
|
|
|
wtpman_remove(wtpman);
|
2018-04-02 21:00:37 +02:00
|
|
|
return NULL;
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2016-03-16 15:34:24 +01:00
|
|
|
static void wtpman_run_dtls(void *arg)
|
|
|
|
{
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2016-03-16 15:34:24 +01:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* reject connections to our multi- or broadcast sockets */
|
|
|
|
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
|
|
|
cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str_p(&wtpman->conn->addr,sock_buf));
|
2016-03-16 15:34:24 +01:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-26 15:11:57 +02:00
|
|
|
/*// time_t timer = cw_timer_start(wtpman->conn->wait_dtls);*/
|
2016-03-16 15:34:24 +01:00
|
|
|
|
|
|
|
/* establish dtls session */
|
2018-05-05 00:36:19 +02:00
|
|
|
if (!wtpman_dtls_setup(wtpman)) {
|
2016-03-16 15:34:24 +01:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-05 00:36:19 +02:00
|
|
|
wtpman_main(arg);
|
2016-03-16 15:34:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
void wtpman_destroy(struct wtpman *wtpman)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
if (wtpman->conn)
|
2014-07-11 22:12:11 +02:00
|
|
|
conn_destroy(wtpman->conn);
|
2015-04-07 07:42:36 +02:00
|
|
|
free(wtpman);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr, int dtlsmode)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-04-02 21:00:37 +02:00
|
|
|
struct sockaddr dbgaddr;
|
|
|
|
socklen_t dbgaddrl;
|
|
|
|
int sockfd, replyfd;
|
2018-03-05 12:23:16 +01:00
|
|
|
char sock_buf[SOCK_ADDR_BUFSIZE];
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman;
|
2014-07-11 22:12:11 +02:00
|
|
|
wtpman = malloc(sizeof(struct wtpman));
|
|
|
|
if (!wtpman)
|
|
|
|
return 0;
|
2015-04-07 07:42:36 +02:00
|
|
|
memset(wtpman, 0, sizeof(struct wtpman));
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-02-17 20:28:23 +01:00
|
|
|
if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
int port = sock_getport(&socklist[socklistindex].addr);
|
|
|
|
replyfd = socklist_find_reply_socket(srcaddr, port);
|
2016-02-17 20:28:23 +01:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
if (replyfd == -1) {
|
|
|
|
cw_log(LOG_ERR, "Can't find reply socket for request from %s",
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(srcaddr,sock_buf));
|
2016-02-15 19:17:01 +01:00
|
|
|
free(wtpman);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-02-16 08:13:34 +01:00
|
|
|
} else {
|
2016-02-15 19:17:01 +01:00
|
|
|
replyfd = socklist[socklistindex].sockfd;
|
|
|
|
}
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
sockfd = replyfd; /*//socklist[socklistindex].reply_sockfd;*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-17 20:28:23 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
dbgaddrl = sizeof(dbgaddr);
|
2016-03-27 04:32:36 +02:00
|
|
|
getsockname(sockfd, &dbgaddr, &dbgaddrl);
|
2016-02-17 20:28:23 +01:00
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
cw_dbg(DBG_INFO, "Creating wtpman on socket %d, %s:%d", sockfd,
|
2018-03-05 12:23:16 +01:00
|
|
|
sock_addr2str(&dbgaddr,sock_buf), sock_getport(&dbgaddr));
|
2016-02-17 20:28:23 +01:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn = conn_create(sockfd, srcaddr, 100);
|
2018-04-01 12:44:05 +02:00
|
|
|
wtpman->conn->role = CW_ROLE_AC;
|
2016-02-26 18:52:29 +01:00
|
|
|
|
2016-03-27 04:32:36 +02:00
|
|
|
wtpman->conn->data_sock = socklist[socklistindex].data_sockfd;
|
|
|
|
sock_copyaddr(&wtpman->conn->data_addr, (struct sockaddr *) &wtpman->conn->addr);
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!wtpman->conn) {
|
2014-07-11 22:12:11 +02:00
|
|
|
wtpman_destroy(wtpman);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
2018-04-03 07:35:55 +02:00
|
|
|
|
2018-04-02 21:00:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-23 08:58:05 +01:00
|
|
|
wtpman->conn->mods = conf_mods;
|
|
|
|
|
2015-04-26 14:46:28 +02:00
|
|
|
wtpman->conn->strict_capwap = conf_strict_capwap;
|
|
|
|
wtpman->conn->strict_hdr = conf_strict_headers;
|
2018-03-26 15:11:57 +02:00
|
|
|
/*
|
2018-03-17 18:01:17 +01:00
|
|
|
// wtpman->conn->radios = mbag_i_create();
|
|
|
|
// wtpman->conn->radios_upd = mbag_i_create();
|
2018-03-17 12:32:40 +01:00
|
|
|
// wtpman->conn->local = ac_config;
|
2015-04-29 19:26:04 +02:00
|
|
|
//wtpman->conn->capwap_mode=0; //CW_MODE_STD; //CISCO;
|
2018-03-17 18:01:17 +01:00
|
|
|
// wtpman->conn->capwap_mode = CW_MODE_CISCO;
|
2015-04-26 23:52:11 +02:00
|
|
|
//wtpman->conn->strict_capwap_hdr=0;
|
2018-03-26 15:11:57 +02:00
|
|
|
*/
|
2018-03-17 12:32:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
wtpman->conn->local_cfg = cw_ktv_create();
|
|
|
|
wtpman->conn->global_cfg = actube_global_cfg;
|
2018-03-20 07:09:09 +01:00
|
|
|
wtpman->conn->local_cfg = actube_global_cfg;
|
|
|
|
|
2018-04-03 07:35:55 +02:00
|
|
|
/* when created caused by a packet in DTLS mode, we try
|
|
|
|
* to find out the modules to load, for detected connection
|
|
|
|
* from discovery request */
|
|
|
|
if (dtlsmode){
|
|
|
|
int rc;
|
|
|
|
struct cw_Mod *cmod, *bmod;
|
|
|
|
|
|
|
|
rc = discovery_cache_get(discovery_cache,srcaddr,&cmod,&bmod);
|
|
|
|
if (rc){
|
|
|
|
cw_dbg(DBG_INFO, "Initializing with mod %s %s",cmod->name,bmod->name);
|
|
|
|
wtpman->conn->msgset = cw_mod_get_msg_set(wtpman->conn,cmod,bmod);
|
|
|
|
wtpman->conn->detected=1;
|
|
|
|
cmod->setup_cfg(wtpman->conn);
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
return wtpman;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
void wtpman_addpacket(struct wtpman *wtpman, uint8_t * packet, int len)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
conn_q_add_packet(wtpman->conn, packet, len);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-03-27 10:14:52 +02:00
|
|
|
void wtpman_start(struct wtpman *wtpman, int dtlsmode)
|
|
|
|
{
|
2018-04-02 01:39:08 +02:00
|
|
|
cw_dbg(DBG_INFO, "Starting wtpman, DTLS mode = %d",dtlsmode);
|
|
|
|
wtpman->dtlsmode=dtlsmode;
|
2018-05-05 00:36:19 +02:00
|
|
|
pthread_create(&wtpman->thread, NULL, wtpman_main,
|
2018-04-01 18:32:13 +02:00
|
|
|
(void *) wtpman);
|
|
|
|
return;
|
2018-04-02 01:39:08 +02:00
|
|
|
}
|
2014-07-26 20:25:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|