2014-07-11 22:12:11 +02:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-04-05 20:27:17 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Connection object stuff
|
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#ifndef __CONN_H
|
|
|
|
#define __CONN_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include "fragman.h"
|
|
|
|
#include "cwmsg.h"
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2018-03-04 16:59:20 +01:00
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
/*#include "action.h"*/
|
|
|
|
|
|
|
|
/*#include "mbag.h"*/
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
#include "intavltree.h"
|
2015-03-31 08:04:03 +02:00
|
|
|
|
2018-03-03 17:42:28 +01:00
|
|
|
|
2016-02-22 18:33:47 +01:00
|
|
|
#include "mod.h"
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2016-03-27 04:40:36 +02:00
|
|
|
|
|
|
|
struct cw_action_in;
|
|
|
|
|
2016-03-26 11:45:05 +01:00
|
|
|
#define CONN_MAX_MSG_LENGTH 65536
|
|
|
|
|
2016-04-10 15:59:15 +02:00
|
|
|
|
|
|
|
#include "netconn.h"
|
|
|
|
#include "connlist.h"
|
|
|
|
|
|
|
|
|
2015-04-05 20:27:17 +02:00
|
|
|
/**
|
|
|
|
* Connection Object
|
|
|
|
*/
|
2015-03-31 08:04:03 +02:00
|
|
|
struct conn {
|
2014-07-11 22:12:11 +02:00
|
|
|
int sock;
|
|
|
|
struct sockaddr_storage addr;
|
2016-03-26 12:37:37 +01:00
|
|
|
|
2016-04-10 15:59:15 +02:00
|
|
|
struct connlist * connlist;
|
|
|
|
|
2016-03-26 12:37:37 +01:00
|
|
|
|
|
|
|
int data_sock;
|
|
|
|
struct sockaddr_storage data_addr;
|
|
|
|
|
2016-04-10 15:59:15 +02:00
|
|
|
struct netconn * data_nc;
|
|
|
|
|
2016-03-26 12:37:37 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
int recv_timeout;
|
2018-03-05 20:39:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
mavl_t remote_cfg;
|
2018-03-12 18:01:40 +01:00
|
|
|
mavl_t local_cfg;
|
2018-03-17 12:32:40 +01:00
|
|
|
mavl_t global_cfg;
|
2018-03-12 18:01:40 +01:00
|
|
|
|
2018-03-05 20:39:15 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
/* mbag_t outgoing;
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_t incomming;
|
|
|
|
mbag_t remote;
|
|
|
|
mbag_t local;
|
2016-04-02 09:05:07 +02:00
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
mbag_t radios;
|
2016-04-02 09:05:07 +02:00
|
|
|
mbag_t radios_upd;
|
2015-04-19 23:27:44 +02:00
|
|
|
mbag_t config;
|
2016-04-02 09:05:07 +02:00
|
|
|
mbag_t config_upd;
|
2018-03-17 17:29:09 +01:00
|
|
|
*/
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2016-04-10 15:59:15 +02:00
|
|
|
uint8_t session_id[16];
|
|
|
|
|
|
|
|
|
2018-02-28 07:38:02 +01:00
|
|
|
int receiver;
|
|
|
|
|
2015-04-18 11:20:24 +02:00
|
|
|
/** base_mac */
|
|
|
|
bstr_t base_rmac;
|
2015-04-12 09:00:18 +02:00
|
|
|
|
|
|
|
/** Wireless Binding ID of this connection */
|
|
|
|
uint8_t wbid;
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/** Counter for mandatory message elements */
|
|
|
|
struct avltree *mand;
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-04-12 09:00:18 +02:00
|
|
|
/** Actionsdefs - this defines the possible actions for
|
|
|
|
this conn object, so in the end this is the specification
|
|
|
|
of the protocoll */
|
2018-03-03 08:15:19 +01:00
|
|
|
|
2018-02-26 18:28:12 +01:00
|
|
|
|
|
|
|
struct cw_MsgSet * msgset;
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-04-12 09:00:18 +02:00
|
|
|
/** Current CAPWAP state */
|
2015-03-30 07:56:42 +02:00
|
|
|
|
|
|
|
uint8_t capwap_state;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-12 09:00:18 +02:00
|
|
|
/** The framgent manager used on this connection */
|
2015-05-01 12:02:11 +02:00
|
|
|
frag_t *fragman;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-12 09:00:18 +02:00
|
|
|
/** Current Fragment ID */
|
2014-07-11 22:12:11 +02:00
|
|
|
int fragid;
|
|
|
|
|
|
|
|
int seqnum;
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
int last_seqnum_received;
|
2014-07-11 22:12:11 +02:00
|
|
|
int last_message_id_received;
|
|
|
|
|
2014-08-17 13:59:13 +02:00
|
|
|
|
|
|
|
struct cwmsg req_msg;
|
|
|
|
struct cwmsg resp_msg;
|
2015-04-12 09:00:18 +02:00
|
|
|
|
|
|
|
/** Buffer for outgoing request messages */
|
2016-03-26 11:45:05 +01:00
|
|
|
uint8_t req_buffer[CONN_MAX_MSG_LENGTH];
|
2014-08-17 13:59:13 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
/** Buffer for outgoing response messages */
|
2016-03-26 11:45:05 +01:00
|
|
|
uint8_t resp_buffer[CONN_MAX_MSG_LENGTH];
|
2015-04-05 02:07:59 +02:00
|
|
|
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
|
2015-04-12 09:00:18 +02:00
|
|
|
/** Max mtu, could be changed during discovery */
|
|
|
|
int mtu;
|
|
|
|
/* 0 mtu discovery turned off, 1 discovery tuned on */
|
|
|
|
int mtu_discovery;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
/* receive and send methods */
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
int (*recv_packet) (struct conn *, uint8_t *, int);
|
|
|
|
int (*recv_packet_peek) (struct conn *, uint8_t *, int);
|
|
|
|
int (*send_packet) (struct conn *, const uint8_t *, int);
|
2018-03-03 08:15:19 +01:00
|
|
|
/*
|
2016-04-10 15:59:15 +02:00
|
|
|
// int (*recv_data_packet) (struct conn *, uint8_t *,int);
|
|
|
|
// int (*send_data_packet) (struct conn *, const uint8_t *, int);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-12 23:28:55 +02:00
|
|
|
int (*readfrom) (struct conn *, uint8_t *, int, struct sockaddr_storage *);
|
2015-03-31 08:04:03 +02:00
|
|
|
int (*read) (struct conn *, uint8_t *, int);
|
|
|
|
int (*write) (struct conn *, const uint8_t *, int);
|
2018-03-03 08:15:19 +01:00
|
|
|
/*
|
2016-04-10 15:59:15 +02:00
|
|
|
// int (*write_data) (struct conn *, const uint8_t *, int);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
/* optional packet queue */
|
2015-03-31 08:04:03 +02:00
|
|
|
uint8_t **q;
|
2014-07-11 22:12:11 +02:00
|
|
|
int qsize;
|
|
|
|
int qrpos;
|
|
|
|
int qwpos;
|
|
|
|
sem_t q_sem;
|
2015-03-31 08:04:03 +02:00
|
|
|
uint8_t *cur_packet;
|
2014-07-11 22:12:11 +02:00
|
|
|
int cur_packet_len;
|
|
|
|
int cur_packet_pos;
|
|
|
|
|
|
|
|
/* dtls stuff */
|
2015-03-31 08:04:03 +02:00
|
|
|
int (*dtls_start) (struct conn *);
|
|
|
|
int (*dtls_accept) (struct conn *);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
char *dtls_psk;
|
2014-07-11 22:12:11 +02:00
|
|
|
int dtls_psk_len;
|
|
|
|
|
2016-03-12 22:27:58 +01:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
char *dtls_cert_file;
|
|
|
|
char *dtls_key_file;
|
|
|
|
char *dtls_key_pass;
|
2014-08-02 09:44:06 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
void *dtls_data;
|
|
|
|
char *dtls_cipher;
|
2014-08-16 09:08:34 +02:00
|
|
|
int dtls_error;
|
2015-04-12 09:00:18 +02:00
|
|
|
|
2014-08-16 12:39:26 +02:00
|
|
|
uint8_t dtls_cookie[8];
|
2015-04-12 09:00:18 +02:00
|
|
|
|
2014-08-16 14:07:18 +02:00
|
|
|
int dtls_verify_peer;
|
2016-03-12 22:27:58 +01:00
|
|
|
int dtls_mtu;
|
|
|
|
|
2015-02-07 03:00:11 +01:00
|
|
|
uint8_t dtls_buffer[2048];
|
|
|
|
int dtls_buffer_len;
|
|
|
|
int dtls_buffer_pos;
|
|
|
|
|
2014-08-17 19:16:15 +02:00
|
|
|
/* capwap timers */
|
|
|
|
int retransmit_interval;
|
2014-08-18 00:05:25 +02:00
|
|
|
int max_retransmit;
|
2014-08-17 19:16:15 +02:00
|
|
|
int wait_dtls;
|
|
|
|
int wait_join;
|
2015-03-31 08:04:03 +02:00
|
|
|
|
2014-08-17 19:16:15 +02:00
|
|
|
|
2014-08-02 09:44:06 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* used to link the conn obj with other objects */
|
2015-03-31 08:04:03 +02:00
|
|
|
void *data;
|
2014-08-17 13:59:13 +02:00
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
/** Mode */
|
2015-01-04 23:08:52 +01:00
|
|
|
int capwap_mode;
|
2015-04-13 11:00:46 +02:00
|
|
|
|
|
|
|
/** CAWAP mode for outgoing messages */
|
|
|
|
int capwap_mode_out;
|
|
|
|
|
2015-01-04 23:08:52 +01:00
|
|
|
|
2014-08-17 13:59:13 +02:00
|
|
|
int strict_capwap;
|
2015-04-13 11:00:46 +02:00
|
|
|
int strict_hdr;
|
2014-08-23 09:38:31 +02:00
|
|
|
|
2016-02-20 16:19:22 +01:00
|
|
|
|
|
|
|
int (*process_packet)(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from);
|
2016-02-21 09:25:36 +01:00
|
|
|
int (*process_message)(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
|
|
|
struct sockaddr *from);
|
2016-02-22 18:33:47 +01:00
|
|
|
|
2016-02-20 16:19:22 +01:00
|
|
|
|
2016-02-23 08:58:05 +01:00
|
|
|
int detected;
|
2016-02-22 18:33:47 +01:00
|
|
|
void * mods;
|
2016-02-20 16:19:22 +01:00
|
|
|
|
2016-03-27 04:40:36 +02:00
|
|
|
|
|
|
|
int (*msg_start)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);
|
|
|
|
int (*msg_end)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from);
|
|
|
|
|
2016-04-12 07:33:24 +02:00
|
|
|
int (*elem_end)(struct conn *conn,struct cw_action_in *a,int afrc,uint8_t*elem,int len,struct sockaddr *from);
|
2016-03-27 04:40:36 +02:00
|
|
|
|
2018-03-03 08:15:19 +01:00
|
|
|
/*
|
2016-03-27 04:40:36 +02:00
|
|
|
// void (*actions_registered)(struct conn *conn);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2016-03-27 04:40:36 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-17 13:59:13 +02:00
|
|
|
#define conn_is_strict_capwap(conn) (conn->strict_capwap)
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
struct conn *conn_create(int sock, struct sockaddr *addr, int qsize);
|
|
|
|
struct conn *conn_create_noq(int sock, struct sockaddr *addr);
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern int conn_send_cwmsg(struct conn *conn, struct cwmsg *cwmsg);
|
2018-03-03 08:15:19 +01:00
|
|
|
|
|
|
|
/*
|
2015-04-10 17:14:55 +02:00
|
|
|
//extern int conn_process_packet(struct conn *conn, uint8_t * packet, int len,
|
|
|
|
// int (*cb) (void *, uint8_t *,int len), void *cbarg);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-02-20 16:19:22 +01:00
|
|
|
extern int conn_process_packet(struct conn *conn, uint8_t * packet, int len,struct sockaddr *from);
|
2016-02-21 09:25:36 +01:00
|
|
|
extern int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
|
|
|
|
struct sockaddr *from);
|
2016-02-20 16:19:22 +01:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern uint8_t *conn_get_message(struct conn *conn);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern int conn_send_packet(struct conn *conn, const uint8_t * buffer, int len);
|
2016-03-26 12:37:37 +01:00
|
|
|
extern int conn_send_data_packet(struct conn * conn, const uint8_t * buffer, int len);
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern void conn_destroy(struct conn *conn);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
uint8_t *conn_q_get_packet(struct conn *conn);
|
|
|
|
extern int conn_q_recv_packet(struct conn *conn, uint8_t * buffer, int len);
|
|
|
|
extern int conn_q_recv_packet_peek(struct conn *conn, uint8_t * buffer, int len);
|
2015-02-08 00:49:59 +01:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern int conn_recv_packet(struct conn *conn, uint8_t * buf, int len);
|
|
|
|
extern int conn_recv_packet_peek(struct conn *conn, uint8_t * buf, int len);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern int conn_send_response(struct conn *conn, struct cwmsg *cwmsg, int seqnum);
|
|
|
|
extern struct cwrmsg *conn_get_response(struct conn *conn);
|
2014-07-25 00:26:54 +02:00
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#define conn_get_next_seqnum(conn) (conn->seqnum=((conn->seqnum+1)&0xff))
|
|
|
|
#define conn_get_last_seqnum(conn) (conn->seqnum&0xff)
|
|
|
|
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
void conn_q_add_packet(struct conn *conn, uint8_t * packet, int len);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-25 07:56:14 +02:00
|
|
|
struct image_identifier;
|
2015-03-17 01:10:08 +01:00
|
|
|
struct cwimage_data;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
extern void conn_prepare_request(struct conn *conn, int type);
|
|
|
|
extern int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *,
|
|
|
|
struct image_identifier *id);
|
2018-03-03 08:15:19 +01:00
|
|
|
/*
|
2015-05-01 20:34:50 +02:00
|
|
|
//extern void conn_detect_capwap(struct conn *conn, struct wtpinfo *wtpinfo);
|
2018-03-03 08:15:19 +01:00
|
|
|
*/
|
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
struct cwrmsg *conn_send_request(struct conn *conn);
|
|
|
|
struct cwrmsg *conn_wait_for_message(struct conn *conn, time_t timer);
|
2015-03-16 21:41:33 +01:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
struct cwrmsg *conn_wait_for_request(struct conn *conn, int *msglist, time_t timer);
|
2015-03-16 21:41:33 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2014-08-24 15:03:53 +02:00
|
|
|
#define conn_is_error(conn) (conn->dtls_error)
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-03-31 08:04:03 +02:00
|
|
|
void conn_init(struct conn *conn);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
extern int cw_read_messages(struct conn *conn);
|
|
|
|
|
2015-04-12 23:28:55 +02:00
|
|
|
extern int conn_recvfrom_packet(struct conn *conn, uint8_t * buf, int len,
|
|
|
|
struct sockaddr_storage *from);
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
int conn_send_msg(struct conn * conn, uint8_t *rawmsg);
|
|
|
|
int cw_read_from(struct conn * conn);
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2016-04-12 07:33:24 +02:00
|
|
|
void conn_clear_upd(struct conn *conn, int merge);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-27 04:40:36 +02:00
|
|
|
#endif /* __CONN_H */
|