New type cw_type_bits
This commit is contained in:
@ -60,6 +60,7 @@ CWSRC=\
|
||||
cw_type_word.c\
|
||||
cw_type_sysptr.c\
|
||||
cw_type_array.c\
|
||||
cw_type_bits.c\
|
||||
cw_write_descriptor_subelem.c\
|
||||
cw_write_radio_element.c\
|
||||
cw_detect_nat.c\
|
||||
|
@ -11,7 +11,7 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
|
||||
char mkey[CW_CFG_MAX_KEY_LEN];
|
||||
const char *key;
|
||||
|
||||
|
||||
// cw_dbg(DBG_X,"HK: %s",handler->key,);
|
||||
|
||||
if (!type){
|
||||
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
||||
@ -25,11 +25,7 @@ int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams *
|
||||
else{
|
||||
key = handler->key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* cw_dbg(DBG_X, "READ: %s / %s",type->name,key);*/
|
||||
// cw_dbg(DBG_X, "READ: %s / %s",type->name,key);
|
||||
type->read(params->cfg, key,elem_data,elem_len,handler->param);
|
||||
return CAPWAP_RESULT_SUCCESS;
|
||||
}
|
||||
|
@ -560,6 +560,8 @@ int cw_put_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
|
||||
int cw_send_request(struct cw_Conn *conn,int msg_id);
|
||||
int cw_out_generic_walk(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst);
|
||||
int cw_out_generic0(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params
|
||||
, uint8_t * dst,const char *key);
|
||||
|
||||
/**
|
||||
*@}
|
||||
|
@ -1,37 +0,0 @@
|
||||
|
||||
#include "capwap.h"
|
||||
#include "msgset.h"
|
||||
#include "val.h"
|
||||
#include "log.h"
|
||||
#include "dbg.h"
|
||||
|
||||
int cw_in_generic(struct cw_ElemHandler * handler, struct cw_ElemHandlerParams * params,
|
||||
uint8_t * elem_data, int elem_len)
|
||||
{
|
||||
cw_Type_t * type;
|
||||
type = (cw_Type_t*)handler->type;
|
||||
char mkey[CW_CFG_MAX_KEY_LEN];
|
||||
const char *key;
|
||||
|
||||
|
||||
|
||||
if (!type){
|
||||
cw_log(LOG_ERR,"Can't handle element: %s, no type defined",handler->name);
|
||||
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
|
||||
}
|
||||
|
||||
if (handler->mkkey != NULL){
|
||||
handler->mkkey(handler->key,elem_data,elem_len, mkey);
|
||||
key = mkey;
|
||||
}
|
||||
else{
|
||||
key = handler->key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* cw_dbg(DBG_X, "READ: %s / %s",type->name,key);*/
|
||||
type->read(params->cfg, key,elem_data,elem_len,handler->param);
|
||||
return CAPWAP_RESULT_SUCCESS;
|
||||
}
|
54
src/cw/cw_type_bits.c
Normal file
54
src/cw/cw_type_bits.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include "val.h"
|
||||
|
||||
static int get_len(const struct cw_ValBit *bits)
|
||||
{
|
||||
int i;
|
||||
for (i=0;bits[i].key!=NULL;i++);
|
||||
return bits[i].bit;
|
||||
}
|
||||
|
||||
static int get_bit(const uint8_t * src,int pos, int len)
|
||||
{
|
||||
int b;
|
||||
uint8_t m;
|
||||
b = len-1-pos/8;
|
||||
m = 1<<(pos%8);
|
||||
return src[b]&m ? 1:0;
|
||||
}
|
||||
|
||||
static int bread(cw_Cfg_t *cfg, const char * key, const uint8_t *src, int len, const void *param)
|
||||
{
|
||||
const struct cw_ValBit * bits=param;
|
||||
int l,i;
|
||||
|
||||
l = get_len(bits);
|
||||
for(i=0;bits[i].key!=NULL;i++){
|
||||
int rc;
|
||||
printf("%s: %d\n",bits[i].key,get_bit(src,bits[i].bit,l));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void * param)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const struct cw_Type cw_type_bits = {
|
||||
"Bits", /* name */
|
||||
NULL, /* del */
|
||||
NULL, /* put */
|
||||
NULL, /* get */
|
||||
NULL, /* to_str */
|
||||
NULL, /* from_str */
|
||||
NULL, /* len */
|
||||
NULL, /* data */
|
||||
NULL, /* get_type_name */
|
||||
NULL,
|
||||
bread,
|
||||
bwrite
|
||||
|
||||
};
|
@ -37,12 +37,13 @@ static int read_struct(cw_Cfg_t * cfg,const cw_ValStruct_t * stru, const char *p
|
||||
break;
|
||||
default:
|
||||
l = stru[i].len;
|
||||
cw_dbg(DBG_X,"pos: %d, l:%d. len: %d",pos,l,len);
|
||||
if (pos+l > len){
|
||||
l = len-pos;
|
||||
l = pos<len ? len-pos : 0 ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cw_dbg(DBG_X,"This is l %d",l);
|
||||
l=stru[i].type->read(cfg,key,data+pos,l,stru[i].valguard);
|
||||
|
||||
|
||||
@ -102,8 +103,9 @@ static int write_struct(cw_Cfg_t ** cfgs, const cw_ValStruct_t * stru, const ch
|
||||
sprintf(key,"%s",pkey);
|
||||
|
||||
// result = cw_cfg_get_l(cfgs,key,NULL);
|
||||
|
||||
rc = cw_cfg_base_exists_l(cfgs,key);
|
||||
// printf("Base? :%s, %d\n",key,rc);
|
||||
// cw_dbg(DBG_X,"Base? :'%s', %d\n",key,rc);
|
||||
if(result) {
|
||||
// char s[2048];
|
||||
// result->type->to_str(result,s,2048);
|
||||
|
@ -86,9 +86,7 @@ struct cw_StrListElem cw_dbg_strings[] = {
|
||||
DBG_ELEM_IN | DBG_ELEM_OUT |
|
||||
DBG_MSG_ERR | DBG_ELEM_ERR |
|
||||
DBG_PKT_ERR | DBG_RFC | DBG_WARN
|
||||
|
||||
|
||||
| DBG_STATE), "std" },
|
||||
| DBG_STATE | DBG_INFO), "std" },
|
||||
|
||||
{ DBG_ALL, "all"},
|
||||
|
||||
|
@ -52,6 +52,7 @@ typedef struct cw_Val cw_Val_t;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @class cw_Type
|
||||
* @author 7u83
|
||||
@ -117,7 +118,10 @@ struct cw_ValStruct {
|
||||
typedef struct cw_ValStruct cw_ValStruct_t;
|
||||
|
||||
|
||||
|
||||
struct cw_ValBit {
|
||||
uint16_t bit;
|
||||
const char *key;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -147,6 +151,7 @@ struct cw_ValIndexed{
|
||||
typedef struct cw_ValIndexed cw_ValIndexed_t;
|
||||
|
||||
|
||||
extern const struct cw_Type cw_type_bits;
|
||||
extern const struct cw_Type cw_type_byte;
|
||||
extern const struct cw_Type cw_type_word;
|
||||
extern const struct cw_Type cw_type_dword;
|
||||
@ -159,6 +164,7 @@ extern const struct cw_Type cw_type_bool;
|
||||
extern const struct cw_Type cw_type_struct;
|
||||
extern const struct cw_Type cw_type_array;
|
||||
|
||||
#define CW_TYPE_BITS (&cw_type_bits)
|
||||
#define CW_TYPE_BYTE (&cw_type_byte)
|
||||
#define CW_TYPE_WORD (&cw_type_word)
|
||||
#define CW_TYPE_DWORD (&cw_type_dword)
|
||||
|
Reference in New Issue
Block a user