GnuTLS is now supported on client side.
FossilOrigin-Name: 1cb3d6ca96bf4b9447418b5a3983a3abc8918d60ef745cc2600a353f4a7f559b
This commit is contained in:
parent
7264630ca8
commit
2dd03898b4
@ -1,4 +1,4 @@
|
|||||||
include ../Config.mak
|
include ../Config.mak
|
||||||
|
|
||||||
WITH_GNUTLS=1
|
WITH_GNUTLS=1
|
||||||
WITH_OPENSSL=0
|
WITH_OPENSSL=1
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
|
include ../Config.mak
|
||||||
|
|
||||||
#SSL settings
|
#
|
||||||
SSL_LIBRARY=OPENSSL
|
SSL_LIBRARY=GNUTLS
|
||||||
USE_CONTRIB_OPENSSL=1
|
|
||||||
|
|
||||||
# C compiler settings
|
|
||||||
CC=clang
|
|
||||||
|
|
||||||
|
|
||||||
CFLAGS += -I/usr/include/libnl3
|
CFLAGS += -I/usr/include/libnl3
|
||||||
@ -17,4 +15,8 @@ LDFLAGS += -L../contrib/libubox/build
|
|||||||
CONF_LIBRARY=UCI
|
CONF_LIBRARY=UCI
|
||||||
USE_CONTRIB_UCI=0
|
USE_CONTRIB_UCI=0
|
||||||
|
|
||||||
|
ifeq ($(USE_CONTRIB_UCI),1)
|
||||||
|
CFLAGS+=-I../contrib/uci
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,6 +154,7 @@ CFLAGS+=$(GNUTLS_CFLAGS)
|
|||||||
CFLAGS+=-DWITH_GNUTLS
|
CFLAGS+=-DWITH_GNUTLS
|
||||||
DTLSOBJS+= dtls_gnutls.o \
|
DTLSOBJS+= dtls_gnutls.o \
|
||||||
dtls_gnutls_accept.o \
|
dtls_gnutls_accept.o \
|
||||||
|
dtls_gnutls_connect.o \
|
||||||
dtls_gnutls_bio.o \
|
dtls_gnutls_bio.o \
|
||||||
dtls_gnutls_get_cipher.o
|
dtls_gnutls_get_cipher.o
|
||||||
endif
|
endif
|
||||||
|
@ -57,10 +57,6 @@ struct conn * conn_create(int sock, struct sockaddr * addr, int qsize)
|
|||||||
if (addr)
|
if (addr)
|
||||||
sock_copyaddr(&conn->addr,addr);
|
sock_copyaddr(&conn->addr,addr);
|
||||||
|
|
||||||
// printf("AF IN: %i\n",addr->sa_family);
|
|
||||||
// char str[200] ;
|
|
||||||
// sock_addrtostr((struct sockaddr*)&conn->addr,str,200);
|
|
||||||
// printf("CONN CREATOR: %s\n",str);
|
|
||||||
|
|
||||||
conn->fragman = fragman_create();
|
conn->fragman = fragman_create();
|
||||||
if (conn->fragman==NULL){
|
if (conn->fragman==NULL){
|
||||||
@ -81,15 +77,18 @@ struct conn * conn_create(int sock, struct sockaddr * addr, int qsize)
|
|||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
conn->recv_packet=conn_q_recv_packet;
|
conn->recv_packet=conn_q_recv_packet;
|
||||||
|
conn->recv_packet_peek=conn_q_recv_packet_peek;
|
||||||
}
|
}
|
||||||
else
|
else{
|
||||||
conn->recv_packet = conn_recv_packet;
|
conn->recv_packet = conn_recv_packet;
|
||||||
|
conn->recv_packet_peek = conn_recv_packet_peek;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn->send_packet = conn_send_packet;
|
||||||
|
|
||||||
conn->last_seqnum_received=-1;
|
conn->last_seqnum_received=-1;
|
||||||
conn->mtu=1500;
|
conn->mtu=1500;
|
||||||
|
|
||||||
conn->send_packet = conn_send_packet;
|
|
||||||
|
|
||||||
conn->cur_packet=0;
|
conn->cur_packet=0;
|
||||||
conn->recv_timeout=1;
|
conn->recv_timeout=1;
|
||||||
|
@ -69,6 +69,7 @@ struct conn{
|
|||||||
/* receive and send methods */
|
/* receive and send methods */
|
||||||
|
|
||||||
int (*recv_packet)(struct conn *, uint8_t *,int);
|
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);
|
int (*send_packet)(struct conn *, const uint8_t *, int);
|
||||||
|
|
||||||
int (*read)(struct conn *, uint8_t*, int);
|
int (*read)(struct conn *, uint8_t*, int);
|
||||||
@ -147,8 +148,8 @@ 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(struct conn * conn, uint8_t * buffer,int len);
|
||||||
extern int conn_q_recv_packet_peek(struct conn * conn, uint8_t * buffer,int len);
|
extern int conn_q_recv_packet_peek(struct conn * conn, uint8_t * buffer,int len);
|
||||||
|
|
||||||
|
|
||||||
extern int conn_recv_packet(struct conn* conn,uint8_t *buf,int len);
|
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);
|
||||||
|
|
||||||
extern int conn_send_response(struct conn * conn,struct cwmsg * cwmsg,int seqnum);
|
extern int conn_send_response(struct conn * conn,struct cwmsg * cwmsg,int seqnum);
|
||||||
extern struct cwrmsg * conn_get_response(struct conn * conn);
|
extern struct cwrmsg * conn_get_response(struct conn * conn);
|
||||||
|
@ -44,24 +44,24 @@ struct conn * conn_create_noq(int sock, struct sockaddr * addr)
|
|||||||
if (addr)
|
if (addr)
|
||||||
sock_copyaddr(&conn->addr,addr);
|
sock_copyaddr(&conn->addr,addr);
|
||||||
|
|
||||||
// printf("AF IN: %i\n",addr->sa_family);
|
|
||||||
// char str[200] ;
|
|
||||||
// sock_addrtostr((struct sockaddr*)&conn->addr,str,200);
|
|
||||||
// printf("CONN CREATOR: %s\n",str);
|
|
||||||
|
|
||||||
|
/* create the CAPWAP framentation manager */
|
||||||
conn->fragman = fragman_create();
|
conn->fragman = fragman_create();
|
||||||
if (conn->fragman==NULL){
|
if (conn->fragman==NULL){
|
||||||
conn_destroy(conn);
|
conn_destroy(conn);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set packet recieve and send methods */
|
||||||
conn->recv_packet = conn_recv_packet;
|
conn->recv_packet = conn_recv_packet;
|
||||||
|
conn->recv_packet_peek = conn_recv_packet_peek;
|
||||||
|
conn->send_packet = conn_send_packet;
|
||||||
|
|
||||||
|
|
||||||
|
/* misc settings */
|
||||||
conn->last_seqnum_received=-1;
|
conn->last_seqnum_received=-1;
|
||||||
conn->mtu=1500;
|
conn->mtu=1500;
|
||||||
|
|
||||||
conn->send_packet = conn_send_packet;
|
|
||||||
|
|
||||||
conn->cur_packet=0;
|
conn->cur_packet=0;
|
||||||
conn->recv_timeout=1;
|
conn->recv_timeout=1;
|
||||||
@ -70,7 +70,6 @@ struct conn * conn_create_noq(int sock, struct sockaddr * addr)
|
|||||||
conn->write = conn->send_packet;
|
conn->write = conn->send_packet;
|
||||||
conn->read = conn->recv_packet;
|
conn->read = conn->recv_packet;
|
||||||
|
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,9 @@
|
|||||||
|
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
|
||||||
int conn_recv_packet(struct conn* conn,uint8_t *buf,int len)
|
int conn_recv_packet_(struct conn* conn,uint8_t *buf,int len,int flags)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
int flags=0;
|
|
||||||
while( (n = recv(conn->sock,(char*)buf,len,flags)) < 0 ){
|
while( (n = recv(conn->sock,(char*)buf,len,flags)) < 0 ){
|
||||||
if (errno!=EINTR)
|
if (errno!=EINTR)
|
||||||
{
|
{
|
||||||
@ -40,3 +39,17 @@ int conn_recv_packet(struct conn* conn,uint8_t *buf,int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* yes, these functions could be better defined as macros in a .h file */
|
||||||
|
|
||||||
|
int conn_recv_packet(struct conn* conn,uint8_t *buf,int len)
|
||||||
|
{
|
||||||
|
return conn_recv_packet_(conn,buf,len,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int conn_recv_packet_peek(struct conn* conn,uint8_t *buf,int len)
|
||||||
|
{
|
||||||
|
int rc = conn_recv_packet_(conn,buf,len,MSG_PEEK);
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,11 @@ int dtls_gnutls_init()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dtls_gnutls_shutdown(struct conn *conn)
|
||||||
|
{
|
||||||
|
/* implement it */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void dtls_gnutls_data_destroy(struct dtls_gnutls_data *d)
|
void dtls_gnutls_data_destroy(struct dtls_gnutls_data *d)
|
||||||
{
|
{
|
||||||
@ -74,7 +79,7 @@ int dtls_gnutls_read(struct conn * conn, uint8_t *buffer, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn)
|
struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn,int config)
|
||||||
{
|
{
|
||||||
struct dtls_gnutls_data *d = malloc(sizeof(struct dtls_gnutls_data));
|
struct dtls_gnutls_data *d = malloc(sizeof(struct dtls_gnutls_data));
|
||||||
if (!d)
|
if (!d)
|
||||||
@ -106,7 +111,7 @@ struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rc = gnutls_init(&d->session, GNUTLS_SERVER | GNUTLS_DATAGRAM);
|
rc = gnutls_init(&d->session, config);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
cw_log(LOG_ERR, "DTLS - Can't init session: %s", gnutls_strerror(rc));
|
cw_log(LOG_ERR, "DTLS - Can't init session: %s", gnutls_strerror(rc));
|
||||||
dtls_gnutls_data_destroy(d);
|
dtls_gnutls_data_destroy(d);
|
||||||
@ -132,10 +137,10 @@ struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnutls_certificate_server_set_request(d->session,GNUTLS_CERT_REQUEST);
|
|
||||||
|
|
||||||
gnutls_transport_set_pull_function(d->session, dtls_gnutls_bio_read);
|
gnutls_transport_set_pull_function(d->session, dtls_gnutls_bio_read);
|
||||||
gnutls_transport_set_push_function(d->session, dtls_gnutls_bio_write);
|
gnutls_transport_set_push_function(d->session, dtls_gnutls_bio_write);
|
||||||
|
gnutls_transport_set_pull_timeout_function(d->session, dtls_gnutls_bio_wait);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ struct dtls_gnutls_data {
|
|||||||
gnutls_priority_t priority_cache;
|
gnutls_priority_t priority_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn);
|
struct dtls_gnutls_data *dtls_gnutls_data_create(struct conn *conn,int config);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ int dtls_gnutls_accept(struct conn *conn)
|
|||||||
if (tlen <0 && errno == EAGAIN)
|
if (tlen <0 && errno == EAGAIN)
|
||||||
continue;
|
continue;
|
||||||
if (tlen < 0 ){
|
if (tlen < 0 ){
|
||||||
/* something went wrong, log a message */
|
/* something went wrong, iwe should log a message */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ int dtls_gnutls_accept(struct conn *conn)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dtls_gnutls_bio_read(conn, buffer, sizeof(buffer));
|
// dtls_gnutls_bio_read(conn, buffer, sizeof(buffer));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -92,11 +92,11 @@ int dtls_gnutls_accept(struct conn *conn)
|
|||||||
cw_dbg(DBG_DTLS, "DTLS - Cookie verified! Starting handshake ...");
|
cw_dbg(DBG_DTLS, "DTLS - Cookie verified! Starting handshake ...");
|
||||||
|
|
||||||
|
|
||||||
d = dtls_gnutls_data_create(conn);
|
d = dtls_gnutls_data_create(conn,GNUTLS_SERVER | GNUTLS_DATAGRAM);
|
||||||
if (!d)
|
if (!d)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
gnutls_transport_set_pull_timeout_function(d->session, dtls_gnutls_bio_wait);
|
gnutls_certificate_server_set_request(d->session,GNUTLS_CERT_REQUEST);
|
||||||
gnutls_dtls_prestate_set(d->session, &prestate);
|
gnutls_dtls_prestate_set(d->session, &prestate);
|
||||||
|
|
||||||
c_timer = cw_timer_start(10);
|
c_timer = cw_timer_start(10);
|
||||||
|
@ -46,13 +46,6 @@ ssize_t dtls_gnutls_bio_write(gnutls_transport_ptr_t b, const void *data, size_t
|
|||||||
return dtls_bio_write(conn,data,len);
|
return dtls_bio_write(conn,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* wait for an incoming packet, used by gnutls to determine if
|
|
||||||
* data is available on "asynchropnous" connections.
|
|
||||||
*
|
|
||||||
* Attention! This function only works for struct conn objects where
|
|
||||||
* queueing is enabled. Used by AC-Tube.
|
|
||||||
*/
|
|
||||||
int dtls_gnutls_bio_wait(gnutls_transport_ptr_t ptr, unsigned int ms)
|
int dtls_gnutls_bio_wait(gnutls_transport_ptr_t ptr, unsigned int ms)
|
||||||
{
|
{
|
||||||
struct conn * conn = (struct conn*)ptr;
|
struct conn * conn = (struct conn*)ptr;
|
||||||
@ -62,7 +55,7 @@ int dtls_gnutls_bio_wait(gnutls_transport_ptr_t ptr, unsigned int ms)
|
|||||||
uint8_t buffer[5];
|
uint8_t buffer[5];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
rc = conn_q_recv_packet_peek(conn,buffer,sizeof(buffer));
|
rc = conn->recv_packet_peek(conn,buffer,sizeof(buffer));
|
||||||
|
|
||||||
}while(!cw_timer_timeout(timer) && rc==GNUTLS_E_AGAIN);
|
}while(!cw_timer_timeout(timer) && rc==GNUTLS_E_AGAIN);
|
||||||
|
|
||||||
|
@ -5,30 +5,14 @@ ifndef CC
|
|||||||
CC=gcc
|
CC=gcc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef INCLUDE_DIR
|
|
||||||
XINCLUDE=-I $(INCLUDE_DIR)
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef LIB_DIR
|
|
||||||
XLIB=-L $(LIB_DIR)
|
|
||||||
endif
|
|
||||||
include ../Config.mak
|
|
||||||
|
|
||||||
|
|
||||||
ifeq ($(USE_CONTRIB_UCI),1)
|
|
||||||
CFLAGS+=-I../contrib/uci
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
WITH_UCI=1
|
|
||||||
|
|
||||||
CFLAGS+=-DWITH_RMAC_SUPPORT
|
CFLAGS+=-DWITH_RMAC_SUPPORT
|
||||||
CFLAGS+=-DWITH_IPV6
|
CFLAGS+=-DWITH_IPV6
|
||||||
CFLAGS+=-DWITH_CW_LOG
|
CFLAGS+=-DWITH_CW_LOG
|
||||||
CFLAGS+=-DWITH_CW_LOG_DEBUG
|
CFLAGS+=-DWITH_CW_LOG_DEBUG
|
||||||
CFLAGS+=-DWITH_DTLS
|
CFLAGS+=-DWITH_DTLS
|
||||||
CFLAGS+=-DWITH_UCI
|
|
||||||
CFLAGS+=$(XINCLUDE)
|
|
||||||
|
|
||||||
|
|
||||||
ifndef ARCH
|
ifndef ARCH
|
||||||
@ -36,32 +20,45 @@ ifndef ARCH
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef CFLAGS
|
|
||||||
CFLAGS += -O2 -Wall -g
|
CFLAGS += -O2 -Wall -g
|
||||||
#endif
|
|
||||||
|
|
||||||
LDFLAGS += -L../../src/capwap/$(ARCH)
|
LDFLAGS += -L../../src/capwap/$(ARCH)
|
||||||
#LDFLAGS += -L/usr/local/lib
|
|
||||||
LDFLAGS += -luci
|
|
||||||
#LDFLAGS += -L../capwap
|
|
||||||
LDFLAGS += $(XLIB)
|
|
||||||
|
|
||||||
#LDFLAGS += -lpthread
|
|
||||||
#LDFLAGS += -lrt
|
|
||||||
|
|
||||||
LIBS+=-lcapwap
|
LIBS+=-lcapwap
|
||||||
#LIBS+=-liw
|
|
||||||
LIBS+=-lnl-3
|
LIBS+=-lnl-3
|
||||||
LIBS+=-lnl-genl-3
|
LIBS+=-lnl-genl-3
|
||||||
LIBS+=$(OPENSSLLIB)
|
|
||||||
#LIBS+=-lcrypto
|
CONFOBJS = wtp_conf.o
|
||||||
#LIBS+=-lrt
|
|
||||||
ifdef WITH_UCI
|
ifeq ($(CONF_LIBRARY),UCI)
|
||||||
|
CFLAGS+=-DWITH_UCI
|
||||||
LIBS+=-luci -lubox
|
LIBS+=-luci -lubox
|
||||||
|
CONFOBJS += conf_uci.o
|
||||||
else
|
else
|
||||||
LIBS+=-lconfuse
|
LIBS+=-lconfuse
|
||||||
|
CONFOBJS += wtp_conf_confuse.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ifeq ($(SSL_LIBRARY),GNUTLS)
|
||||||
|
CFLAGS+=-DWITH_GNUTLS
|
||||||
|
CFLAGS+=$(GNUTLS_CFLAGS)
|
||||||
|
LIBS+=$(GNUTLS_LIBS)
|
||||||
|
LDFLAGS+=$(GNUTLS_LDFLAGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(SSL_LIBRARY),OPENSSL)
|
||||||
|
CFLAGS+=-DWITH_OPENSSL
|
||||||
|
CFLAGS+=$(OPESSL_CFLAGS)
|
||||||
|
LDFLAGS+=$(OPENSSL_LDFLAGS)
|
||||||
|
LIBS+=$(OPENSSL_LIBS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#HA_FILES += ../contrib/hostap/src/drivers/driver_nl80211.o
|
#HA_FILES += ../contrib/hostap/src/drivers/driver_nl80211.o
|
||||||
|
|
||||||
HA_INCS += -I$(INCLUDE_DIR)/libnl-tiny
|
HA_INCS += -I$(INCLUDE_DIR)/libnl-tiny
|
||||||
@ -74,19 +71,11 @@ CFLAGS += $(HA_INCS)
|
|||||||
#CFLAGS += -I../src
|
#CFLAGS += -I../src
|
||||||
#CFLAGS += -I../src/utils
|
#CFLAGS += -I../src/utils
|
||||||
CFLAGS += -I../../src
|
CFLAGS += -I../../src
|
||||||
CFLAGS += -I$(OPENSSLINC)
|
|
||||||
|
|
||||||
#CFLAGS += -I/usr/local/include
|
#CFLAGS += -I/usr/local/include
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CONFOBJS = wtp_conf.o
|
|
||||||
|
|
||||||
ifdef WITH_UCI
|
|
||||||
CONFOBJS += conf_uci.o
|
|
||||||
else
|
|
||||||
CONFOBJS += wtp_conf_confuse.o
|
|
||||||
endif
|
|
||||||
|
|
||||||
OBJS += wtp_main.o
|
OBJS += wtp_main.o
|
||||||
|
|
||||||
@ -127,8 +116,7 @@ endif
|
|||||||
|
|
||||||
|
|
||||||
wtp: $(BCHECK) $(OBJS)
|
wtp: $(BCHECK) $(OBJS)
|
||||||
$(Q)$(CC) $(LDFLAGS) -o wtp $(OBJS) $(LIBS)
|
$(Q)$(CC) $(OBJS) -o wtp $(LDFLAGS) $(LIBS)
|
||||||
|
|
||||||
@$(E) " LD " $@
|
@$(E) " LD " $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
@ -60,20 +60,24 @@ static void read_dbg_options(struct uci_context *ctx, struct uci_section *sectio
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; cw_dbg_cfgstrs[i].name; i++) {
|
for (i=0; cw_dbg_cfgstrs[i].name; i++) {
|
||||||
|
|
||||||
set_dbg_opt(ctx,section,cw_dbg_cfgstrs[i].level,cw_dbg_cfgstrs[i].name);
|
set_dbg_opt(ctx,section,cw_dbg_cfgstrs[i].level,cw_dbg_cfgstrs[i].name);
|
||||||
|
|
||||||
// if (!strcmp(str,cw_dbg_cfgstrs[i].name))
|
|
||||||
// return cw_dbg_cfgstrs[i].level;
|
|
||||||
}
|
}
|
||||||
// return 0;
|
}
|
||||||
|
|
||||||
|
static void read_timers(struct uci_context *ctx,struct uci_section *section)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0; conf_timer_cfgstrs[i].name; i++) {
|
||||||
|
|
||||||
|
const char *str = uci_lookup_option_string(ctx,section,conf_timer_cfgstrs[i].name);
|
||||||
|
if ( str ) {
|
||||||
|
*(conf_timer_cfgstrs[i].value)=atol(str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* set_dbg_opt(ctx,section,DBG_DTLS,"dtls");
|
|
||||||
set_dbg_opt(ctx,section,DBG_DTLS_DETAIL,"dtls_detail");
|
|
||||||
set_dbg_opt(ctx,section,DBG_DTLS_BIO,"dtls_bio");
|
|
||||||
set_dbg_opt(ctx,section,DBG_DTLS_BIO_DMP,"dtls_bio_dmp");
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_config(const char * filename){
|
int read_config(const char * filename){
|
||||||
@ -126,6 +130,7 @@ int read_config(const char * filename){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read_timers(ctx,section);
|
||||||
|
|
||||||
const char *str;
|
const char *str;
|
||||||
str = uci_lookup_option_string(ctx,section,"name");
|
str = uci_lookup_option_string(ctx,section,"name");
|
||||||
|
@ -61,7 +61,7 @@ static int acprint(void *p,void*d) //,int ctr)
|
|||||||
static int msg_cb(void *priv,struct cwrmsg * cwrmsg)
|
static int msg_cb(void *priv,struct cwrmsg * cwrmsg)
|
||||||
{
|
{
|
||||||
if (cwrmsg->type != CWMSG_DISCOVERY_RESPONSE){
|
if (cwrmsg->type != CWMSG_DISCOVERY_RESPONSE){
|
||||||
cw_log_debug0("Expected discovery response, but received %i",cwrmsg->type);
|
cw_dbg(DBG_ERR,"Expected discovery response, but received %i",cwrmsg->type);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ static void rand_sleep(int seconds)
|
|||||||
cw_rand((uint8_t*)&rnd,sizeof(rnd));
|
cw_rand((uint8_t*)&rnd,sizeof(rnd));
|
||||||
uint16_t max = 0-1;
|
uint16_t max = 0-1;
|
||||||
int r = (rnd * usecs) / max;
|
int r = (rnd * usecs) / max;
|
||||||
cw_log_debug0("Sleeping for %u milliseconds\n",r);
|
cw_dbg(DBG_CW_INFO,"Sleeping for %u milliseconds\n",r);
|
||||||
usleep(r*1000);
|
usleep(r*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ static int do_discover_conn(struct conn * conn,struct discovery_info * di)
|
|||||||
#ifdef WITH_CW_LOG_DEBUG
|
#ifdef WITH_CW_LOG_DEBUG
|
||||||
char str[100];
|
char str[100];
|
||||||
sock_addrtostr((struct sockaddr*)&conn->addr,str,100);
|
sock_addrtostr((struct sockaddr*)&conn->addr,str,100);
|
||||||
cw_log_debug0("Sending discovery request to %s",str);
|
// cw_log_debug0("Sending discovery request to %s",str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
@ -158,7 +158,7 @@ static int do_discover_conn(struct conn * conn,struct discovery_info * di)
|
|||||||
continue;
|
continue;
|
||||||
if (errno == EMSGSIZE){
|
if (errno == EMSGSIZE){
|
||||||
conn->mtu-=4;
|
conn->mtu-=4;
|
||||||
cw_log_debug2("Setting mtu to %i",conn->mtu);
|
// cw_log_debug2("Setting mtu to %i",conn->mtu);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ static int do_discover_conn(struct conn * conn,struct discovery_info * di)
|
|||||||
#ifdef WITH_CW_LOG_DEBUG
|
#ifdef WITH_CW_LOG_DEBUG
|
||||||
char str[100];
|
char str[100];
|
||||||
sock_addrtostr((struct sockaddr*)&sa,str,100);
|
sock_addrtostr((struct sockaddr*)&sa,str,100);
|
||||||
cw_log_debug0("Received packet from %s",str);
|
// cw_log_debug0("Received packet from %s",str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct conn * rconn;
|
struct conn * rconn;
|
||||||
@ -279,7 +279,7 @@ ACIPLIST * do_discovery(const char *acaddr)
|
|||||||
if ( discovery_count >= conf_max_discoveries){
|
if ( discovery_count >= conf_max_discoveries){
|
||||||
sulking_state();
|
sulking_state();
|
||||||
discovery_count=0;
|
discovery_count=0;
|
||||||
cw_log_debug0("Entering discovery state");
|
// cw_log_debug0("Entering discovery state");
|
||||||
}
|
}
|
||||||
discovery_count++;
|
discovery_count++;
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ ACIPLIST * do_discovery(const char *acaddr)
|
|||||||
freeaddrinfo(res0);
|
freeaddrinfo(res0);
|
||||||
|
|
||||||
if (di.aciplist->count){
|
if (di.aciplist->count){
|
||||||
cw_log_debug2("Discover responses received: %i\n",di.response_count);
|
// cw_log_debug2("Discover responses received: %i\n",di.response_count);
|
||||||
return di.aciplist;
|
return di.aciplist;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ void acinfo_log_(int level,const struct ac_info *acinfo,const char * xstr)
|
|||||||
{
|
{
|
||||||
char str[8192];
|
char str[8192];
|
||||||
acinfo_print(str,acinfo);
|
acinfo_print(str,acinfo);
|
||||||
cw_log_debug(level,"%s\n%s",xstr,str);
|
// cw_log_debug(level,"%s\n%s",xstr,str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ int join_state(struct conn * conn)
|
|||||||
#ifdef WITH_CW_LOG_DEBUG
|
#ifdef WITH_CW_LOG_DEBUG
|
||||||
char str[64];
|
char str[64];
|
||||||
sock_addrtostr(&conn->addr,str,64);
|
sock_addrtostr(&conn->addr,str,64);
|
||||||
cw_log_debug0("Sending join request to %s",str);
|
// cw_log_debug0("Sending join request to %s",str);
|
||||||
#endif
|
#endif
|
||||||
printf("Seqnum before = %i\n",conn->seqnum);
|
printf("Seqnum before = %i\n",conn->seqnum);
|
||||||
rc = cwsend_join_request(conn,&ri,wtpinfo);
|
rc = cwsend_join_request(conn,&ri,wtpinfo);
|
||||||
@ -46,7 +46,7 @@ int join_state(struct conn * conn)
|
|||||||
|
|
||||||
struct cwrmsg * cwrmsg = conn_get_message(conn);
|
struct cwrmsg * cwrmsg = conn_get_message(conn);
|
||||||
|
|
||||||
cw_log_debug0("Received message %i",cwrmsg->seqnum);
|
// cw_log_debug0("Received message %i",cwrmsg->seqnum);
|
||||||
|
|
||||||
if (cwrmsg->type != CWMSG_JOIN_RESPONSE || cwrmsg->seqnum != conn->seqnum){
|
if (cwrmsg->type != CWMSG_JOIN_RESPONSE || cwrmsg->seqnum != conn->seqnum){
|
||||||
printf("Wrong message\n");
|
printf("Wrong message\n");
|
||||||
@ -91,19 +91,8 @@ int join(struct sockaddr *sa)
|
|||||||
#ifdef WITH_DTLS
|
#ifdef WITH_DTLS
|
||||||
cw_dbg (DBG_DTLS,"Establishing DTLS session with %s",sock_addr2str(sa));
|
cw_dbg (DBG_DTLS,"Establishing DTLS session with %s",sock_addr2str(sa));
|
||||||
|
|
||||||
/*
|
|
||||||
#ifdef WITH_CW_LOG_DEBUG
|
|
||||||
{
|
|
||||||
char str[100];
|
|
||||||
sock_addrtostr(sa,str,100);
|
|
||||||
cw_log_debug0("Establishing DTLS connection to %s",str);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
printf("conf_dtls_cipher %s\n",conf_dtls_cipher);
|
|
||||||
|
|
||||||
if (conf_dtls_psk){
|
if (conf_dtls_psk){
|
||||||
conn->dtls_psk=conf_dtls_psk;
|
conn->dtls_psk=conf_dtls_psk;
|
||||||
conn->dtls_psk_len=strlen(conn->dtls_psk);
|
conn->dtls_psk_len=strlen(conn->dtls_psk);
|
||||||
@ -126,11 +115,14 @@ printf("conf_dtls_cipher %s\n",conf_dtls_cipher);
|
|||||||
dtls_shutdown(conn);
|
dtls_shutdown(conn);
|
||||||
char str[100];
|
char str[100];
|
||||||
sock_addrtostr(sa,str,100);
|
sock_addrtostr(sa,str,100);
|
||||||
cw_log(LOG_ERR,"Cant establish DTLS connection to %s",str);
|
cw_log(LOG_ERR,"Can't establish DTLS connection to %s",str);
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
cw_dbg (DBG_DTLS,"DTLS session established with %s, cipher=%s",sock_addr2str(sa),dtls_get_cipher(conn));
|
cw_dbg (DBG_DTLS,"DTLS session established with %s, cipher=%s",sock_addr2str(sa),dtls_get_cipher(conn));
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -140,7 +132,7 @@ exit(0);
|
|||||||
{
|
{
|
||||||
char str[100];
|
char str[100];
|
||||||
sock_addrtostr(sa,str,100);
|
sock_addrtostr(sa,str,100);
|
||||||
cw_log_debug0("DTLS connection to %s established",str);
|
// cw_log_debug0("DTLS connection to %s established",str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -40,13 +40,13 @@ struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg)
|
|||||||
|
|
||||||
#ifdef WITH_CW_LOG_DEBUG
|
#ifdef WITH_CW_LOG_DEBUG
|
||||||
if (i>0){
|
if (i>0){
|
||||||
cw_log_debug1("Retransmitting request, type=%i,seqnum=%i",cwmsg->type,cwmsg->seqnum);
|
// cw_log_debug1("Retransmitting request, type=%i,seqnum=%i",cwmsg->type,cwmsg->seqnum);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rc = conn_send_cwmsg(conn,cwmsg);
|
int rc = conn_send_cwmsg(conn,cwmsg);
|
||||||
if (rc<0){
|
if (rc<0){
|
||||||
cw_log_debug1("Error sending request, type=%i, seqnum %i, %s",cwmsg->type,cwmsg->seqnum,strerror(errno));
|
// cw_log_debug1("Error sending request, type=%i, seqnum %i, %s",cwmsg->type,cwmsg->seqnum,strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct cwrmsg * r = get_response(conn,cwmsg->type+1,cwmsg->seqnum);
|
struct cwrmsg * r = get_response(conn,cwmsg->type+1,cwmsg->seqnum);
|
||||||
@ -74,7 +74,7 @@ int run(struct conn * conn)
|
|||||||
|
|
||||||
// cwsend_echo_request(conn,&radioinfo);
|
// cwsend_echo_request(conn,&radioinfo);
|
||||||
|
|
||||||
cw_log_debug1("Sending echo request");
|
// cw_log_debug1("Sending echo request");
|
||||||
cwmsg_init_echo_request(&cwmsg,buffer,conn,&radioinfo);
|
cwmsg_init_echo_request(&cwmsg,buffer,conn,&radioinfo);
|
||||||
struct cwrmsg * rc = send_request(conn,&cwmsg);
|
struct cwrmsg * rc = send_request(conn,&cwmsg);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ int run(struct conn * conn)
|
|||||||
if (rc==0){
|
if (rc==0){
|
||||||
|
|
||||||
dtls_shutdown(conn);
|
dtls_shutdown(conn);
|
||||||
cw_log_debug1("Connection lost, no echo response");
|
// cw_log_debug1("Connection lost, no echo response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
echo_interval_timer=time(NULL);
|
echo_interval_timer=time(NULL);
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
int sulking_state()
|
int sulking_state()
|
||||||
{
|
{
|
||||||
cw_log_debug0("Entering Sulking state");
|
cw_dbg(DBG_CW_INFO,"Entering Sulking state");
|
||||||
cw_log_debug0("Sleeping for %i seconds",conf_silent_interval);
|
cw_dbg(DBG_CW_INFO,"Sleeping for %i seconds",conf_silent_interval);
|
||||||
sleep(conf_silent_interval);
|
sleep(conf_silent_interval);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,13 @@ uint8_t * conf_model_no;
|
|||||||
uint8_t * cont_serial_no;
|
uint8_t * cont_serial_no;
|
||||||
|
|
||||||
|
|
||||||
|
LONGSTRS conf_timer_cfgstrs[] = {
|
||||||
|
"max_discovery_interval",&conf_max_discovery_interval,
|
||||||
|
"discovery_interval",&conf_discovery_interval,
|
||||||
|
"max_discoveries",&conf_max_discoveries,
|
||||||
|
"silent_interval",&conf_silent_interval,
|
||||||
|
0,0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int wtpconf_primary_if()
|
int wtpconf_primary_if()
|
||||||
@ -173,7 +179,7 @@ int wtpconf_ac_list()
|
|||||||
conf_ac_list_len=len;
|
conf_ac_list_len=len;
|
||||||
#ifdef WITH_CW_LOG_DEBUG
|
#ifdef WITH_CW_LOG_DEBUG
|
||||||
for (i=0; i<conf_ac_list_len; i++){
|
for (i=0; i<conf_ac_list_len; i++){
|
||||||
cw_log_debug0("Using AC: %s\n",conf_ac_list[i]);
|
cw_dbg(DBG_CW_INFO,"Using AC: %s\n",conf_ac_list[i]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -117,4 +117,15 @@ extern int conf_mtu_discovery;
|
|||||||
extern int conf_mtu;
|
extern int conf_mtu;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
long *value;
|
||||||
|
}LONGSTRS;
|
||||||
|
extern LONGSTRS conf_timer_cfgstrs[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -94,13 +94,6 @@ int do_connect(void *priv,void *data)
|
|||||||
|
|
||||||
int wtp_main(const char *ad)
|
int wtp_main(const char *ad)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cw_dbg_opt_level = DBG_DTLS | DBG_CW_INFO | DBG_ALL;
|
|
||||||
// gr();
|
|
||||||
// exit(0);
|
|
||||||
|
|
||||||
wtpconf_preinit();
|
wtpconf_preinit();
|
||||||
|
|
||||||
if (!read_config("./wtp_uci.conf")){
|
if (!read_config("./wtp_uci.conf")){
|
||||||
@ -109,7 +102,6 @@ int wtp_main(const char *ad)
|
|||||||
|
|
||||||
cw_dbg_opt_level = conf_dbg_level;
|
cw_dbg_opt_level = conf_dbg_level;
|
||||||
|
|
||||||
|
|
||||||
wtpconf_init();
|
wtpconf_init();
|
||||||
|
|
||||||
|
|
||||||
@ -150,9 +142,9 @@ int wtp_main(const char *ad)
|
|||||||
}
|
}
|
||||||
}while (!aciplist);
|
}while (!aciplist);
|
||||||
|
|
||||||
cw_log_debug0("Entering join state");
|
// cw_log_debug0("Entering join state");
|
||||||
if (!aciplist){
|
if (!aciplist){
|
||||||
cw_log_debug0("Don't got any discovery response");
|
// cw_log_debug0("Don't got any discovery response");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,16 @@ config 'wtp'
|
|||||||
# default is gnu
|
# default is gnu
|
||||||
option vendor_id
|
option vendor_id
|
||||||
|
|
||||||
|
option max_discovery_interval 30
|
||||||
|
option discovery_interval 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
config 'dbg'
|
||||||
|
# defbug options
|
||||||
|
option dtls 0
|
||||||
|
option dtls_detail 0
|
||||||
|
option dtls_bio 0
|
||||||
|
option dtls_bio_dmp 0
|
||||||
|
|
||||||
|
|
||||||
option dbg all, nothing
|
|
||||||
|
Loading…
Reference in New Issue
Block a user