join works

FossilOrigin-Name: 85bcc56e6aca1fbb8c437e74bc6bdc16d378a510e8e48a7fb58b996e919e138f
This commit is contained in:
7u83@mail.ru 2018-04-07 17:28:00 +00:00
parent 195c76dc88
commit 3ae4f89bea
17 changed files with 162 additions and 124 deletions

View File

@ -59,6 +59,7 @@ CWSRC=\
cw_in_check_join_resp.c\
cw_in_generic.c\
cw_in_generic_struct.c\
cw_out_generic_struct.c\
cw_init_data_keep_alive_msg.c\
cw_inline.c\
cw_in_radio_generic.c\
@ -96,7 +97,6 @@ CWSRC=\
cw_type_ipaddress.c\
cw_type_word.c\
cw_type_sysptr.c\
cw_util.c\
cw_write_descriptor_subelem.c\
cw_read_from.c \
cw_write_radio_element.c\
@ -123,13 +123,13 @@ KTVSRC=\
cw_ktv_read_file.c\
cw_ktv_readline.c\
cw_ktv_read_struct.c\
cw_ktv_write_struct.c\
cw_ktv_std_types.c\
LWSRC=\
lw_addelem.c\
lw_checksum.c\
lw_cisco_id_to_str.c\
lw_elem_id_to_str.c\
lw_inline.c\
lw_msg_id_to_str.c\
@ -138,7 +138,6 @@ LWSRC=\
lw_put_ac_descriptor.c\
lw_put_bstr.c\
lw_put_str.c\
lw_put_cisco_path_mtu.c\
lw_put_image_data.c\
lw_put_sockaddr.c\
lw_readelem_wtp_name.c\
@ -172,6 +171,7 @@ MAVLSRC=\
MLISTSRC=\
mlist_append.c\
mlist_delete.c\
mlist_append_ptr.c\
mlist_create.c\
mlist_destroy.c\

View File

@ -15,8 +15,8 @@ struct cw_StrListElem capwap_strings_elem[] = {
{CW_ELEM_RESERVED_9, "Reserved 9"},
{CW_ELEM_CAPWAP_CONTROL_IPV4_ADDRESS, "Control IPv4 Address"},
{CW_ELEM_CAPWAP_CONTROL_IPV6_ADDRESS, "Control IPv6 Address"},
{CW_ELEM_CAPWAP_LOCAL_IPV4_ADDRESS, "CAWPAP Local IPv4 Address"},
{CW_ELEM_CAPWAP_LOCAL_IPV6_ADDRESS, "CAPWAP Local IPv6 Address"},
{CAPWAP_ELEM_CAPWAP_LOCAL_IPV4_ADDRESS, "CAWPAP Local IPv4 Address"},
{CAPWAP_ELEM_CAPWAP_LOCAL_IPV6_ADDRESS, "CAPWAP Local IPv6 Address"},
{CW_ELEM_CAPWAP_TIMERS, "CAPWAP Timers"},
{CW_ELEM_CAPWAP_TRANSPORT_PROTOCOL, "CAPWAP Transport Protocol"},
{CW_ELEM_DATA_TRANSFER_DATA, "Data Transfer Data"},
@ -36,7 +36,7 @@ struct cw_StrListElem capwap_strings_elem[] = {
{CW_ELEM_IMAGE_INFORMATION, "Image Information"},
{CW_ELEM_INITIATE_DOWNLOAD, "Initiate Download"},
{CAPWAP_ELEM_LOCATION_DATA, "Location Data"},
{CW_ELEM_MAXIMUM_MESSAGE_LENGTH, "Maximum Message Length"},
{CAPWAP_ELEM_MAXIMUM_MESSAGE_LENGTH, "Maximum Message Length"},
{CAPWAP_ELEM_MTU_DISCOVERY_PADDING, "MTU Discovery Padding"},
{CW_ELEM_RADIO_ADMINISTRATIVE_STATE, "Radio Administrative State"},
{CW_ELEM_RADIO_OPERATIONAL_STATE, "Radio Operational State"},

View File

@ -39,11 +39,10 @@
/*#include "mbag.h"*/
#include "intavltree.h"
#include "bstr.h"
#include "mod.h"
struct cw_action_in;
#define CONN_MAX_MSG_LENGTH 65536

View File

@ -400,6 +400,9 @@ int cw_in_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerP
int cw_out_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst);
int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst);
int cw_in_radio_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
uint8_t * elem_data, int elem_len);
@ -486,6 +489,11 @@ int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state);
int cw_put_local_ip_address(uint8_t *dst, int id, int ipv_id, int ipv6_id,
uint8_t *src, int len);
uint8_t *cw_init_data_keep_alive_msg(uint8_t * buffer,uint8_t *rmac);
/*int cw_out_radio_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst);*/

View File

