/* This file is part of actube. actube 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 . */ #include #include #include #include #include #include #include #include #include "actube.h" #include "wtplist.h" #include "dtls.h" #include "cw_log.h" #include "conf.h" #include "sock.h" #include "socklist.h" #include "db.h" int ac_run(); void alive_thread(void *data) { while(1){ sleep(5); db_ping(); } } #include "cw_action.h" cw_actionlist_t the_tree; int dstart(struct conn *conn,struct cw_action a,uint8_t *data,int len) { printf("DISCO STart Action!!\n"); } int main (int argc, const char * argv[]) { cw_actionlist_t t = cw_actionlist_create(); the_tree=t; cw_action_t discovery_actions[] = { { CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST,-1,0,0, dstart }, {CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST, CW_ELEM_DISCOVERY_TYPE}, {CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST, CW_ELEM_WTP_BOARD_DATA}, {CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST, CW_ELEM_WTP_DESCRIPTOR}, {CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST, CW_ELEM_WTP_FRAME_TUNNEL_MODE}, {CW_STATE_DISCOVERY,CW_MSG_DISCOVERY_REQUEST, CW_ELEM_WTP_MAC_TYPE}, {0} }; cw_action_t join_actions[] = { {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST,-1,0,0}, {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST, CW_ELEM_DISCOVERY_TYPE}, {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST, CW_ELEM_WTP_BOARD_DATA}, {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST, CW_ELEM_WTP_DESCRIPTOR}, {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST, CW_ELEM_WTP_FRAME_TUNNEL_MODE}, {CW_STATE_JOIN,CW_MSG_JOIN_REQUEST, CW_ELEM_WTP_MAC_TYPE}, {0} }; cw_register_actions(t,discovery_actions); cw_register_actions(t,join_actions); #define CW_NAME_DISCOVER_REQUEST "Discovery Request" /* int i; for(i=0; discovery[i].capwap_state!=CW_STATE_MAX; i++){ printf("State: %d MSG_ID: %d ELEM_ID: %d\n",discovery[i].capwap_state,discovery[i].msg_id,discovery[i].elem_id); void * rc = msgtree_add(t,&(discovery[i])); printf("Added to tree %p\n",rc); } */ /* e.capwap_state=0; e.msg_id = CW_MSG_DISCOVERY_REQUEST; e.elem_id = CW_ELEM_AC_NAME; e.name = "AC Name"; msgtree_add(t,&e); */ // send_image_file(0,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAP.tar"); cw_log_name="AC-Tube"; read_config("ac.conf"); // cw_log_debug_level=conf_debug_level; cw_log(LOG_INFO,"Starting AC-Tube, Name=%s, ID=%s",conf_acname,conf_acid); // cw_dbg_opt_level= DBG_CW_MSGELEM_DMP | // DBG_CW_MSGELEM | DBG_CW_PKT| DBG_CW_RFC | DBG_ERR | DBG_CW_MSG | DBG_DTLS ; //| DBG_ALL; cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP; // cw_log_dbg(DBG_CW_MSG,"Hello %s","World"); db_init(); db_start(); db_ping(); pthread_t alth; pthread_create (&alth, NULL, alive_thread, (void *)0); #ifdef WITH_DTLS dtls_init(); #endif if (!socklist_init()) goto errX; if (!wtplist_init()) goto errX; int rc = ac_run(); errX: wtplist_destroy(); socklist_destroy(); return rc; } void process_ctrl_packet(int index, struct sockaddr * addr, uint8_t * buffer, int len); #define AC_PROTO_CAPWAP 0 #define AC_PROTO_LWAPP 1 int ac_run() { if (!conf_listen_addrs_len){ cw_log(LOG_ERR,"Fatal error: No listen addresses found."); return 1; } /* it is important to create the unicast sockets first, * because when we create the mcast an bcast sockets next * we will look for already created sockets to find a * good unicast reply socket */ int i; for(i=0; imax) max=socklist[i].sockfd; } /* wait for an event */ int n; while((n=select(max+1, &fset, NULL, NULL, NULL)) < 0) { if (errno != EINTR) return n; } /* process the received packet */ for( i=0; i