Some AC actions added.

FossilOrigin-Name: 81ab5c5c07e3ed0b84527274f3c80314fc6411fdd9aede3dba3b2cb2ae0eef8c
This commit is contained in:
7u83@mail.ru 2015-04-26 10:36:53 +00:00
parent e1a6017211
commit f3a034122f
27 changed files with 216 additions and 1288 deletions

View File

@ -163,6 +163,7 @@ int main (int argc, const char * argv[])
DBGX("Attention! %s","DBGX is ON!");
cw_register_actions_cipwap_ac(&capwap_actions);
cw_register_actions_capwap_80211_ac(&capwap_actions);
//cw_register_actions_capwap_80211_ac(&capwap_actions);

View File

@ -114,6 +114,8 @@ conn->strict_capwap=0;
conn->strict_hdr=1;
conn->capwap_mode=CW_MODE_CIPWAP;
conn->config = mbag_create();
conn->radios = mbag_create();
time_t timer = cw_timer_start(10);
@ -378,62 +380,11 @@ static int wtpman_send_image_file(struct wtpman *wtpman, struct cwrmsg *cwrmsg)
}
*/
static void wtpman_run(void *arg)
static void wtpman_image_data(struct wtpman *wtpman)
{
struct wtpman *wtpman = (struct wtpman *) arg;
struct cwrmsg *cwrmsg; // = conn_get_message(wtpman->conn);
struct conn * conn = wtpman->conn;
wtpman->conn->seqnum = 0;
/* reject connections to our multi- or broadcast sockets */
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.",
CLIENT_IP);
wtpman_remove(wtpman);
return;
}
time_t timer = cw_timer_start(wtpman->conn->wait_dtls);
/* establish dtls session */
if (!wtpman_establish_dtls(wtpman)) {
wtpman_remove(wtpman);
return;
}
/* dtls is established, goto join state */
if (!wtpman_join(wtpman, timer)) {
wtpman_remove(wtpman);
return;
}
/* here the WTP has joined, now we assume an image data request
or an configuration status request. Nothing else.
*/
int rc = 0;
while (!cw_timer_timeout(timer)
&& wtpman->conn->capwap_state == CW_STATE_CONFIGURE) {
rc = cw_read_messages(wtpman->conn);
if (rc < 0) {
if (errno != EAGAIN)
break;
}
}
if (!rc) {
cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc));
}
struct conn *conn = wtpman->conn;
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
/* Image upload */
const char *filename =
mbag_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME,NULL);
@ -480,6 +431,84 @@ static void wtpman_run(void *arg)
wtpman_remove(wtpman);
}
static void wtpman_run(void *arg)
{
struct wtpman *wtpman = (struct wtpman *) arg;
struct cwrmsg *cwrmsg; // = conn_get_message(wtpman->conn);
wtpman->conn->seqnum = 0;
struct conn *conn = wtpman->conn;
/* reject connections to our multi- or broadcast sockets */
if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) {
cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.",
CLIENT_IP);
wtpman_remove(wtpman);
return;
}
time_t timer = cw_timer_start(wtpman->conn->wait_dtls);
/* establish dtls session */
if (!wtpman_establish_dtls(wtpman)) {
wtpman_remove(wtpman);
return;
}
/* dtls is established, goto join state */
if (!wtpman_join(wtpman, timer)) {
wtpman_remove(wtpman);
return;
}
/* here the WTP has joined, now we assume an image data request
or an configuration status request. Nothing else.
*/
int rc = 0;
while (!cw_timer_timeout(timer)
&& wtpman->conn->capwap_state == CW_STATE_CONFIGURE) {
rc = cw_read_messages(wtpman->conn);
if (rc < 0) {
if (errno != EAGAIN)
break;
}
}
if (!cw_rcok(rc)) {
cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc));
wtpman_remove(wtpman);
return;
}
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
wtpman_image_data(wtpman);
return;
}
conn->capwap_state=CW_STATE_RUN;
rc = 0;
while (!cw_timer_timeout(timer)
&& wtpman->conn->capwap_state == CW_STATE_RUN) {
rc = cw_read_messages(wtpman->conn);
if (rc < 0) {
if (errno != EAGAIN)
break;
}
}

View File

@ -322,6 +322,7 @@ CWACTION=action.o \
capwap_actions_ac.o \
capwap_actions_wtp.o \
capwap_80211_actions_wtp.o \
capwap_80211_actions_ac.o \
cw_in_generic.o \
cw_in_wtp_descriptor.o \
cw_out_wtp_board_data.o \

View File

