More work on CW VM code ..
FossilOrigin-Name: 3b0cb324535527b32d0e938b03151c75f6100ca2059fc121e2c4d350a8caf8a4
This commit is contained in:
@ -21,7 +21,7 @@ endif
|
||||
|
||||
|
||||
CFLAGS += -Os -Wall -g
|
||||
CFLAGS += -Os -Wall
|
||||
#CFLAGS += -Os -Wall
|
||||
LDFLAGS += -L../../src/capwap/$(ARCH)
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "capwap/acinfo.h"
|
||||
#include "capwap/sock.h"
|
||||
#include "capwap/cw_util.h"
|
||||
#include "capwap/aciplist.h"
|
||||
#include "capwap/acpriolist.h"
|
||||
|
||||
|
||||
#include "wtp.h"
|
||||
@ -41,26 +43,109 @@
|
||||
|
||||
|
||||
|
||||
cw_aciplist_t cw_select_ac(struct conn *conn, cw_itemstore_t dis)
|
||||
{
|
||||
|
||||
cw_aciplist_t aciplist = cw_aciplist_create();
|
||||
if (!aciplist) {
|
||||
cw_log(LOG_ERROR, "Can't allocate aciplist");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* get the AC Name with Priority list */
|
||||
cw_acpriolist_t priolist;
|
||||
priolist = cw_itemstore_get_avltree(conn->local, CW_ITEM_AC_PRIO_LIST);
|
||||
|
||||
cw_aciplist_t resultlist=cw_aciplist_create();
|
||||
|
||||
|
||||
DEFINE_AVLITER(i, dis);
|
||||
avliter_foreach(&i){
|
||||
cw_itemstore_t ac = ((cw_item_t *) (avliter_get(&i)))->data;
|
||||
|
||||
char *ac_name = cw_itemstore_get_str(ac, CW_ITEM_AC_NAME);
|
||||
|
||||
int prio = 256;
|
||||
if (ac_name) {
|
||||
/* See if we can find AC Name in Priority List */
|
||||
if (priolist)
|
||||
prio = cw_acpriolist_get(priolist, ac_name);
|
||||
else
|
||||
prio = 256;
|
||||
|
||||
}
|
||||
|
||||
cw_aciplist_t acips =
|
||||
cw_itemstore_get_avltree(ac, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
|
||||
|
||||
DEFINE_AVLITER(i2, acips);
|
||||
avliter_foreach(&i2){
|
||||
cw_acip_t *acip = avliter_get(&i2);
|
||||
cw_acip_t *n = malloc(sizeof(cw_acip_t));
|
||||
memcpy(n,acip,sizeof(cw_acip_t));
|
||||
|
||||
n->wtp_count |= prio<<16;
|
||||
cw_aciplist_del(resultlist,n);
|
||||
cw_aciplist_add(resultlist,n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resultlist;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int run_discovery(struct conn *conn)
|
||||
{
|
||||
conn->capwap_state=CW_STATE_DISCOVERY;
|
||||
cw_itemstore_set_byte(conn->local,CW_ITEM_DISCOVERY_TYPE,CW_DISCOVERY_TYPE_UNKNOWN);
|
||||
// conn->incomming = cw_itemstore_create();
|
||||
|
||||
conn->capwap_state = CW_STATE_DISCOVERY;
|
||||
cw_itemstore_set_byte(conn->outgoing, CW_ITEM_DISCOVERY_TYPE,
|
||||
CW_DISCOVERY_TYPE_UNKNOWN);
|
||||
|
||||
|
||||
cw_init_request(conn,CW_MSG_DISCOVERY_REQUEST);
|
||||
cw_put_msg(conn,conn->req_buffer);
|
||||
conn_send_msg(conn,conn->req_buffer);
|
||||
cw_init_request(conn, CW_MSG_DISCOVERY_REQUEST);
|
||||
cw_put_msg(conn, conn->req_buffer);
|
||||
conn_send_msg(conn, conn->req_buffer);
|
||||
|
||||
|
||||
time_t timer = cw_timer_start(10);
|
||||
time_t timer = cw_timer_start(0);
|
||||
|
||||
while (!cw_timer_timeout(timer)
|
||||
&& conn->capwap_state == CW_STATE_DISCOVERY) {
|
||||
cw_read_messages(conn);
|
||||
printf ("Got one annswer\n");
|
||||
|
||||
}
|
||||
cw_itemstore_t discs;
|
||||
|
||||
while (!cw_timer_timeout(timer)
|
||||
&& conn->capwap_state == CW_STATE_DISCOVERY) {
|
||||
avltree_del_all(conn->incomming);
|
||||
|
||||
int rc = cw_read_messages(conn);
|
||||
|
||||
if (rc<0) {
|
||||
if (errno==EAGAIN)
|
||||
continue;
|
||||
|
||||
cw_log(LOG_ERROR,"Error reading messages: %s",strerror(errno));
|
||||
break;
|
||||
}
|
||||
discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES);
|
||||
}
|
||||
|
||||
|
||||
int i;
|
||||
|
||||
cw_aciplist_t list = cw_select_ac(conn, discs);
|
||||
|
||||
DEFINE_AVLITER(ii,list);
|
||||
avliter_foreach(&ii){
|
||||
cw_acip_t * ip = avliter_get(&ii);
|
||||
|
||||
}
|
||||
|
||||
avltree_del_all(conn->remote);
|
||||
|
||||
cw_itemstore_set_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -70,50 +155,50 @@ static int run_discovery(struct conn *conn)
|
||||
|
||||
/**
|
||||
* Run discovery for on address (eg broadcast 255.255.255.255)
|
||||
*/
|
||||
*/
|
||||
static int cw_run_discovery(struct conn *conn, const char *acaddr)
|
||||
{
|
||||
|
||||
/* get addr of destination */
|
||||
/* get addr of destination */
|
||||
struct addrinfo hints;
|
||||
struct addrinfo * res,*res0;
|
||||
memset(&hints,0,sizeof(hints));
|
||||
struct addrinfo *res, *res0;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
|
||||
int rc = getaddrinfo(acaddr,conf_control_port,&hints,&res0);
|
||||
if(rc){
|
||||
cw_log(LOG_ERR,"Can't connect to AC %s: %s",acaddr,gai_strerror(rc));
|
||||
int rc = getaddrinfo(acaddr, conf_control_port, &hints, &res0);
|
||||
if (rc) {
|
||||
cw_log(LOG_ERR, "Can't connect to AC %s: %s", acaddr, gai_strerror(rc));
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(res=res0; res; res=res->ai_next)
|
||||
{
|
||||
for (res = res0; res; res = res->ai_next) {
|
||||
|
||||
int sockfd;
|
||||
int opt;
|
||||
sockfd=socket(res->ai_family,SOCK_DGRAM,0);
|
||||
if (sockfd == -1){
|
||||
cw_log(LOG_ERR,"Can't create socket for %s: %s",acaddr,strerror(errno));
|
||||
sockfd = socket(res->ai_family, SOCK_DGRAM, 0);
|
||||
if (sockfd == -1) {
|
||||
cw_log(LOG_ERR, "Can't create socket for %s: %s", acaddr,
|
||||
strerror(errno));
|
||||
continue;
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt))<0){
|
||||
cw_log(LOG_ERR,"Can't set broadcast sockopt");
|
||||
}
|
||||
sock_set_recvtimeout(sockfd,1);
|
||||
sock_set_dontfrag(sockfd,0);
|
||||
|
||||
sock_copyaddr(&conn->addr,res->ai_addr);
|
||||
conn->sock=sockfd;
|
||||
opt = 1;
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt)) < 0) {
|
||||
cw_log(LOG_ERR, "Can't set broadcast sockopt");
|
||||
}
|
||||
sock_set_recvtimeout(sockfd, 1);
|
||||
sock_set_dontfrag(sockfd, 0);
|
||||
|
||||
sock_copyaddr(&conn->addr, res->ai_addr);
|
||||
conn->sock = sockfd;
|
||||
|
||||
run_discovery(conn);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
freeaddrinfo(res0);
|
||||
@ -124,7 +209,8 @@ static int cw_run_discovery(struct conn *conn, const char *acaddr)
|
||||
|
||||
int discovery()
|
||||
{
|
||||
struct conn * conn = get_conn();
|
||||
cw_run_discovery(conn,"255.255.255.255");
|
||||
struct conn *conn = get_conn();
|
||||
cw_run_discovery(conn, "255.255.255.255");
|
||||
conn->capwap_state=CW_STATE_JOIN;
|
||||
return 0;
|
||||
}
|
||||
|
123
src/wtp/join.c
123
src/wtp/join.c
@ -12,6 +12,8 @@
|
||||
#include "capwap/cw_log.h"
|
||||
#include "capwap/sock.h"
|
||||
#include "capwap/dtls.h"
|
||||
#include "capwap/aciplist.h"
|
||||
#include "capwap/capwap_items.h"
|
||||
|
||||
/*
|
||||
#define acinfo_log acinfo_log_
|
||||
@ -88,8 +90,129 @@ acinfo.result_code=99;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
int run_join_d(struct sockaddr *sa)
|
||||
{
|
||||
struct conn *conn = get_conn();
|
||||
conn->capwap_state=CW_STATE_JOIN;
|
||||
|
||||
int sockfd;
|
||||
int rc;
|
||||
|
||||
sockfd = socket(AF_INET,SOCK_DGRAM,0);
|
||||
if (sockfd==-1){
|
||||
cw_log(LOG_ERR,"Can't create socket: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
sock_set_recvtimeout(sockfd,1);
|
||||
|
||||
rc = connect(sockfd,(struct sockaddr*)sa,sock_addrlen((struct sockaddr*)sa));
|
||||
|
||||
if (rc<0){
|
||||
cw_log(LOG_ERR,"Can't connect to %s: %s\n",sock_addr2str(sa),strerror(errno));
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
conn->sock=sockfd;
|
||||
sock_copyaddr(&conn->addr,sa);
|
||||
|
||||
cw_dbg (DBG_DTLS,"Establishing DTLS session with %s",sock_addr2str(sa));
|
||||
|
||||
if (conf_dtls_psk){
|
||||
conn->dtls_psk=conf_dtls_psk;
|
||||
conn->dtls_psk_len=strlen(conn->dtls_psk);
|
||||
conn->dtls_cipher=conf_dtls_cipher;
|
||||
}
|
||||
|
||||
if (conf_sslkeyfilename && conf_sslcertfilename){
|
||||
|
||||
conn->dtls_key_file = conf_sslkeyfilename;
|
||||
conn->dtls_cert_file = conf_sslcertfilename;
|
||||
conn->dtls_key_pass = conf_sslkeypass;
|
||||
conn->dtls_cipher=conf_dtls_cipher;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
rc = dtls_connect(conn);
|
||||
if (rc!=1){
|
||||
dtls_shutdown(conn);
|
||||
cw_log(LOG_ERR,"Can't establish DTLS connection to %s", sock_addr2str(sa));
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
cw_dbg (DBG_DTLS,"DTLS Connection successful established with %s",sock_addr2str(sa));
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int run_join(struct conn * conn)
|
||||
{
|
||||
|
||||
// cw_init_request(conn, CW_MSG_JOIN_REQUEST);
|
||||
// if ( cw_put_msg(conn, conn->req_buffer) == -1 )
|
||||
// return 0;
|
||||
//
|
||||
// conn_send_msg(conn, conn->req_buffer);
|
||||
|
||||
int rc = cw_send_request(conn,CW_MSG_JOIN_REQUEST);
|
||||
|
||||
if (rc >=0 ) {
|
||||
cw_dbg(DBG_ELEM,"Join Result: %d - %s",rc,cw_strresult(rc));
|
||||
|
||||
}
|
||||
if (rc != 0 && rc != 2) {
|
||||
cw_log(LOG_ERR,"Join to %s was not successful.",sock_addr2str(&conn->addr));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int join()
|
||||
{
|
||||
struct conn * conn = get_conn();
|
||||
cw_aciplist_t iplist = cw_itemstore_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
|
||||
if (!iplist){
|
||||
cw_log(LOG_ERR,"No Ips to join controller.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_AVLITER(ii,iplist);
|
||||
avliter_foreach(&ii){
|
||||
cw_acip_t * ip = avliter_get(&ii);
|
||||
|
||||
cw_dbg(DBG_ELEM,"Going to join CAWAP controller on %s",sock_addr2str(&ip->ip));
|
||||
|
||||
int rc = run_join_d((struct sockaddr*)&ip->ip);
|
||||
if (!rc)
|
||||
continue;
|
||||
rc = run_join(conn);
|
||||
if (rc){
|
||||
conn->capwap_state=CW_STATE_CONFIGURE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int join(struct sockaddr *sa)
|
||||
{
|
||||
int sockfd;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "capwap/conn.h"
|
||||
#include "capwap/cw_log.h"
|
||||
#include "capwap/dtls.h"
|
||||
#include "capwap/acpriolist.h"
|
||||
|
||||
#include "wtp.h"
|
||||
#include "wtp_conf.h"
|
||||
@ -43,8 +44,11 @@ int main()
|
||||
|
||||
|
||||
cw_register_actions_capwap_wtp(&capwap_actions);
|
||||
////cw_register_actions_capwap_80211_wtp(&capwap_actions);
|
||||
|
||||
conn->actions = &capwap_actions;
|
||||
conn->remote = cw_itemstore_create();
|
||||
conn->outgoing = cw_itemstore_create();
|
||||
conn->incomming = cw_itemstore_create();
|
||||
conn->local = cw_itemstore_create();
|
||||
|
||||
cw_itemstore_t board_data = cw_itemstore_create();
|
||||
@ -59,9 +63,20 @@ int main()
|
||||
|
||||
|
||||
|
||||
cw_itemstore_set_avltree(conn->local, CW_ITEM_WTP_BOARD_DATA, board_data);
|
||||
cw_itemstore_set_avltree(conn->outgoing, CW_ITEM_WTP_BOARD_DATA, board_data);
|
||||
|
||||
cw_acpriolist_t acprios = cw_acpriolist_create();
|
||||
cw_acpriolist_set(acprios,"Master AC",strlen("Master AC"),1);
|
||||
cw_acpriolist_set(acprios,"AC8new",strlen("AC8new"),12);
|
||||
|
||||
cw_itemstore_set_avltree(conn->local,CW_ITEM_AC_PRIO_LIST,acprios);
|
||||
|
||||
cw_itemstore_set_str(conn->local,CW_ITEM_LOCATION_DATA,"Berlin");
|
||||
cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube");
|
||||
|
||||
|
||||
discovery();
|
||||
join();
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user