WTP sends session id.

FossilOrigin-Name: 32e0df82a8e40e3a3953127ceae58359cdce56696d802e54983f813b00ed1342
This commit is contained in:
7u83@mail.ru 2015-04-10 19:44:05 +00:00
parent 3fe1bc0d21
commit 76e044c1fb
17 changed files with 97 additions and 55 deletions

View File

@ -282,7 +282,7 @@ int socklist_add_unicast(const char *addr, const char * port, int ac_proto)
socklist[socklist_len].ac_proto=ac_proto; socklist[socklist_len].ac_proto=ac_proto;
socklist_len++; socklist_len++;
cw_log(LOG_INFO,"Bound to: %s (%i)\n",addr,sockfd); cw_log(LOG_INFO,"Bound to: %s (%i)",addr,sockfd);
} }
freeaddrinfo(res0); freeaddrinfo(res0);
@ -349,7 +349,7 @@ int socklist_add_broadcast(const char *addr, const char * port,int ac_proto)
// printf ("sock proto %d\n",socklist[socklist_len].ac_proto); // printf ("sock proto %d\n",socklist[socklist_len].ac_proto);
socklist_len++; socklist_len++;
cw_log(LOG_INFO,"Bound to broadcast: %s:%s (%i,R:%i,I:%d)\n",addr,port,sockfd,rfd,socklist_len-1); cw_log(LOG_INFO,"Bound to broadcast: %s:%s (%i,R:%i,I:%d)",addr,port,sockfd,rfd,socklist_len-1);
} }
freeaddrinfo(res0); freeaddrinfo(res0);

View File

@ -95,14 +95,6 @@ LWAPPCISCOOBJS = \
CAPWAPOBJS= \ CAPWAPOBJS= \
cwmsg_init_echo_request.o \
cwmsg_addelem.o \
cwmsg_vaddelem.o \
cwmsg_addelem_ac_descriptor.o \
cwmsg_addelem_wtp_descriptor.o \
cwmsg_addelem_cw_local_ip_addr.o \
cwmsg_addelem_mtu_discovery_padding.o \
cwmsg_addelem_ac_timestamp.o \
cwmsg_addelem_maximum_message_length.o \ cwmsg_addelem_maximum_message_length.o \
cwmsg_addelem_image_identifier.o \ cwmsg_addelem_image_identifier.o \
cwmsg_send.o \ cwmsg_send.o \
@ -148,7 +140,15 @@ CAPWAPOBJS= \
# cwsend_unknow_response.o \ # cwsend_unknow_response.o \
cw_send_configuration_update_response.o \ cw_send_configuration_update_response.o \
cwsend_echo_request.o \ cwsend_echo_request.o \
cw_send_echo_response.o \ cwmsg_init_echo_request.o \
cwmsg_addelem.o \
cwmsg_vaddelem.o \
cwmsg_addelem_ac_descriptor.o \
cwmsg_addelem_wtp_descriptor.o \
cwmsg_addelem_cw_local_ip_addr.o \
cwmsg_addelem_mtu_discovery_padding.o \
cwmsg_addelem_ac_timestamp.o \
cw_send_echo_response.o \
cw_handle_echo_request.o \ cw_handle_echo_request.o \
cwsend_conf_status_response.o\ cwsend_conf_status_response.o\
cw_readmsg_configuration_status_response.o \ cw_readmsg_configuration_status_response.o \

View File

@ -73,7 +73,7 @@ struct cw_action_out{
uint32_t item_id; uint32_t item_id;
uint32_t vendor_id; uint32_t vendor_id;
uint16_t elem_id; uint16_t elem_id;
int (*init)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a); struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a);
uint8_t mand; uint8_t mand;

View File

