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-03-20 22:31:09 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief
|
|
|
|
*/
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2018-03-03 17:42:28 +01:00
|
|
|
#include "capwap.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "conn.h"
|
|
|
|
#include "sock.h"
|
2018-03-03 17:42:28 +01:00
|
|
|
|
2018-04-09 09:27:38 +02:00
|
|
|
#include "msgset.h"
|
|
|
|
#include "cw.h"
|
|
|
|
|
2014-08-17 19:16:15 +02:00
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/**
|
2015-03-20 22:31:09 +01:00
|
|
|
* Create a conn object
|
2015-11-02 11:12:18 +01:00
|
|
|
* @param sock a socket
|
2015-03-20 22:31:09 +01:00
|
|
|
* @param addr the address associated
|
|
|
|
* @param qsize size of packet queue
|
|
|
|
* @return A pointer to the created object
|
|
|
|
* This function creates a conn obnject with queueing functionality
|
|
|
|
* for asynchronous operation.
|
|
|
|
* To create a conn object without queue functionallity use #conn_create_noq.
|
2014-07-11 22:12:11 +02:00
|
|
|
*/
|
2014-07-20 12:51:03 +02:00
|
|
|
struct conn * conn_create(int sock, struct sockaddr * addr, int qsize)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
|
|
|
struct conn * conn;
|
|
|
|
conn = malloc(sizeof (struct conn));
|
|
|
|
if (!conn)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-17 19:16:15 +02:00
|
|
|
conn_init(conn);
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
conn->sock=sock;
|
|
|
|
|
|
|
|
if (addr)
|
|
|
|
sock_copyaddr(&conn->addr,addr);
|
|
|
|
|
|
|
|
|
|
|
|
conn->fragman = fragman_create();
|
|
|
|
if (conn->fragman==NULL){
|
|
|
|
conn_destroy(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->qsize=qsize;
|
|
|
|
if (qsize != 0){
|
|
|
|
if (!(conn->q=malloc( sizeof(uint8_t *) * qsize))){
|
|
|
|
conn_destroy(conn);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
conn->qrpos=-1;
|
|
|
|
if (sem_init(&conn->q_sem,0,0)!=0){
|
2015-04-12 10:19:02 +02:00
|
|
|
cw_log(LOG_ERR,"Fatal- Can't init semaphore for conn object: %s",strerror(errno));
|
2014-07-11 22:12:11 +02:00
|
|
|
conn_destroy(conn);
|
|
|
|
return NULL;
|
|
|
|
};
|
|
|
|
conn->recv_packet=conn_q_recv_packet;
|
2015-02-08 21:07:55 +01:00
|
|
|
conn->recv_packet_peek=conn_q_recv_packet_peek;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2015-02-08 21:07:55 +01:00
|
|
|
else{
|
2014-07-11 22:12:11 +02:00
|
|
|
conn->recv_packet = conn_recv_packet;
|
2015-02-08 21:07:55 +01:00
|
|
|
conn->recv_packet_peek = conn_recv_packet_peek;
|
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-02-08 21:07:55 +01:00
|
|
|
conn->send_packet = conn_send_packet;
|
2018-03-25 10:07:39 +02:00
|
|
|
/* conn->send_data_packet = conn_send_data_packet;*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
conn->last_seqnum_received=-1;
|
|
|
|
conn->mtu=1500;
|
|
|
|
|
|
|
|
|
|
|
|
conn->cur_packet=0;
|
|
|
|
conn->recv_timeout=1;
|
|
|
|
|
|
|
|
conn->seqnum=-1;
|
|
|
|
conn->write = conn->send_packet;
|
|
|
|
conn->read = conn->recv_packet;
|
|
|
|
|
2018-03-25 10:07:39 +02:00
|
|
|
/* conn->write_data = conn->send_data_packet; */
|
2016-03-27 04:45:14 +02:00
|
|
|
|
2016-03-12 22:28:51 +01:00
|
|
|
conn->dtls_mtu = 1500;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|