@ -45,12 +45,13 @@ struct cw_action_in{
uint16_t elem_id;
int (*start)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from);
int (*end)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from);
// uint8_t itemtype;
const struct mbag_typedef * itemtype;
uint16_t item_id;
uint16_t min_len;
uint16_t max_len;
uint8_t mand;
// mbag_t (*target)(struct conn *conn,struct cw_action_in *a);
};
typedef int(*cw_action_fun_t)(struct conn *,struct cw_action_in *,uint8_t*,int ,struct sockaddr *);
@ -92,7 +93,7 @@ struct cw_action_out{
struct mbag_typedef * itemtype;
void *defval;
int xopt;
// int xopt;
};

View File

@ -1114,5 +1114,7 @@ int cw_out_radio_administrative_states(struct conn *conn, struct cw_action_out *
int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
#endif

View File

@ -91,6 +91,8 @@ int cw_out_radio_infos(struct conn *conn, struct cw_action_out *a, uint8_t * dst
extern int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def);
extern struct cw_str capwap_strings_elem80211[];
extern int cw_register_actions_capwap_80211_ac(struct cw_actiondef *def);

View File

@ -5,8 +5,8 @@
#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \
CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
MBAG_STR, /* Type of element */ \
cw_in_radio_generic, 0, /* start/end callback */ \
MBAG_DWORD, /* Type of element */ \
CW_ITEM_LOCATION_DATA, /* ID to use store */ \
5, 5 /* min/max length */

View File

@ -28,7 +28,21 @@ cw_action_in_t capwap_80211_actions_wtp_in[] = {
cw_action_out_t capwap_80211_actions_wtp_out[]={
/* Session ID */
/* --------------------------------------------------------
* Discovery Resquest
*/
/* 802.11 Radio Information */
{CW_MSG_DISCOVERY_REQUEST, CW_ELEM80211_WTP_RADIO_INFORMATION, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}
,
/* --------------------------------------------------------
* Join Resquest
*/
/* 802.11 Radio Information */
{CW_MSG_JOIN_REQUEST, CW_ELEM80211_WTP_RADIO_INFORMATION, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}

View File

@ -4,7 +4,6 @@
int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len)
{
conn->capwap_state=CW_STATE_NONE;

View File

@ -233,9 +233,9 @@ cw_action_out_t capwap_actions_ac_out[] = {
,
/* Result Code */
{CW_MSG_CONFIGURATION_STATUS_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1}
,
// {CW_MSG_CONFIGURATION_STATUS_RESPONSE, CW_ITEM_RESULT_CODE, 0,
// CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1}
// ,

View File

@ -56,6 +56,7 @@ struct conn {
mbag_t local;
mbag_t radios;
uint8_t radio_create;
mbag_t config;
@ -256,6 +257,8 @@ extern int cw_read_messages(struct conn *conn);
extern int conn_recvfrom_packet(struct conn *conn, uint8_t * buf, int len,
struct sockaddr_storage *from);
int conn_send_msg(struct conn * conn, uint8_t *rawmsg);
int cw_read_from(struct conn * conn);

View File

@ -247,7 +247,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,struct
if (!af) {
cw_dbg(DBG_ELEM_ERR,
"Element %d (%s) not allowed in msg of type %d (%s), ignoring.",
as.elem_id, cw_strelem(as.elem_id), as.msg_id,
as.elem_id, cw_strelemp(conn->actions,as.elem_id), as.msg_id,
cw_strmsg(as.msg_id));
continue;
}

View File

@ -6,9 +6,8 @@
#include "capwap.h"
int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
@ -24,8 +23,13 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int
return 0;
}
return 1;
}
mbag_t itemstore = conn->incomming;
int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len, struct sockaddr *from)
{
if (a->itemtype == MBAG_BYTE) {
mbag_set_byte(itemstore, a->item_id, *data);
@ -60,7 +64,7 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int
*/
if (a->itemtype == MBAG_VENDORSTR) {
mbag_set_vendorstr(itemstore, a->item_id,
cw_get_dword(data), data + 4, len - 4);
cw_get_dword(data), data + 4, len - 4);
return 1;
}
@ -70,6 +74,49 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int
return 0;
}
int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
if (!check_len(conn, a, data, len, from))
return 0;
mbag_t itemstore;
/// if (!a->target)
itemstore = conn->incomming;
// else
// itemstore = a->target(conn, a);
return do_save(itemstore, conn, a, data, len, from);
}
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
if (!check_len(conn, a, data, len, from))
return 0;
int rid = cw_get_byte(data);
mbag_t radio = mbag_get_mbag(conn->radios, rid, NULL);
if (!radio) {
if (a->vendor_id != 0
|| ( (a->vendor_id == 0) && (a->msg_id != CW_MSG_DISCOVERY_REQUEST
&& a->msg_id != CW_MSG_JOIN_REQUEST) )) {
cw_dbg(DBG_ELEM_ERR, "Radio not found %d", rid);
return 0;
}
mbag_set_mbag(conn->radios,rid,mbag_create());
}
return 1;
}

View File