@ -962,6 +962,8 @@ int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t
int cw_out_wtp_board_data(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ; int cw_out_wtp_board_data(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ;
void cw_init_request(struct conn *conn,int msg_id); void cw_init_request(struct conn *conn,int msg_id);
struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a);

View File

@ -27,3 +27,25 @@ struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a)
return cw_itemstore_get(conn->local,a->item_id); return cw_itemstore_get(conn->local,a->item_id);
} }
#include "capwap.h"
#include "capwap_items.h"
#include "log.h"
#include "rand.h"
struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a)
{
printf("Vendor ID: %d\n", a->vendor_id);
uint8_t session_id[16];
int l = cw_rand(session_id,16);
if ( l!=16 ) {
cw_log(LOG_ERR,"Can't init session ID.");
return NULL;
}
return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,4);
}

View File

@ -148,17 +148,17 @@ cw_action_out_t capwap_actions_ac_out[] = {
/* AC Descriptor */ /* AC Descriptor */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR,
cw_out_ac_descriptor, 0} NULL,cw_out_ac_descriptor, 0}
, ,
/* AC Name */ /* AC Name */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME, 0, {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_NAME, 0,
CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_outgoing} CW_ELEM_AC_NAME, NULL, cw_out_generic, cw_out_get_outgoing}
, ,
/* List of CAPWAP Control IPv4 and IPv6 addresses */ /* List of CAPWAP Control IPv4 and IPv6 addresses */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, 0, {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, 0,
0, cw_out_capwap_control_ip_addr_list, cw_out_get_outgoing} 0, NULL, cw_out_capwap_control_ip_addr_list, cw_out_get_outgoing}
, ,
@ -170,17 +170,17 @@ cw_action_out_t capwap_actions_ac_out[] = {
/* Result Code */ /* Result Code */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0, {CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_outgoing, 1} CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1}
, ,
/* AC Descriptor */ /* AC Descriptor */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR, {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR,
cw_out_ac_descriptor, 0, 1} NULL,cw_out_ac_descriptor, 0, 1}
, ,
/* AC Name */ /* AC Name */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME, 0, {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME, 0,
CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_outgoing} CW_ELEM_AC_NAME, NULL, cw_out_generic, cw_out_get_outgoing}
, ,
@ -194,7 +194,7 @@ cw_action_out_t capwap_actions_ac_out[] = {
/* Result Code */ /* Result Code */
{CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_RESULT_CODE, 0, {CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_outgoing, 1} CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1}
, ,

View File

@ -89,13 +89,13 @@ cw_action_out_t capwap_actions_wtp_out[] = {
/* AC Name */ /* AC Name */
{CW_MSG_DISCOVERY_REQUEST, CW_ITEM_DISCOVERY_TYPE, 0, {CW_MSG_DISCOVERY_REQUEST, CW_ITEM_DISCOVERY_TYPE, 0,
CW_ELEM_DISCOVERY_TYPE, cw_out_generic, cw_out_get_outgoing} CW_ELEM_DISCOVERY_TYPE, NULL,cw_out_generic, cw_out_get_outgoing}
, ,
/* WTP Board Data */ /* WTP Board Data */
{CW_MSG_DISCOVERY_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0, {CW_MSG_DISCOVERY_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0,
CW_ELEM_WTP_BOARD_DATA, cw_out_wtp_board_data, cw_out_get_outgoing} CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing}
, ,
@ -108,15 +108,26 @@ cw_action_out_t capwap_actions_wtp_out[] = {
/* Location Data */ /* Location Data */
{CW_MSG_JOIN_REQUEST, CW_ITEM_LOCATION_DATA, 0, {CW_MSG_JOIN_REQUEST, CW_ITEM_LOCATION_DATA, 0,
CW_ELEM_LOCATION_DATA, cw_out_generic, cw_out_get_local,1} CW_ELEM_LOCATION_DATA, NULL,cw_out_generic, cw_out_get_local,1}
, ,
/* WTP Board Data */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0,
CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing}
,
/* WTP Name */ /* WTP Name */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_NAME, 0, {CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_NAME, 0,
CW_ELEM_WTP_NAME, cw_out_generic, cw_out_get_local,1} CW_ELEM_WTP_NAME, NULL,cw_out_generic, cw_out_get_local,1}
, ,
/* Session ID */
{CW_MSG_JOIN_REQUEST, CW_ITEM_SESSION_ID, 0,
CW_ELEM_SESSION_ID, NULL,cw_out_generic, cw_out_get_session_id,1}
,
{0, 0} {0, 0}
}; };