@ -0,0 +1,35 @@
#include "ktv.h"
#include "dbg.h"
#include "log.h"
int cw_ktv_write_struct(mavl_t ktv, const cw_KTVStruct_t * stru, const char *pkey,
uint8_t * dst)
{
char key[CW_KTV_MAX_KEY_LEN];
int pos, i;
cw_KTV_t * result;
pos=0; i=0;
for(i=0; stru[i].type != NULL;i++){
if (stru[i].position!=-1){
pos=stru[i].position;
}
memset(dst+pos,0,stru[i].len);
sprintf(key,"%s/%s",pkey,stru[i].key);
result = cw_ktv_get(ktv,key,stru[i].type);
if (result == NULL){
cw_log(LOG_ERR,"Can't put %s, no value found",key);
continue;
}
result->type->put(result,dst+pos);
pos+=stru[i].len;
}
return pos;
}

View File

@ -0,0 +1,30 @@
#include "capwap.h"
#include "msgset.h"
#include "ktv.h"
#include "log.h"
#include "cw.h"
int cw_out_generic_struct(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
, uint8_t * dst)
{
int start;
int len,l;
start = handler->vendor ? 10 : 4;
if (!handler->type){
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
len = cw_ktv_write_struct(params->conn->local_cfg,handler->type,handler->key,dst+start);
if (handler->vendor)
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
l = len + cw_put_elem_hdr(dst, handler->id, len);
return l;
}

View File

@ -25,6 +25,7 @@ int cw_process_element(struct cw_ElemHandlerParams *params, int proto, int vendo
/* try to retrieve a handler for this message element */
handler = cw_msgset_get_elemhandler(params->conn->msgset,proto, vendor, elem_id);
if (!handler) {
cw_dbg(DBG_ELEM_ERR, "Unrecognized message element: %d, ignoring",
elem_id);
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;

View File

@ -7,47 +7,26 @@
#include "dbg.h"
#include "cw.h"
int cw_put_local_ip_address(int sock, uint8_t *dst, int ipv4elem_id, int ipv6elem_id)
int cw_put_local_ip_address(uint8_t *dst, int id, int ipv4_id, int ipv6_id,
uint8_t *src, int len)
{
struct sockaddr_storage a;
int id;
socklen_t alen = sizeof(struct sockaddr_storage);
int rc = getsockname(sock, (struct sockaddr *) &a, &alen);
if (rc != 0){
cw_log(LOG_ERR,"Can't determine sock IP address - %s\n",strerror(errno));
return 0;
}
switch (((struct sockaddr *) &a)->sa_family) {
case AF_INET:
{
struct sockaddr_in *sain = (struct sockaddr_in *) &a;
id = ipv4elem_id;
cw_put_data(dst + 4, (uint8_t *) & sain->sin_addr, 4);
if (len ==4 && id == ipv4_id){
cw_put_data(dst + 4, src, 4);
return 4 + cw_put_elem_hdr(dst, id, 4);
}
case AF_INET6:
{
struct sockaddr_in6 *sain;
id = ipv6elem_id;
sain = (struct sockaddr_in6 *) &a;
cw_put_data(dst + 4, (uint8_t *) & sain->sin6_addr, 16);
return 16 + cw_put_elem_hdr(dst, id, 16);
if (len ==16 && id == ipv6_id){
cw_put_data(dst + 4, src, 16);
return 4 + cw_put_elem_hdr(dst, id, 4);
}
}
cw_log(DBG_MSG_ERR, "Can't determine CAPWAP Local IP Adress");
return 0;
}

View File

@ -102,6 +102,10 @@ static int len ( struct cw_KTV * data ){
return bstr_len(data->val.ptr);
}
static void * data(cw_KTV_t * data)
{
return bstr_data(data->val.ptr);
}
const struct cw_Type cw_type_ipaddress = {
"IPAddress", /* name */
@ -110,7 +114,8 @@ const struct cw_Type cw_type_ipaddress = {
get, /* get */
to_str, /* to_str */
from_str, /* from_str */
len /* len */
len, /* len */
data /* data */
};

View File

@ -1,74 +0,0 @@
/*
This file is part of libcapwap.
libcapwap 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/>.
*/
#include <stdio.h>
#include "cw_util.h"
#include "log.h"
#include "capwap.h"
/*
void cw_mand_elem_found(int *l,int type)
{
if (!cw_dbg_is_level(DBG_CW_RFC))
return;
int i;
for (i=0; l[i]!=-1; i++){
if(l[i]==type){
l[i]=0;
return;
}
}
}
*/
/*
void cw_get_missing_mand_elems(char *dst, int *l)
{
if (!cw_dbg_is_level(DBG_CW_RFC))
return;
char *s = dst;
int i;
const char * k = "";
for (i=0; l[i]!=-1; i++){
if(l[i]){
s += sprintf(s,"%s[%s]",k,cw_strelem(l[i]));
k=",";
}
}
}
*/
/*
int cw_is_missing_mand_elems(int *l)
{
int i;
for (i=0; l[i]!=-1; i++){
if(l[i]){
return 1;
}
}
return 0;
}
*/

View File

@ -521,7 +521,7 @@ void cw_dbg_ktv_dump(mavl_t ktv, uint32_t dbglevel,
type = data->type;
type->to_str(data,value,0);
cw_dbg(dbglevel,"%s%s (%s): %s",prefix,data->key,type->name, value);
cw_dbg(dbglevel,"%s%s :%s: %s",prefix,data->key,type->name, value);
}
if (footer != NULL)

View File

@ -102,7 +102,7 @@ int dtls_gnutls_accept(struct conn *conn)
if (tlen < 0 && errno == EAGAIN)
continue;
if (tlen < 0) {
/* something went wrong, iwe should log a message */
/* something went wrong, we should log a message */
continue;
}

View File

@ -93,6 +93,10 @@ struct cw_KTVStruct {
typedef struct cw_KTVStruct cw_KTVStruct_t;
int cw_ktv_read_struct(mavl_t ktv,const cw_KTVStruct_t * stru, const char *pkey,
uint8_t * data, int len);
int cw_ktv_write_struct(mavl_t ktv, const cw_KTVStruct_t * stru, const char *pkey,
uint8_t * dst);
extern const struct cw_Type cw_type_byte;
extern const struct cw_Type cw_type_word;

View File

@ -2,13 +2,13 @@
#include "lwapp.h"
#include "lwapp_cisco.h"
/*#include "lwapp_cisco.h"*/
#include "lw.h"
#include "vendors.h"
/*
int lw_addelem(uint8_t*dst, uint8_t type, uint8_t *msgelem, uint16_t len)
{
*dst = type;
@ -30,11 +30,15 @@ int lw_addelem_vendor_specific(uint8_t *dst,uint32_t vendor_id,uint16_t elem_id,
lw_set_word(dst+1,l);
return l;
}
*/
/**
* Add the vendor specific elem Cisco Padding
* @param dst destination
*/
/*
int lw_addelem_cisco_padding(uint8_t *dst, int len)
{
lw_set_dword(dst+3,LW_VENDOR_ID_CISCO);
@ -43,6 +47,7 @@ int lw_addelem_cisco_padding(uint8_t *dst, int len)
memset(dst+11,0,len);
return lw_put_elem_hdr(dst,LW_ELEM_VENDOR_SPECIFIC,11+len);
}
*/
/*
int lw_put_cisco_path_mtu(uint8_t *dst, uint16_t max, uint16_t padding)

View File

@ -72,6 +72,8 @@ typedef struct mlist * mlist_t;
mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2), void (*del)(void *), size_t data_size);
struct mlistelem *mlist_append(mlist_t l, void *data);
struct mlistelem * mlist_delete(mlist_t list, void *data);
struct mlistelem * mlist_get(mlist_t list, const void *data);
void mlist_destroy(mlist_t l);
struct mlistelem *mlist_replace(mlist_t l, void *data);

View File

@ -1,17 +1,60 @@
#include <string.h>
#include <stdio.h>
#include "mlist.h"
struct mlistelem * mlist_replace(mlist_t list, void *data)
struct mlistelem * mlist_delete(mlist_t list, void *data)
{
struct mlistelem *e;
e = mlist_get(list,data);
mlist_foreach(e,list){
void *tdata = mlistelem_dataptr(e);
if (list->cmp(tdata,data)==0){
break;
}
}
if (e == NULL)
return NULL;
if (e->prev==NULL && e->next==NULL){
if (list->del)
list->del(e);
free(e);
list->count=0;
list->first=NULL;
list->last=NULL;
return NULL;
}
if (e==list->first){
list->first=e->next;
e->next->prev=NULL;
if (list->del)
list->del(e);
list->count--;
free(e);
return NULL;
return e;
}
if (e==list->last){
list->last=e->prev;
e->prev->next=NULL;
if (list->del)
list->del(e);
list->count--;
free(e);
return NULL;
}
e->next->prev=e->prev;
e->prev->next=e->next;
if (list->del)
list->del(e);
list->count--;
free(e);
return NULL;
}

View File

@ -198,11 +198,12 @@ static int update_msgdata(struct cw_MsgSet *set, struct cw_MsgData *msgdata,
elemdef->vendor, elemdef->id, handler->name);
}
/* add message elemeent to the elements list */
/* add/delete/replace message elemeent to/from/in the elements list */
switch ( elemdef->op & 0xff){
case CW_IGNORE:
break;
case CW_DELETE:
mlist_delete(msgdata->elements_list, &ed);
break;
case CW_APPEND:
mlist_append(msgdata->elements_list, &ed);