@ -20,8 +20,8 @@ ifndef ARCH
endif
#CFLAGS += -O0 -Wall -g
CFLAGS += -Os -Wall
CFLAGS += -O0 -Werror -g
#CFLAGS += -Os -Wall
LDFLAGS += -L../contrib/jsmn -L../../src/capwap/$(ARCH)

View File

@ -193,7 +193,7 @@ int cfg_json_get_ac_ip_list(struct mbag_itemdef *idef, char *js, jsmntok_t * t,
}
return 0;
}
@ -430,7 +430,9 @@ struct mbag_itemdef board_data_cfg[] = {
struct mbag_itemdef radio_cfg[] = {
{CW_RADIO_ADMIN_STATE, "admin_state", cfg_json_get_byte, cfg_json_put_byte}
{CW_RADIO_ADMIN_STATE, "admin_state", cfg_json_get_byte, cfg_json_put_byte},
{CW_RADIO_TYPE, "radio_type", cfg_json_get_dword, cfg_json_put_dword},
{0,0,0}
};
@ -699,7 +701,7 @@ int cfg_json_save()
////printf("DST:%s\n",dst);
//exit(0);
cw_save_file("cfg.json", dst, n);
return 1;
}
struct mbag_itemdef *get_cfg(struct mbag_itemdef *cfg, const char *key)

View File

@ -27,10 +27,12 @@
"wtp_board_data_options":".x00010000",
"radios":{
"0":{
"admin_state":"2"
"admin_state":"2",
"radio_type":"0"
},
"1":{
"admin_state":"2"
"admin_state":"2",
"radio_type":"0"
}
},
"bssid":""

View File

@ -12,8 +12,9 @@ int changestate()
if ( !cw_rcok(rc) ) {
cw_strresult(rc);
return 0;
}
return 1;
}

View File

@ -27,6 +27,6 @@ int configure()
printf("Got change resp %p\n",cwrmsg);
*/
return 0;
}

View File

@ -161,7 +161,7 @@ static int run_discovery(struct conn *conn)
mbag_set_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list);
return 0;
return 1;
}
@ -228,5 +228,5 @@ int discovery()
struct conn *conn = get_conn();
cw_run_discovery(conn, "255.255.255.255");
conn->capwap_state=CW_STATE_JOIN;
return 0;
return 1;
}

View File

@ -20,7 +20,7 @@
#include "dot11.h"
/*
uint8_t * mk_frame( uint8_t *b)
{
@ -70,7 +70,7 @@ int dot11_get_beacon_head(struct apdata *ap, uint8_t *dst, int *len)
printf("t1\n");
/* set-up head */
// set-up head
struct dot11_mgmt_head head;
memset (&head,0,sizeof(head));
@ -79,11 +79,11 @@ printf("t2\n");
head.frame_control = htole16 (DOT11_FTYPE_MGMT | DOT11_STYPE_BEACON);
head.duration = htole16(0);
/* destination address */
// destination address
memset(head.da, 0xff, sizeof(head.da));
printf("t3\n");
/* source address */
// source address
memcpy (head.sa , ap->mac,6);
memcpy (head.bssid , ap->mac,6);
b += add_bytes(b,&head,sizeof(head));
@ -140,8 +140,9 @@ add_supp_rates_ie(uint8_t *buf,uint32_t * rates, int num_rates)
return b-buf;
}
*/
/*
dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd)
{
bd->head = malloc(256);
@ -165,5 +166,5 @@ printf ("done\n");
return 0;
}
*/

View File

@ -319,7 +319,7 @@ struct beacon_data{
};
dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd);
int dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd);

View File

@ -10,7 +10,7 @@
#include "nlt.h"
/*
static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
{
@ -362,3 +362,6 @@ int nlt_get_wiphy_list(struct nl_sock *sk)
}
}
*/

View File

@ -80,7 +80,7 @@ int run()
// cw_strresult(rc);
// }
return 0;
}

View File

@ -10,6 +10,10 @@ extern int join();
extern int discovery();
extern int image_update();
extern int setup_conf(struct conn * conn);
extern int configure();
extern int run();
extern int changestate();
struct conn * get_conn();

View File

@ -220,6 +220,7 @@ int wtpconf_preinit()
conf_board_id = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_ID);
conf_board_revision = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_REVISION);
return 0;
}
int wtpconf_init()

View File

@ -21,7 +21,7 @@
#include "jsmn.h"
#include "cfg.h"
@ -168,9 +168,12 @@ cw_set_msg_end_callback(conn,CW_STATE_CONFIGURE,CW_MSG_CONFIGURATION_STATUS_RESP
the_conn->strict_capwap=0;
discovery();
join();
the_conn->strict_capwap=1;
if (!discovery())
return -1;
if (!join())
return -1;
mavl_destroy(conn->incomming);
conn->incomming=conn->config;
configure();

File diff suppressed because it is too large Load Diff