View File

@ -56,13 +56,13 @@ cw_action_out_t cipwap_actions_ac_out[] = {
/* AC Descriptor (Cisco) */ /* AC Descriptor (Cisco) */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 ,
CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} CW_ELEM_AC_DESCRIPTOR, NULL,cw_out_cisco_ac_descriptor, 0}
, ,
/* Cisco AP Timesync - Important to get the WTP a DTLS /* Cisco AP Timesync - Important to get the WTP a DTLS
connection stablished*/ connection stablished*/
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_TIMESTAMP, CW_VENDOR_ID_CISCO, {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_TIMESTAMP, CW_VENDOR_ID_CISCO,
CW_CISCO_AP_TIMESYNC, cw_out_cisco_ap_timesync, 0} CW_CISCO_AP_TIMESYNC, NULL,cw_out_cisco_ap_timesync, 0}
, ,
/* ------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------
@ -71,7 +71,7 @@ cw_action_out_t cipwap_actions_ac_out[] = {
/* AC Descriptor (Cisco) */ /* AC Descriptor (Cisco) */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 ,
CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} CW_ELEM_AC_DESCRIPTOR, NULL,cw_out_cisco_ac_descriptor, 0}
, ,

View File

@ -18,6 +18,9 @@ int cw_put_item(uint8_t * dst, struct cw_item *item)
return cw_put_word(dst, item->word); return cw_put_word(dst, item->word);
case CW_ITEMTYPE_DWORD: case CW_ITEMTYPE_DWORD:
return cw_put_dword(dst, item->dword); return cw_put_dword(dst, item->dword);
case CW_ITEMTYPE_BSTR:
return cw_put_bstr(dst,item->data);
} }
return 0; return 0;

View File

@ -37,6 +37,7 @@
int cw_put_msg(struct conn *conn, uint8_t * rawout) int cw_put_msg(struct conn *conn, uint8_t * rawout)
{ {
/* rawout is already initialized, so we can get /* rawout is already initialized, so we can get
msg type from buffer */ msg type from buffer */
uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout); uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout);

View File

