2014-07-11 22:12:11 +02:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <stdio.h>
|
2015-03-30 07:56:42 +02:00
|
|
|
#include <stdlib.h>
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <unistd.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
2015-10-18 10:14:33 +02:00
|
|
|
//#include <netinet/in.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include "actube.h"
|
|
|
|
#include "wtplist.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/dtls.h"
|
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/dbg.h"
|
|
|
|
#include "cw/sock.h"
|
2015-10-18 10:14:33 +02:00
|
|
|
#include "conf.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include "socklist.h"
|
|
|
|
|
2014-08-25 22:38:52 +02:00
|
|
|
#include "db.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/capwap_items.h"
|
|
|
|
#include "cw/capwap_cisco.h"
|
|
|
|
#include "cw/capwap_80211.h"
|
|
|
|
#include "cw/action.h"
|
|
|
|
#include "cw/capwap_crypto.h"
|
|
|
|
#include "cw/mbag.h"
|
2015-04-29 12:22:28 +02:00
|
|
|
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
#include "ac.h"
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/format.h"
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
int ac_run();
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
static void *alive_thread(void *data)
|
2014-08-25 22:38:52 +02:00
|
|
|
{
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Ping the database every 5 seconds */
|
2015-10-18 10:14:33 +02:00
|
|
|
while (1) {
|
2014-08-25 22:38:52 +02:00
|
|
|
sleep(5);
|
|
|
|
db_ping();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
#include <getopt.h>
|
|
|
|
static int parse_args(int argc, char *argv[])
|
2015-04-07 07:42:36 +02:00
|
|
|
{
|
2015-10-18 10:14:33 +02:00
|
|
|
int getopt_ret, option_index;
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
2016-02-14 12:11:52 +01:00
|
|
|
{"version", optional_argument, NULL, 'v'},
|
2015-10-18 10:14:33 +02:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
int o;
|
|
|
|
while ((o = getopt_long(argc, argv, "v", long_options, &option_index)) != -1) {
|
|
|
|
switch (o) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
printf("AC-Tube 0.01, %s\n", SYS_ARCH);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2015-05-01 12:50:28 +02:00
|
|
|
}
|
|
|
|
|
2016-02-22 09:18:35 +01:00
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/mod.h"
|
2016-02-22 09:18:35 +01:00
|
|
|
extern struct mod_ac * cw_get_mod_ac(const char *name);
|
|
|
|
|
2016-03-03 20:46:20 +01:00
|
|
|
#include "cw/mlist.h"
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
static int mcmp(void *v1,void*v2)
|
|
|
|
{
|
|
|
|
return strcmp((char*)v1,(char*)v2);
|
|
|
|
}
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
int rc = 0;
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
struct mlist_elem *e;
|
|
|
|
|
|
|
|
mlist_t * l = mlist_create(mcmp);
|
|
|
|
|
|
|
|
mlist_append(l,"Hallo");
|
|
|
|
|
|
|
|
mlist_append(l,"Welt");
|
|
|
|
|
|
|
|
e = mlist_find(l,NULL,"Welt");
|
|
|
|
|
|
|
|
printf("Found: %p\n",e);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-02-22 18:33:47 +01:00
|
|
|
/*
|
|
|
|
struct mod_ac *m = cw_get_mod_ac("cipwap");
|
|
|
|
printf("Ptr: %p\n",m);
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2016-02-22 18:33:47 +01:00
|
|
|
m->init();
|
|
|
|
*/
|
2016-02-22 09:18:35 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
/* parse arguments */
|
|
|
|
parse_args(argc, argv);
|
2015-05-01 12:50:28 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_log_name = "AC-Tube";
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
read_config("ac.conf");
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Show debug options if there are any set */
|
2015-10-18 10:14:33 +02:00
|
|
|
if (cw_dbg_opt_level)
|
|
|
|
cw_log(LOG_INFO, "Debug Options: %08X", cw_dbg_opt_level);
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* XXX Hard coded debug settigns, set it by config in the future */
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS;
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* Warn, if the "secret" debugging feature for
|
2015-10-18 10:14:33 +02:00
|
|
|
developers is turned on ;) */
|
|
|
|
DBGX("Attention! %s", "DBGX is ON!");
|
2015-04-29 12:42:04 +02:00
|
|
|
|
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Initialize the database */
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!db_init())
|
2015-04-29 12:22:28 +02:00
|
|
|
goto errX;
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
/* Start the database */
|
2015-04-29 12:22:28 +02:00
|
|
|
if (!db_start())
|
|
|
|
goto errX;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
db_ping();
|
2014-08-16 10:13:11 +02:00
|
|
|
|
2015-04-29 19:23:52 +02:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
/* Start a database "pinger thread", which inserts
|
|
|
|
every xx seconds a timestamp into the DB */
|
|
|
|
pthread_t alth;
|
2015-10-18 10:14:33 +02:00
|
|
|
pthread_create(&alth, NULL, alive_thread, NULL);
|
2014-07-13 19:18:56 +02:00
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* Init DTLS library */
|
|
|
|
dtls_init();
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2015-04-29 12:22:28 +02:00
|
|
|
int regn;
|
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* Load CAPWAP base protocol */
|
2016-02-28 13:41:45 +01:00
|
|
|
/* if (conf_capwap_mode == CW_MODE_CIPWAP) {
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_dbg(DBG_INFO, "Loading CIPWAP Actions ...");
|
2015-04-29 12:22:28 +02:00
|
|
|
regn = cw_register_actions_cipwap_ac(&capwap_actions);
|
2015-10-18 10:14:33 +02:00
|
|
|
} else {
|
|
|
|
cw_dbg(DBG_INFO, "Loading standard CAPWAP Actions ...");
|
2015-04-29 12:22:28 +02:00
|
|
|
regn = cw_register_actions_capwap_ac(&capwap_actions);
|
2015-04-26 15:12:44 +02:00
|
|
|
}
|
2016-02-28 13:41:45 +01:00
|
|
|
*/
|
|
|
|
|
2016-03-04 22:10:47 +01:00
|
|
|
//regn = cw_register_actions_capwap_ac(&capwap_actions);
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
|
2016-02-28 15:13:10 +01:00
|
|
|
//struct outelem * l = cw_actionlist_out_get_mlist(capwap_actions.out,CW_MSG_DISCOVERY_RESPONSE);
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2016-02-28 15:13:10 +01:00
|
|
|
//printf("List got: %p\n",l);
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exit(0);
|
|
|
|
|
2015-04-26 15:12:44 +02:00
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
/* Load bindings */
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_dbg(DBG_INFO, "Loading 802.11 Bindings ...");
|
|
|
|
// regn += cw_register_actions_capwap_80211_ac(&capwap_actions);
|
2015-04-29 12:22:28 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
cw_dbg(DBG_INFO, "Registered %d protocol actions and strings.", regn);
|
2015-04-26 15:12:44 +02:00
|
|
|
|
2015-04-05 20:27:17 +02:00
|
|
|
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
ac_global_init();
|
2014-07-11 22:12:11 +02:00
|
|
|
if (!socklist_init())
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
if (!wtplist_init())
|
|
|
|
goto errX;
|
|
|
|
|
|
|
|
|
2015-04-29 12:42:04 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
|
|
|
|
cw_log(LOG_INFO, "Starting AC-Tube, Name=%s, ID=%s", conf_acname, conf_acid);
|
2015-04-05 02:07:59 +02:00
|
|
|
rc = ac_run();
|
2015-10-18 10:14:33 +02:00
|
|
|
errX:
|
2015-04-29 19:23:52 +02:00
|
|
|
/* XXX There is more cleanup to do */
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_destroy();
|
|
|
|
socklist_destroy();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
void process_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
int ac_run()
|
|
|
|
{
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!conf_listen_addrs_len) {
|
|
|
|
cw_log(LOG_ERR, "Fatal error: No listen addresses found.");
|
2014-07-11 22:12:11 +02:00
|
|
|
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;
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_listen_addrs_len; i++) {
|
2016-02-17 16:16:39 +01:00
|
|
|
char addr[100];
|
|
|
|
char port[50];
|
|
|
|
int proto;
|
|
|
|
|
|
|
|
conf_parse_listen_addr(conf_listen_addrs[i], addr, port, &proto);
|
|
|
|
|
|
|
|
|
|
|
|
struct sockaddr sa;
|
|
|
|
|
|
|
|
|
|
|
|
socklist_add_unicast(addr, port,proto);
|
|
|
|
|
|
|
|
//#ifdef WITH_LWAPP
|
|
|
|
// if (conf_lwapp)
|
|
|
|
// socklist_add_unicast(conf_listen_addrs[i], conf_lw_control_port,
|
|
|
|
// AC_PROTO_LWAPP);
|
|
|
|
//#endif
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-17 16:16:39 +01:00
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (socklist_len == 0) {
|
|
|
|
cw_log(LOG_ERR, "Fatal error: Could not setup any listen socket");
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create multicast sockets */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_mcast_groups_len; i++) {
|
2016-02-17 20:25:19 +01:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
socklist_add_multicast(conf_mcast_groups[i], conf_control_port,
|
|
|
|
AC_PROTO_CAPWAP);
|
2014-07-26 20:29:30 +02:00
|
|
|
#ifdef WITH_LWAPP
|
2015-10-18 10:14:33 +02:00
|
|
|
if (conf_lwapp)
|
|
|
|
socklist_add_multicast(conf_mcast_groups[i], conf_lw_control_port,
|
|
|
|
AC_PROTO_LWAPP);
|
|
|
|
#endif
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-02-16 08:13:34 +01:00
|
|
|
/* broadcast socket ipv4 only */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < conf_bcast_addrs_len; i++) {
|
2016-02-17 20:25:19 +01:00
|
|
|
|
|
|
|
char addr[50],port[50];
|
|
|
|
int proto;
|
|
|
|
conf_parse_listen_addr(conf_bcast_addrs[i], addr, port, &proto);
|
|
|
|
|
|
|
|
socklist_add_broadcast(addr,port,proto);
|
2014-07-26 20:29:30 +02:00
|
|
|
#ifdef WITH_LWAPP
|
2015-10-18 10:14:33 +02:00
|
|
|
// printf("Adding %d\n",socklist_len);
|
|
|
|
if (conf_lwapp)
|
|
|
|
socklist_add_broadcast(conf_bcast_addrs[i], conf_lw_control_port,
|
|
|
|
AC_PROTO_LWAPP);
|
|
|
|
// printf ("SI %d, PROTO: %d\n",socklist_len-1,socklist[socklist_len-1].ac_proto);
|
|
|
|
#endif
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
//get_acinfo();
|
2014-07-28 07:07:43 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
while (1) {
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
/* prepare fdset */
|
|
|
|
fd_set fset;
|
|
|
|
int max = 0;
|
|
|
|
FD_ZERO(&fset);
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < socklist_len; i++) {
|
|
|
|
FD_SET(socklist[i].sockfd, &fset);
|
|
|
|
if (socklist[i].sockfd > max)
|
|
|
|
max = socklist[i].sockfd;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for an event */
|
|
|
|
int n;
|
2015-10-18 10:14:33 +02:00
|
|
|
while ((n = select(max + 1, &fset, NULL, NULL, NULL)) < 0) {
|
|
|
|
if (errno != EINTR)
|
2014-07-11 22:12:11 +02:00
|
|
|
return n;
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
/* process the received packet */
|
2015-10-18 10:14:33 +02:00
|
|
|
for (i = 0; i < socklist_len; i++) {
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!FD_ISSET(socklist[i].sockfd, &fset))
|
2014-07-11 22:12:11 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
struct sockaddr_storage srcaddr;
|
|
|
|
socklen_t sockaddrlen;
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
memset(&srcaddr, 0, sizeof(struct sockaddr_storage));
|
2014-07-11 22:12:11 +02:00
|
|
|
sockaddrlen = sizeof(struct sockaddr_storage);
|
|
|
|
|
|
|
|
uint8_t buffer[4096];
|
|
|
|
int len = sock_receive(socklist[i].sockfd,
|
2015-10-18 10:14:33 +02:00
|
|
|
buffer, sizeof(buffer),
|
|
|
|
0,
|
|
|
|
(struct sockaddr *) &srcaddr,
|
|
|
|
&sockaddrlen);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
process_ctrl_packet(i, (struct sockaddr *) &srcaddr, buffer, len);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
void process_cw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2015-02-07 10:57:58 +01:00
|
|
|
|
2016-02-14 17:30:14 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
/* first of all check preamble */
|
2015-03-23 07:48:27 +01:00
|
|
|
int preamble = cw_get_hdr_preamble(buffer);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (preamble != CAPWAP_PACKET_PREAMBLE && preamble != CAPWAP_DTLS_PACKET_PREAMBLE) {
|
|
|
|
cw_dbg(DBG_PKT_ERR,
|
|
|
|
"Discarding packet from %s, wrong preamble, preamble = 0x%01X",
|
|
|
|
sock_addr2str(addr), preamble);
|
2014-07-11 22:12:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_lock();
|
2015-10-18 10:14:33 +02:00
|
|
|
struct wtpman *wtpman = wtplist_get(addr);
|
|
|
|
if (!wtpman) {
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
wtpman = wtpman_create(index, addr);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-12 10:19:02 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
|
|
|
cw_log(LOG_ERR, "Error creating wtpman: %s", strerror(errno));
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
|
|
|
|
if (!wtplist_add(wtpman)) {
|
|
|
|
cw_log(LOG_ERR, "Error adding wtpman: Too many wtp connections");
|
2014-07-11 22:12:11 +02:00
|
|
|
wtpman_destroy(wtpman);
|
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
wtpman_start(wtpman, preamble & 0xf);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
2014-07-28 07:07:43 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
wtpman_addpacket(wtpman, buffer, len);
|
2014-07-11 22:12:11 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
void process_lw_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-26 20:29:30 +02:00
|
|
|
{
|
2015-04-05 02:07:59 +02:00
|
|
|
//int sock = socklist[index].reply_sockfd;
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
uint8_t *m = buffer + 6;
|
|
|
|
uint32_t val = ntohl(*((uint32_t *) (m)));
|
|
|
|
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
printf("VAL: %08X\n", val);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* first of all check preamble */
|
|
|
|
int version = LWTH_GET_VERSION(m);
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (version != LW_VERSION) {
|
|
|
|
// cw_log_debug1("Discarding LWAPP packet, wrong verson");
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int l = LWTH_GET_LENGTH(m);
|
2015-10-18 10:14:33 +02:00
|
|
|
printf("LEN = %d\n", l);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (l + 12 != len) {
|
|
|
|
// cw_log_debug1("Discarding LWAPP packet, wrong length");
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wtplist_lock();
|
2015-10-18 10:14:33 +02:00
|
|
|
struct wtpman *wtpman = wtplist_get(addr);
|
|
|
|
if (!wtpman) {
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
wtpman = wtpman_create(index, addr);
|
2014-07-26 20:29:30 +02:00
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
if (!wtpman) {
|
|
|
|
cw_log(LOG_ERR, "Error creating wtpman: %s", strerror(errno));
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
|
|
|
|
if (!wtplist_add(wtpman)) {
|
|
|
|
cw_log(LOG_ERR, "Error adding wtpman: Too many wtp connections");
|
2014-07-26 20:29:30 +02:00
|
|
|
wtpman_destroy(wtpman);
|
|
|
|
wtplist_unlock();
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
//wtpman_lw_start(wtpman);
|
2014-07-26 20:29:30 +02:00
|
|
|
}
|
2015-04-05 02:07:59 +02:00
|
|
|
//wtpman_lw_addpacket(wtpman,buffer,len);
|
2014-07-26 20:29:30 +02:00
|
|
|
wtplist_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-18 10:14:33 +02:00
|
|
|
void process_ctrl_packet(int index, struct sockaddr *addr, uint8_t * buffer, int len)
|
2014-07-26 20:29:30 +02:00
|
|
|
{
|
2015-10-18 10:14:33 +02:00
|
|
|
switch (socklist[index].ac_proto) {
|
2014-07-26 20:29:30 +02:00
|
|
|
case AC_PROTO_CAPWAP:
|
2015-10-18 10:14:33 +02:00
|
|
|
process_cw_ctrl_packet(index, addr, buffer, len);
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
case AC_PROTO_LWAPP:
|
2015-10-18 10:14:33 +02:00
|
|
|
process_lw_ctrl_packet(index, addr, buffer, len);
|
2014-07-26 20:29:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|