2014-07-11 22:12:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include "wtplist.h"
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap.h"
|
|
|
|
#include "cw/sock.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "socklist.h"
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/conn.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "wtpman.h"
|
|
|
|
#include "conf.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/timer.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/lwmsg.h"
|
|
|
|
#include "cw/lwapp.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-03-08 20:06:42 +01:00
|
|
|
//#include "cw/capwap_80211.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap_cisco.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/cw_util.h"
|
2014-08-16 10:10:00 +02:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap_items.h"
|
2015-04-05 02:07:59 +02:00
|
|
|
#include "ac.h"
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dtls.h"
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dbg.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
|
|
|
extern struct cw_actiondef capwap_actions;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-07-19 12:36:43 +02:00
|
|
|
/* macro to convert our client ip to a string */
|
2015-03-17 01:10:08 +01:00
|
|
|
//#define CLIENT_IP (sock_addrtostr((struct sockaddr*)&wtpman->conn->addr, (char[64]){0},64))
|
|
|
|
|
|
|
|
#define CLIENT_IP (sock_addr2str(&wtpman->conn->addr))
|
|
|
|
|
2016-02-17 16:18:26 +01:00
|
|
|
/*void conn_handle_change_state_event_request(struct conn *conn)
|
2014-08-23 12:05:45 +02:00
|
|
|
{
|
|
|
|
}
|
2016-02-17 16:18:26 +01:00
|
|
|
*/
|
2014-08-23 12:05:45 +02:00
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
/*
|
2015-04-07 07:42:36 +02:00
|
|
|
struct rh_param {
|
|
|
|
struct conn *conn;
|
2014-08-24 15:07:30 +02:00
|
|
|
int *msglist;
|
2014-08-24 11:10:46 +02:00
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int conn_rh(void *param)
|
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
struct rh_param *p = (struct rh_param *) param;
|
2014-08-24 15:07:30 +02:00
|
|
|
int i;
|
2015-04-07 07:42:36 +02:00
|
|
|
int *msglist = p->msglist;
|
2014-08-24 15:07:30 +02:00
|
|
|
|
2015-03-16 02:41:35 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
printf("Param %p\n", param);
|
2015-03-16 02:41:35 +01:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
for (i = 0; msglist[i] != -1; i++) {
|
|
|
|
if (msglist[i] == p->conn->cwrmsg.type)
|
2014-08-24 15:07:30 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2015-04-07 07:42:36 +02:00
|
|
|
cw_log(LOG_ERR, "Unexpected message from %s", sock_addr2str(&p->conn->addr));
|
|
|
|
cwsend_unknown_response(p->conn, p->conn->cwrmsg.seqnum, p->conn->cwrmsg.type);
|
|
|
|
return 1;
|
2014-08-24 15:07:30 +02:00
|
|
|
}
|
2015-04-12 10:19:02 +02:00
|
|
|
*/
|
2014-08-24 15:07:30 +02:00
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
/*
|
2015-04-07 07:42:36 +02:00
|
|
|
struct ac_info *get_acinfo();
|
2015-04-12 10:19:02 +02:00
|
|
|
*/
|
2014-07-11 22:12:11 +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
|
|
|
/*
|
2015-04-07 07:42:36 +02:00
|
|
|
int check_discovery(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len)
|
|
|
|
{
|
|
|
|
printf("Discovery END!!!\n");
|
2015-04-11 19:00:51 +02:00
|
|
|
conn->capwap_state = CW_STATE_NONE;
|
2015-04-07 07:42:36 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-18 10:15:30 +02:00
|
|
|
*/
|
|
|
|
|
2014-08-16 16:09:24 +02:00
|
|
|
static void wtpman_run_discovery(void *arg)
|
|
|
|
{
|
2014-08-17 18:47:24 +02:00
|
|
|
|
2016-02-14 17:30:14 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
2015-04-26 14:15:12 +02:00
|
|
|
//struct cwrmsg *cwrmsg;
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
struct conn *conn = wtpman->conn;
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2015-04-26 23:52:11 +02:00
|
|
|
//conn->config = mbag_create();
|
|
|
|
//conn->radios = mbag_create();
|
2015-04-12 19:19:29 +02:00
|
|
|
|
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
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
extern cw_actionlist_in_t the_tree;
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn->capwap_state = CW_STATE_DISCOVERY;
|
2015-04-05 02:07:59 +02:00
|
|
|
wtpman->conn->actions = &capwap_actions;
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/*
|
|
|
|
cw_actionlist_in_set_msg_end_callback(capwap_actions.in, CW_STATE_DISCOVERY,
|
|
|
|
CW_MSG_DISCOVERY_REQUEST, check_discovery);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
wtpman->conn->outgoing = mbag_create();
|
|
|
|
wtpman->conn->incomming = mbag_create();
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
while (!cw_timer_timeout(timer)
|
|
|
|
&& wtpman->conn->capwap_state == CW_STATE_DISCOVERY) {
|
|
|
|
cw_read_messages(wtpman->conn);
|
2015-03-31 08:04:03 +02:00
|
|
|
}
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
struct mbag_item *wn = mbag_get(wtpman->conn->incomming, CW_ITEM_WTP_NAME);
|
2015-04-05 20:27:17 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (wn) {
|
2016-02-17 16:18:26 +01:00
|
|
|
// printf("WTP Name: %s\n", wn->data);
|
|
|
|
// exit(0);
|
2015-04-05 20:27:17 +02:00
|
|
|
}
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2014-08-16 15:13:40 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-07-19 12:36:43 +02:00
|
|
|
|
2014-08-22 08:21:38 +02:00
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
|
|
|
|
static int wtpman_establish_dtls(void *arg)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
/* setup cipher */
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn->dtls_cipher = conf_sslcipher;
|
2014-08-02 14:22:37 +02:00
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
/* setup DTSL certificates */
|
2015-04-07 07:42:36 +02:00
|
|
|
int dtls_ok = 0;
|
|
|
|
if (conf_sslkeyfilename && conf_sslcertfilename) {
|
2015-02-07 02:01:32 +01:00
|
|
|
|
|
|
|
|
2014-08-02 14:22:37 +02:00
|
|
|
wtpman->conn->dtls_key_file = conf_sslkeyfilename;
|
|
|
|
wtpman->conn->dtls_cert_file = conf_sslcertfilename;
|
|
|
|
wtpman->conn->dtls_key_pass = conf_sslkeypass;
|
2014-08-16 14:05:41 +02:00
|
|
|
wtpman->conn->dtls_verify_peer = conf_dtls_verify_peer;
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_dbg(DBG_DTLS, "Using key file %s", wtpman->conn->dtls_key_file);
|
2016-02-16 08:13:34 +01:00
|
|
|
cw_dbg(DBG_DTLS, "Using cert file %s", wtpman->conn->dtls_cert_file);
|
2015-04-07 07:42:36 +02:00
|
|
|
dtls_ok = 1;
|
2014-08-02 14:22:37 +02:00
|
|
|
}
|
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
/* setup DTLS psk */
|
2015-04-07 07:42:36 +02:00
|
|
|
if (conf_dtls_psk) {
|
|
|
|
wtpman->conn->dtls_psk = conf_dtls_psk;
|
|
|
|
wtpman->conn->dtls_psk_len = strlen(conf_dtls_psk);
|
|
|
|
dtls_ok = 1;
|
2014-08-02 14:22:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!dtls_ok) {
|
|
|
|
cw_log(LOG_ERR,
|
|
|
|
"Can't establish DTLS session, neither psk nor certs set in config file.");
|
2014-08-24 11:10:46 +02:00
|
|
|
return 0;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2014-07-28 07:07:20 +02:00
|
|
|
|
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-01 09:31:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
cw_dbg(DBG_DTLS, "Error establishing DTLS session with %s", CLIENT_IP);
|
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
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
cw_dbg(DBG_DTLS, "DTLS session established with %s, cipher=%s", CLIENT_IP,
|
|
|
|
dtls_get_cipher(wtpman->conn));
|
|
|
|
/* DTLS handshake done */
|
2015-02-09 22:04:54 +01:00
|
|
|
|
2016-03-01 09:31:16 +01:00
|
|
|
/*
|
2015-02-09 22:04:54 +01:00
|
|
|
int cert_len;
|
|
|
|
struct dtls_ssl_cert cert;
|
|
|
|
|
|
|
|
FILE *f;
|
2015-04-07 07:42:36 +02:00
|
|
|
f = fopen("pcert.der", "wb");
|
2015-02-09 22:04:54 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
cert = dtls_get_peers_cert(wtpman->conn, 0);
|
|
|
|
|
2016-03-01 09:31:16 +01:00
|
|
|
printf("Have Peers Cert: %p, %d\n", cert.data, cert.size);
|
|
|
|
fwrite(cert.data, 1, cert.size, f);
|
2015-04-11 19:00:51 +02:00
|
|
|
fclose(f);
|
2016-03-01 09:31:16 +01:00
|
|
|
*/
|
|
|
|
|
2015-02-09 22:04:54 +01:00
|
|
|
|
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
static int wtpman_join(void *arg, time_t timer)
|
2014-08-24 11:10:46 +02:00
|
|
|
{
|
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;
|
2015-04-26 16:08:44 +02:00
|
|
|
|
|
|
|
wtpman->conn->outgoing = mbag_create();
|
|
|
|
wtpman->conn->incomming = mbag_create();
|
2016-02-16 08:13:34 +01:00
|
|
|
conn->config = conn->incomming;
|
|
|
|
// wtpman->conn->local = ac_config;
|
2015-04-26 16:08:44 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
mbag_set_str(conn->local, CW_ITEM_AC_NAME, conf_acname);
|
2015-04-26 16:08:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-24 11:10:46 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
extern cw_actionlist_in_t the_tree;
|
|
|
|
wtpman->conn->actions = &capwap_actions;
|
|
|
|
wtpman->conn->capwap_state = CW_STATE_JOIN;
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn->capwap_state = CW_STATE_JOIN;
|
2015-04-05 02:07:59 +02:00
|
|
|
wtpman->conn->actions = &capwap_actions;
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
// wtpman->conn->itemstore = mbag_create();
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
|
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
cw_dbg(DBG_INFO, "Join State - %s", sock_addr2str(&conn->addr));
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
int rc;
|
2015-04-07 07:42:36 +02:00
|
|
|
while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_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) {
|
2015-04-05 20:27:17 +02:00
|
|
|
break;
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
if (wtpman->conn->capwap_state == CW_STATE_JOIN) {
|
2015-04-07 07:42:36 +02:00
|
|
|
cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.",
|
|
|
|
sock_addr2str(&wtpman->conn->addr), wtpman->conn->wait_dtls);
|
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)
|
|
|
|
{
|
2016-02-16 08:13:34 +01:00
|
|
|
struct conn *conn = wtpman->conn;
|
|
|
|
|
|
|
|
/* Image upload */
|
|
|
|
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.",
|
2015-04-26 12:36:53 +02:00
|
|
|
sock_addr2str(&conn->addr));
|
2016-02-16 08:13:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
cw_dbg(DBG_INFO, "Sending image file '%s' to '%s'.", filename,
|
|
|
|
sock_addr2str(&conn->addr));
|
|
|
|
FILE *infile = fopen(filename, "rb");
|
|
|
|
if (infile == NULL) {
|
|
|
|
cw_log(LOG_ERR, "Can't open image %s: %s",
|
|
|
|
sock_addr2str(&conn->addr), strerror(errno));
|
|
|
|
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) {
|
|
|
|
rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST);
|
|
|
|
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",
|
|
|
|
sock_addr2str(&conn->addr), cw_strrc(rc));
|
|
|
|
} else {
|
|
|
|
cw_dbg(DBG_INFO, "Image '%s' sucessful sent to %s in %0.1f seconds.",
|
|
|
|
filename, sock_addr2str(&conn->addr), cw_clock_stop(&clk));
|
|
|
|
conn->capwap_state = CW_STATE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(infile);
|
|
|
|
wtpman_remove(wtpman);
|
2015-04-26 12:36:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-29 19:26:04 +02:00
|
|
|
#include "db.h"
|
|
|
|
void config_to_sql(struct conn *conn)
|
|
|
|
{
|
|
|
|
// XXX for the moment we use just the IP adress as ID
|
2016-02-16 08:13:34 +01:00
|
|
|
char *wtp_id = sock_addr2str(&conn->addr);
|
|
|
|
|
|
|
|
MAVLITER_DEFINE(it, conn->incomming);
|
|
|
|
mavliter_foreach(&it) {
|
|
|
|
mbag_item_t *i = mavliter_get(&it);
|
|
|
|
|
|
|
|
const struct cw_itemdef *cwi =
|
|
|
|
cw_itemdef_get(conn->actions->items, i->id, NULL);
|
|
|
|
if (cwi) {
|
|
|
|
DBGX("ID %s,%s", i->id, cwi->id);
|
|
|
|
DBGX("Typei %s,Typecwd %s", i->type->name, cwi->type->name);
|
|
|
|
|
|
|
|
// printf("%s != %s ?\n",i->type->name,cwi->type->name);
|
2015-04-29 19:26:04 +02:00
|
|
|
char str[256];
|
2016-02-16 08:13:34 +01:00
|
|
|
if (i->type->to_str) {
|
|
|
|
i->type->to_str(i, str);
|
|
|
|
db_put_wtp_prop(wtp_id, cwi->id, cwi->sub_id, str);
|
|
|
|
} else {
|
|
|
|
cw_log(LOG_ERR, "Can't converto to str");
|
2015-05-01 12:50:28 +02:00
|
|
|
|
|
|
|
}
|
2015-04-29 19:26:04 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// DBGX("ID %d",i->id);
|
2015-04-29 19:26:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
static void wtpman_run(void *arg)
|
|
|
|
{
|
2015-04-26 12:36:53 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman = (struct wtpman *) arg;
|
|
|
|
struct cwrmsg *cwrmsg; // = conn_get_message(wtpman->conn);
|
2014-08-25 07:56:14 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn->seqnum = 0;
|
2015-04-26 12:36:53 +02:00
|
|
|
struct conn *conn = wtpman->conn;
|
|
|
|
|
2014-08-24 15:07:30 +02:00
|
|
|
|
|
|
|
/* reject connections to our multi- or broadcast sockets */
|
2015-04-07 07:42:36 +02:00
|
|
|
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
|
|
|
cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.",
|
|
|
|
CLIENT_IP);
|
2014-08-24 15:07:30 +02:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
time_t timer = cw_timer_start(wtpman->conn->wait_dtls);
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/* establish dtls session */
|
|
|
|
if (!wtpman_establish_dtls(wtpman)) {
|
2014-08-24 15:07:30 +02:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* dtls is established, goto join state */
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!wtpman_join(wtpman, timer)) {
|
2014-08-24 15:07:30 +02:00
|
|
|
wtpman_remove(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
|
2015-03-16 02:41:35 +01:00
|
|
|
|
|
|
|
|
2015-03-17 01:10:08 +01:00
|
|
|
/* here the WTP has joined, now we assume an image data request
|
2015-04-07 07:42:36 +02:00
|
|
|
or an configuration status request. Nothing else.
|
|
|
|
*/
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
int rc = 0;
|
|
|
|
while (!cw_timer_timeout(timer)
|
|
|
|
&& wtpman->conn->capwap_state == CW_STATE_CONFIGURE) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
if (!cw_rcok(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);
|
|
|
|
return;
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2015-04-07 07:42:36 +02:00
|
|
|
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
|
2015-04-26 12:36:53 +02:00
|
|
|
wtpman_image_data(wtpman);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-18 01:45:08 +02:00
|
|
|
|
2014-08-16 10:10:00 +02:00
|
|
|
|
2015-04-29 19:26:04 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
conn->capwap_state = CW_STATE_RUN;
|
2015-04-29 19:26:04 +02:00
|
|
|
|
|
|
|
// XXX testing ...
|
2016-02-16 08:13:34 +01:00
|
|
|
DBGX("Cofig to sql", "");
|
2015-04-29 19:26:04 +02:00
|
|
|
config_to_sql(conn);
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
rc = 0;
|
2015-04-26 23:52:11 +02:00
|
|
|
while (wtpman->conn->capwap_state == CW_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
|
|
|
|
2015-05-01 12:50:28 +02:00
|
|
|
mavl_del_all(conn->outgoing);
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
mavl_conststr_t r = db_get_update_tasks(conn, sock_addr2str(&conn->addr));
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
if (!r)
|
2015-05-02 02:02:06 +02:00
|
|
|
continue;
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
if (!conn->outgoing->count)
|
|
|
|
continue;
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
// DBGX("Have %d tasks",r->count);
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-05-02 02:02:06 +02:00
|
|
|
rc = cw_send_request(conn, CW_MSG_CONFIGURATION_UPDATE_REQUEST);
|
2016-02-16 08:13:34 +01:00
|
|
|
mavl_merge(conn->config, conn->outgoing);
|
2015-05-02 02:02:06 +02:00
|
|
|
mavl_destroy(conn->outgoing);
|
2016-02-16 08:13:34 +01:00
|
|
|
conn->outgoing = mbag_create();
|
2015-05-02 02:02:06 +02:00
|
|
|
config_to_sql(conn);
|
|
|
|
mavl_destroy(r);
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-29 19:26:04 +02:00
|
|
|
wtpman_remove(wtpman);
|
2015-04-11 19:00:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-07-11 22:12:11 +02: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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr)
|
2014-07-11 22:12:11 +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-15 19:17:01 +01:00
|
|
|
|
|
|
|
int replyfd;
|
2016-02-17 20:28:23 +01:00
|
|
|
if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
|
|
|
|
extern int socklist_find_reply_socket(struct sockaddr *sa,int port);
|
|
|
|
|
|
|
|
|
|
|
|
int port=sock_getport(&socklist[socklistindex].addr);
|
|
|
|
replyfd = socklist_find_reply_socket(srcaddr,port);
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
if (replyfd == -1) {
|
|
|
|
cw_log(LOG_ERR, "Can't find reply socket for request from %s",
|
|
|
|
sock_addr2str(srcaddr));
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
int sockfd = replyfd; //socklist[socklistindex].reply_sockfd;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-02-17 20:28:23 +01:00
|
|
|
|
|
|
|
struct sockaddr dbgaddr;
|
|
|
|
socklen_t dbgaddrl=sizeof(dbgaddr);
|
|
|
|
getsockname(sockfd,&dbgaddr,&dbgaddrl);
|
|
|
|
|
2016-02-22 18:33:47 +01:00
|
|
|
cw_dbg(DBG_INFO,"Creating wtpman on socket %d, %s:%d",sockfd,sock_addr2str(&dbgaddr),sock_getport(&dbgaddr));
|
2016-02-17 20:28:23 +01:00
|
|
|
|
2016-02-26 18:52:29 +01:00
|
|
|
extern int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
|
|
|
|
struct sockaddr *from);
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
wtpman->conn = conn_create(sockfd, srcaddr, 100);
|
2016-02-26 18:52:29 +01:00
|
|
|
|
|
|
|
// wtpman->conn->process_packet = conn_process_packet2;
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!wtpman->conn) {
|
2014-07-11 22:12:11 +02:00
|
|
|
wtpman_destroy(wtpman);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
2016-02-16 08:13:34 +01:00
|
|
|
wtpman->conn->radios = mbag_i_create();
|
2015-04-26 23:52:11 +02:00
|
|
|
wtpman->conn->local = ac_config;
|
2015-04-29 19:26:04 +02:00
|
|
|
//wtpman->conn->capwap_mode=0; //CW_MODE_STD; //CISCO;
|
2016-02-16 08:13:34 +01:00
|
|
|
wtpman->conn->capwap_mode = CW_MODE_CISCO;
|
2015-04-26 23:52:11 +02:00
|
|
|
//wtpman->conn->strict_capwap_hdr=0;
|
2015-04-26 14:46:28 +02: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
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t * packet, int len)
|
2014-07-26 20:25:06 +02:00
|
|
|
{
|
2015-04-07 07:42:36 +02:00
|
|
|
// uint8_t * m = packet+12;
|
|
|
|
// int l = LWTH_GET_LENGTH(packet+6);
|
2014-07-26 20:25:06 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
uint8_t *msg = packet + 12;
|
2014-07-26 20:25:06 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
int msgtype = LWMSG_GET_TYPE(msg);
|
|
|
|
int msglen = LWMSG_GET_LEN(msg);
|
|
|
|
printf("Type is %d, Len is %d\n", msgtype, msglen);
|
|
|
|
|
|
|
|
uint8_t *msgdata = LWMSG_GET_DATA(msg);
|
2014-07-26 20:25:06 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
int c=0;
|
|
|
|
while (c < msglen){
|
|
|
|
int eltype = LWMSGELEM_GET_TYPE(data);
|
|
|
|
int ellen = LWMSGELEM_GET_LEN(data);
|
|
|
|
printf ("ELEM TYPE: %d, LEN: %d\n",eltype,ellen);
|
|
|
|
c+=ellen+3;
|
|
|
|
data=data+ellen+3;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
uint8_t *data;
|
2015-03-23 07:48:27 +01:00
|
|
|
/*
|
2014-07-26 20:25:06 +02:00
|
|
|
lw_foreach_msgelem(data,msgdata,msglen){
|
|
|
|
int eltype = LWMSGELEM_GET_TYPE(data);
|
|
|
|
int ellen = LWMSGELEM_GET_LEN(data);
|
|
|
|
uint8_t * eldata = LWMSGELEM_GET_DATA(data);
|
|
|
|
|
|
|
|
wtpinfo_lwreadelem_wtp_descriptor(&wtpman->wtpinfo,eltype,eldata,ellen);
|
|
|
|
|
|
|
|
printf ("ELEM TYPE: %d, LEN: %d\n",eltype,ellen);
|
|
|
|
|
|
|
|
}
|
2015-03-23 07:48:27 +01:00
|
|
|
*/
|
2014-07-26 20:25:06 +02:00
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
// char wi[4096];
|
|
|
|
// wtpinfo_print(wi, &wtpman->wtpinfo);
|
|
|
|
// printf("WTPINFO: \n%s\n", wi);
|
2014-07-26 20:25:06 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
|
|
|
|
// char buffer[2048];
|
|
|
|
// struct lwmsg lwmsg;
|
|
|
|
// lwmsg_init(&lwmsg, buffer,conf_macaddress,LWMSG_DISCOVERY_RESPONSE,conn_get_next_seqnum(wtpman->conn));
|
|
|
|
|
|
|
|
// conn_send_packet(wtpman->conn,buffer,60);
|
2014-07-26 20:25:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
void wtpman_start(struct wtpman *wtpman, int dtlsmode)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2016-02-14 17:30:14 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (dtlsmode) {
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_dbg(DBG_INFO, "Starting wtpman in DTLS mode");
|
2015-04-07 07:42:36 +02:00
|
|
|
pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run,
|
|
|
|
(void *) wtpman);
|
|
|
|
} else {
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_dbg(DBG_INFO, "Starting wtpman in non-dtls mode");
|
2016-02-14 17:30:14 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run_discovery,
|
|
|
|
(void *) wtpman);
|
2014-07-26 20:25:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 16:18:26 +01:00
|
|
|
/*
|
2015-04-07 07:42:36 +02:00
|
|
|
void wtpman_lw_start(struct wtpman *wtpman)
|
2014-07-26 20:25:06 +02:00
|
|
|
{
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2016-02-17 16:18:26 +01:00
|
|
|
*/
|