@ -30,17 +30,17 @@
#include "cw_util.h" #include "cw_util.h"
#include "log.h" #include "log.h"
char * cw_rand_dev = "/dev/random"; char *cw_rand_dev = "/dev/random";
int cw_rand_r(uint8_t*dst, int len) int cw_rand_r(uint8_t * dst, int len)
{ {
int rf; int rf;
int l; int l;
rf = open(cw_rand_dev, O_RDONLY | O_NDELAY); rf = open(cw_rand_dev, O_RDONLY | O_NDELAY);
if (rf<0){ if (rf < 0) {
cw_log(LOG_ERR,"Can't open %s: %s",cw_rand_dev,strerror(errno)); cw_log(LOG_ERR, "Can't open %s: %s", cw_rand_dev, strerror(errno));
return 0; return 0;
} }
@ -48,8 +48,8 @@ int cw_rand_r(uint8_t*dst, int len)
l = read(rf, dst, len); l = read(rf, dst, len);
close(rf); close(rf);
if ((l<0) && (errno != EAGAIN)){ if ((l < 0) && (errno != EAGAIN)) {
cw_log(LOG_ERR,"Cant read from %s: %s",cw_rand_dev,strerror(errno)); cw_log(LOG_ERR, "Cant read from %s: %s", cw_rand_dev, strerror(errno));
return 0; return 0;
} }
@ -58,25 +58,24 @@ int cw_rand_r(uint8_t*dst, int len)
int cw_rand(uint8_t * dst, int len)
int cw_rand(uint8_t *dst, int len)
{ {
static uint32_t rinit = 0; static uint32_t rinit = 0;
if (!rinit){ if (!rinit) {
int l = cw_rand_r((uint8_t*)(&rinit),sizeof(uint32_t)); int l = cw_rand_r((uint8_t *) (&rinit), sizeof(uint32_t));
if (l<sizeof(uint32_t)){ if (l < sizeof(uint32_t)) {
cw_log(LOG_WARNING,"Can't read enough bytes from %s. Using time to init rand instead.",cw_rand_dev); cw_log(LOG_WARNING,
rinit=time(NULL); "Can't read enough bytes from %s. Using time to init rand instead.",
cw_rand_dev);
rinit = time(NULL);
} }
srand(rinit); srand(rinit);
} }
int i; int i;
for (i=0; i<len; i++){ for (i = 0; i < len; i++) {
dst[i]=rand(); dst[i] = rand();
} }
return len; return len;
} }

View File

@ -42,7 +42,6 @@ extern int cw_foreach_msgelem(uint8_t * msgelems, int len,
int (*callback)(void*,int,uint8_t*,int),void *arg ); int (*callback)(void*,int,uint8_t*,int),void *arg );
extern int cw_rand(uint8_t*dst, int len);
@ -55,9 +54,9 @@ extern int cw_rand(uint8_t*dst, int len);
/* functions used to "rfc-verify" message elements */ /* functions used to "rfc-verify" message elements */
void cw_mand_elem_found(int *l,int type); //void cw_mand_elem_found(int *l,int type);
//int cw_is_missing_mand_elems(int *l); //int cw_is_missing_mand_elems(int *l);
void cw_get_missing_mand_elems(char *dst, int *l); //void cw_get_missing_mand_elems(char *dst, int *l);

View File

@ -144,14 +144,14 @@ int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr)
return 1; return 1;
} }
int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len) cw_item_t * cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len)
{ {
struct cw_item *i = cw_item_create(s, id); struct cw_item *i = cw_item_create(s, id);
if (!i) if (!i)
return 0; return NULL;
i->type = CW_ITEMTYPE_BSTR; i->type = CW_ITEMTYPE_BSTR;
i->data = bstr_create(data, len); i->data = bstr_create(data, len);
return 1; return i;
} }
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len) int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len)

View File

@ -74,7 +74,7 @@ extern cw_itemstore_t cw_itemstore_create();
extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n); extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n);
extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str); extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str);
extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr); extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr);
extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len); extern cw_item_t * cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword); extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword);
extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word); extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word);
extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte); extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte);

View File

@ -114,7 +114,6 @@ static int run_discovery(struct conn *conn)
time_t timer = cw_timer_start(0); time_t timer = cw_timer_start(0);
cw_itemstore_t discs;
while (!cw_timer_timeout(timer) while (!cw_timer_timeout(timer)
&& conn->capwap_state == CW_STATE_DISCOVERY) { && conn->capwap_state == CW_STATE_DISCOVERY) {
@ -129,9 +128,16 @@ static int run_discovery(struct conn *conn)
cw_log(LOG_ERROR,"Error reading messages: %s",strerror(errno)); cw_log(LOG_ERROR,"Error reading messages: %s",strerror(errno));
break; break;
} }
discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES);
} }
cw_itemstore_t discs;
discs = cw_itemstore_get_avltree(conn->remote, CW_ITEM_DISCOVERIES);
if (!discs) {
cw_log(LOG_ERR,"No discovery responses received");
return 0;
}
int i; int i;

View File

@ -187,7 +187,7 @@ int join()
struct conn * conn = get_conn(); struct conn * conn = get_conn();
cw_aciplist_t iplist = cw_itemstore_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST); cw_aciplist_t iplist = cw_itemstore_get_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST);
if (!iplist){ if (!iplist){
cw_log(LOG_ERR,"No Ips to join controller."); cw_log(LOG_ERR,"No IPs to join controller.");
return 0; return 0;
} }

View File

@ -75,7 +75,6 @@ int main()
cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube"); cw_itemstore_set_str(conn->local,CW_ITEM_WTP_NAME,"WTP Tube");
cw_log(LOG_ERR,"Entetrente");
discovery(); discovery();
join(); join();