2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/capwap.h"
|
|
|
|
#include "cw/cipwap.h"
|
|
|
|
#include "cw/capwap_items.h"
|
|
|
|
#include "cw/conn.h"
|
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/dtls.h"
|
|
|
|
#include "cw/acpriolist.h"
|
2016-03-08 20:06:42 +01:00
|
|
|
//#include "cw/capwap_80211.h"
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/radio.h"
|
2016-03-31 19:23:51 +02:00
|
|
|
#include "cw/capwap80211_items.h"
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/mod.h"
|
2016-03-02 19:27:54 +01:00
|
|
|
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
#include "wtp.h"
|
|
|
|
#include "wtp_conf.h"
|
|
|
|
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/dbg.h"
|
|
|
|
#include "cw/mavl.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2015-04-14 07:42:23 +02:00
|
|
|
#include "jsmn.h"
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
#include "cfg.h"
|
2015-04-14 07:42:23 +02:00
|
|
|
|
|
|
|
|
2016-03-02 19:27:54 +01:00
|
|
|
#include "../mod/modload.h"
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/** The one and only connection object */
|
|
|
|
struct conn *the_conn;
|
|
|
|
struct cw_actiondef capwap_actions;
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2015-04-20 21:28:22 +02:00
|
|
|
int handle_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
2016-03-04 21:42:39 +01:00
|
|
|
int len, struct sockaddr *from)
|
2015-04-20 21:28:22 +02:00
|
|
|
{
|
2016-03-04 21:42:39 +01:00
|
|
|
MAVLITER_DEFINE(it, conn->incomming);
|
2015-04-20 21:28:22 +02:00
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
mavliter_foreach(&it) {
|
|
|
|
mbag_item_t *item = mavliter_get(&it);
|
2015-04-20 21:28:22 +02:00
|
|
|
|
2016-03-19 12:57:47 +01:00
|
|
|
// printf("MBAG ITEM GOT: %s\n",item->id);
|
|
|
|
if (item->id == CW_ITEM_LOCATION_DATA) {
|
|
|
|
printf("Location Data %s\n",mbag_get_str(conn->incomming,CW_ITEM_LOCATION_DATA,"ups"));
|
|
|
|
|
2015-04-20 21:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-03-04 21:42:39 +01:00
|
|
|
cw_dbg(DBG_INFO, "Saving configuration ...");
|
|
|
|
cfg_to_json();
|
2016-03-19 12:57:47 +01:00
|
|
|
|
|
|
|
// exit(0);
|
2015-04-20 21:28:22 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
const char *t = CW_ITEM_WTP_NAME;
|
2015-04-20 21:28:22 +02:00
|
|
|
|
2016-03-11 18:16:13 +01:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void update_reboot_stats(struct conn * conn, int cause)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
mbag_t rs = mbag_get_mbag(conn->config,CW_ITEM_WTP_REBOOT_STATISTICS,NULL);
|
|
|
|
|
|
|
|
switch (cause){
|
|
|
|
case CW_REBOOT_TYPE_NOT_SUPPORTED:
|
|
|
|
break;
|
|
|
|
case CW_REBOOT_TYPE_AC_INITIATED:
|
2016-03-11 22:23:00 +01:00
|
|
|
mbag_inc_word(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT,1);
|
2016-03-11 18:16:13 +01:00
|
|
|
break;
|
|
|
|
case CW_REBOOT_TYPE_OTHER_FAILURE:
|
2016-03-11 22:23:00 +01:00
|
|
|
mbag_inc_word(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT,1);
|
2016-03-11 18:16:13 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-11 22:23:00 +01:00
|
|
|
|
|
|
|
mbag_inc_word(rs,CW_ITEM_REBOOT_COUNT,1);
|
|
|
|
mbag_set_byte(rs,CW_ITEM_REBOOT_LAST_FAILURE_TYPE,cause);
|
2016-03-11 18:16:13 +01:00
|
|
|
cfg_to_json();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sig_handler(int sig)
|
|
|
|
{
|
|
|
|
struct conn * conn = the_conn; //get_conn();
|
|
|
|
|
|
|
|
update_reboot_stats(conn, CW_REBOOT_TYPE_OTHER_FAILURE);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2016-03-31 19:23:51 +02:00
|
|
|
#include "cw/dot11.h"
|
|
|
|
#include "cw/format.h"
|
|
|
|
|
|
|
|
#include "cw/capwap80211_types.h"
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
int main()
|
|
|
|
{
|
2016-03-11 18:16:13 +01:00
|
|
|
|
2016-03-31 19:23:51 +02:00
|
|
|
signal (SIGINT, sig_handler);
|
2015-03-30 07:56:42 +02:00
|
|
|
|
2014-07-22 07:11:57 +02:00
|
|
|
wtpconf_preinit();
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
if (!read_config("./wtp_uci.conf")) {
|
2014-07-11 22:12:11 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2016-03-31 19:23:51 +02:00
|
|
|
// cw_dbg_opt_level = conf_dbg_level;
|
|
|
|
|
2015-02-03 08:23:03 +01:00
|
|
|
|
2016-03-31 19:23:51 +02:00
|
|
|
if (!wtpconf_init()){
|
|
|
|
return 1;
|
|
|
|
};
|
2014-07-22 07:11:57 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS;
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
dtls_init();
|
2015-02-01 16:55:45 +01:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
the_conn = conn_create_noq(-1, NULL);
|
|
|
|
struct conn *conn = the_conn;
|
2014-08-03 21:42:37 +02:00
|
|
|
|
2015-05-01 00:16:54 +02:00
|
|
|
conn->radios = mbag_i_create();
|
2016-04-02 09:05:07 +02:00
|
|
|
conn->radios_upd=conn->radios;
|
2016-03-05 22:32:52 +01:00
|
|
|
mbag_i_set_mbag(conn->radios,0,mbag_create());
|
2016-03-31 19:23:51 +02:00
|
|
|
// mbag_i_set_mbag(conn->radios,1,mbag_create());
|
2016-03-04 21:42:39 +01:00
|
|
|
// mbag_set_mbag(conn->radios,0xff,mbag_create());
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
|
2016-03-02 19:27:54 +01:00
|
|
|
|
2016-04-02 17:07:35 +02:00
|
|
|
#define CWMOD "cisco"
|
|
|
|
#define CWBIND "cisco"
|
|
|
|
//#define CWMOD "capwap"
|
|
|
|
//#define CWBIND "capwap80211"
|
2016-03-12 16:12:36 +01:00
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
|
2016-03-12 03:57:43 +01:00
|
|
|
struct mod_wtp *mod = modload_wtp(CWMOD);
|
2016-03-02 19:27:54 +01:00
|
|
|
if (!mod) {
|
2016-03-04 21:42:39 +01:00
|
|
|
printf("Can't load mod capwap\n");
|
2016-03-02 19:27:54 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
2016-03-13 09:47:01 +01:00
|
|
|
mod->init();
|
|
|
|
|
2016-03-10 08:07:30 +01:00
|
|
|
mod->register_actions(&capwap_actions,MOD_MODE_CAPWAP);
|
2016-03-12 03:57:43 +01:00
|
|
|
mod = modload_wtp(CWBIND);
|
2016-03-09 09:09:28 +01:00
|
|
|
if (!mod) {
|
|
|
|
printf("Can't load mod capwap80211\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("add capwap80211\n");
|
2016-03-10 08:07:30 +01:00
|
|
|
int rc = mod->register_actions(&capwap_actions,MOD_MODE_BINDINGS);
|
2016-03-09 09:09:28 +01:00
|
|
|
|
|
|
|
printf("Out reg = %d\n",rc);
|
|
|
|
|
|
|
|
conn->detected = 1;
|
2016-03-12 16:12:36 +01:00
|
|
|
conn->dtls_verify_peer=0;
|
2016-03-31 19:23:51 +02:00
|
|
|
conn->dtls_mtu = 2000;
|
2016-03-02 19:27:54 +01:00
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2015-04-21 08:24:59 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
MAVLITER_DEFINE(it,capwap_actions.strelem);
|
|
|
|
mavliter_foreach(&it){
|
|
|
|
struct cw_str *s = mavliter_get(&it);
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
////cw_register_actions_capwap_80211_wtp(&capwap_actions);
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
conn->actions = &capwap_actions;
|
2015-04-19 23:27:44 +02:00
|
|
|
conn->outgoing = mbag_create();
|
|
|
|
conn->incomming = mbag_create();
|
|
|
|
conn->local = mbag_create();
|
2015-04-26 15:48:40 +02:00
|
|
|
|
2016-03-05 14:12:49 +01:00
|
|
|
// conn->base_rmac = get_base_rmac();
|
|
|
|
|
|
|
|
// conn->capwap_mode = CW_MODE_CAPWAP;
|
2016-03-05 08:05:46 +01:00
|
|
|
//conn->capwap_mode = CW_MODE_CISCO;
|
2015-04-26 23:52:11 +02:00
|
|
|
|
2016-03-16 07:58:45 +01:00
|
|
|
the_conn->strict_capwap = 0;
|
2015-04-26 15:48:40 +02:00
|
|
|
|
2014-08-03 21:42:37 +02:00
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
conn->config = mbag_create();
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2015-05-04 07:48:59 +02:00
|
|
|
cfg_from_json(conn);
|
2016-03-05 14:12:49 +01:00
|
|
|
setup_conf(conn);
|
2016-03-31 19:23:51 +02:00
|
|
|
|
|
|
|
mbag_t r;
|
2016-04-01 07:35:31 +02:00
|
|
|
// r = mbag_i_get_mbag(conn->radios,0,NULL);
|
|
|
|
r = conn->radios;
|
2016-03-31 19:23:51 +02:00
|
|
|
MAVLITER_DEFINE(it,r);
|
|
|
|
mavliter_foreach(&it){
|
|
|
|
struct mbag_item *i=mavliter_get(&it);
|
|
|
|
printf("RID = %d\n",i->iid);
|
2016-04-01 07:35:31 +02:00
|
|
|
printf("DATA: %p\n",i->data);
|
|
|
|
mbag_t radio= (mbag_t)i->data;
|
2016-04-02 09:05:07 +02:00
|
|
|
struct mbag_item *mri = mbag_get(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION);
|
2016-03-31 19:23:51 +02:00
|
|
|
|
|
|
|
if (!mri){
|
|
|
|
printf("Setting to 8 %p %p\n",mri,r);
|
2016-04-02 09:05:07 +02:00
|
|
|
mbag_set_dword(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION,1);
|
2016-03-31 19:23:51 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
printf("MRI %p\n",mri);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 09:47:01 +01:00
|
|
|
mod_init_config(mod,conn->config);
|
2016-03-04 21:42:39 +01:00
|
|
|
cfg_to_json();
|
2015-04-14 07:42:23 +02:00
|
|
|
|
2016-03-13 18:55:42 +01:00
|
|
|
// mbag_t board_data = mbag_create();
|
|
|
|
// mbag_set_dword(board_data, CW_ITEM_WTP_BOARD_VENDOR, conf_vendor_id);
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2016-03-13 18:55:42 +01:00
|
|
|
// mbag_set_bstrn(board_data, CW_ITEM_WTP_BOARD_MACADDRESS, conf_macaddress,
|
|
|
|
// conf_macaddress_len);
|
|
|
|
// mbag_set_bstr16n(board_data, CW_ITEM_WTP_BOARD_SERIALNO,
|
|
|
|
// bstr_data(conf_serial_no), bstr_len(conf_serial_no));
|
2016-03-04 21:42:39 +01:00
|
|
|
|
2016-03-13 18:55:42 +01:00
|
|
|
// mbag_set_bstr16n(board_data, CW_ITEM_WTP_BOARD_MODELNO, bstr_data(conf_model_no),
|
|
|
|
// bstr_len(conf_model_no));
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2016-03-03 19:24:28 +01:00
|
|
|
|
|
|
|
|
2016-03-13 18:55:42 +01:00
|
|
|
// mbag_set_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, board_data);
|
2016-03-03 19:24:28 +01:00
|
|
|
|
2016-03-11 18:16:13 +01:00
|
|
|
|
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
|
2016-03-04 22:32:01 +01:00
|
|
|
// mbag_set_bstrv(conn->config, CW_ITEM_WTP_SOFTWARE_VERSION, sw);
|
2016-03-04 20:20:28 +01:00
|
|
|
|
2016-03-13 18:55:42 +01:00
|
|
|
// printf("Board_data %p\n", board_data);
|
2016-03-03 19:24:28 +01:00
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
mbag_t mb = mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, NULL);
|
|
|
|
printf("mbag %p\n", mb);
|
2016-03-03 19:24:28 +01:00
|
|
|
|
2015-04-10 17:14:55 +02:00
|
|
|
|
|
|
|
cw_acpriolist_t acprios = cw_acpriolist_create();
|
2016-03-04 21:42:39 +01:00
|
|
|
cw_acpriolist_set(acprios, "Master AC", strlen("Master AC"), 1);
|
|
|
|
cw_acpriolist_set(acprios, "AC8new", strlen("AC8new"), 12);
|
2015-04-10 17:14:55 +02:00
|
|
|
|
|
|
|
|
2016-03-05 14:12:49 +01:00
|
|
|
//mbag_set_str(conn->config,CW_ITEM_LOCATION_DATA,"Berlin");
|
|
|
|
//mbag_set_str(conn->config,CW_ITEM_WTP_NAME,"WTP Tube");
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2016-03-04 21:42:39 +01:00
|
|
|
mbag_set_byte(conn->local, CW_ITEM_WTP_MAC_TYPE, 0);
|
|
|
|
mbag_set_byte(conn->local, CW_ITEM_WTP_FRAME_TUNNEL_MODE, 0);
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2016-03-09 18:39:57 +01:00
|
|
|
conn->wbid=1;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-20 21:28:22 +02:00
|
|
|
|
|
|
|
|
2016-03-31 19:23:51 +02:00
|
|
|
cw_set_msg_end_callback(conn->actions,CW_STATE_RUN,CW_MSG_CONFIGURATION_UPDATE_REQUEST,handle_update_req);
|
2016-03-01 07:29:52 +01:00
|
|
|
//cw_set_msg_end_callback(conn,CW_STATE_CONFIGURE,CW_MSG_CONFIGURATION_STATUS_RESPONSE,handle_update_req);
|
2015-04-20 21:28:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
if (!discovery())
|
|
|
|
return -1;
|
|
|
|
if (!join())
|
|
|
|
return -1;
|
|
|
|
|
2016-03-11 22:23:00 +01:00
|
|
|
// mavl_del_all(conn->incomming);
|
2016-03-12 22:34:31 +01:00
|
|
|
// conn->incomming = conn->config;
|
2016-03-05 10:31:21 +01:00
|
|
|
if (!configure())
|
|
|
|
return -1;
|
2016-03-19 12:57:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
cfg_to_json();
|
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
changestate();
|
2015-04-20 21:28:22 +02:00
|
|
|
|
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
run();
|
|
|
|
|
2015-04-18 11:20:24 +02:00
|
|
|
//image_update();
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-05-11 21:58:17 +02:00
|
|
|
return 0;
|
2015-04-07 07:42:36 +02:00
|
|
|
}
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
struct conn *get_conn()
|
|
|
|
{
|
|
|
|
return the_conn;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|