Inital commit
FossilOrigin-Name: 86776c67b03ba8881130efdac7f5044f87534fe03f3323814322d5f5b07fa4dc
This commit is contained in:
31
src/cw/mbag_get_upd.c
Normal file
31
src/cw/mbag_get_upd.c
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
|
||||
|
||||
#include "mbag.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
int mbag_get_upd(mbag_t b, mbag_t b_upd, const char *id, uint8_t *dst, int *found)
|
||||
{
|
||||
struct mbag_item *i = mbag_get(b_upd, id);
|
||||
if (i) {
|
||||
if (!i->type->put ){
|
||||
cw_log(LOG_ERROR,"No put method for %s",i->type->name);
|
||||
return -1;
|
||||
}
|
||||
(*found)++;
|
||||
return i->type->put(i, dst);
|
||||
}
|
||||
i = mbag_get(b,id);
|
||||
if (i) {
|
||||
if (!i->type->put){
|
||||
cw_log(LOG_ERROR,"No put method for %s",i->type->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return i->type->put(i, dst);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
118
src/cw/mbag_type_bin.c
Normal file
118
src/cw/mbag_type_bin.c
Normal file
@ -0,0 +1,118 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "capwap80211_types.h"
|
||||
#include "dot11.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int to_str(void *item,char *dst)
|
||||
{
|
||||
mbag_item_t *it= item;
|
||||
|
||||
uint8_t *data = (uint8_t*)it->data;
|
||||
int n=*data;
|
||||
data++;
|
||||
|
||||
char *d=dst;
|
||||
char *space="";
|
||||
int i;
|
||||
for (i=0; i<n; i++){
|
||||
int val = data[i];
|
||||
|
||||
|
||||
d+=sprintf(d,"%s",space);
|
||||
if (val & 0x80){
|
||||
d+=sprintf(d,"*");
|
||||
}
|
||||
|
||||
d+=sprintf(d,"%0.1f",dot11_rate2float(val & 0x7f));
|
||||
|
||||
space=" ";
|
||||
|
||||
}
|
||||
|
||||
return d-dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static struct mbag_item * from_str(const char *src)
|
||||
{
|
||||
mbag_item_t * item = mbag_item_new(CAPWAP80211_TYPE_RATESET);
|
||||
if (!item)
|
||||
return NULL;
|
||||
|
||||
if (strlen(src)==0)
|
||||
return 0;
|
||||
|
||||
uint8_t rates[64];
|
||||
int nrates =0;
|
||||
|
||||
const char *s = src;
|
||||
|
||||
while (*s!=0){
|
||||
while (*s==' ')
|
||||
s++;
|
||||
int m=0;
|
||||
if(*s=='*'){
|
||||
m=0x80;
|
||||
s++;
|
||||
}
|
||||
else{
|
||||
m=0;
|
||||
}
|
||||
|
||||
float val;
|
||||
int n=sscanf(s,"%f",&val);
|
||||
if (n!=1)
|
||||
break;
|
||||
|
||||
int r = dot11_float2rate(val) | m;
|
||||
|
||||
rates[nrates++]=r;
|
||||
|
||||
|
||||
while (*s!=0 && *s!=' ')
|
||||
s++;
|
||||
|
||||
}
|
||||
|
||||
uint8_t *data = malloc(nrates+1);
|
||||
*data=nrates;
|
||||
memcpy(data+1,rates,nrates);
|
||||
|
||||
item->data=data;
|
||||
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
static struct mbag_item * get(const uint8_t *src,int len)
|
||||
{
|
||||
|
||||
mbag_item_t * item = mbag_item_new(MBAG_BIN);
|
||||
if (!item)
|
||||
return NULL;
|
||||
|
||||
uint8_t *data = malloc(len+1);
|
||||
if (!data){
|
||||
free (item);
|
||||
return NULL;
|
||||
}
|
||||
*data=len;
|
||||
memcpy(data+1,src,len);
|
||||
item->data=data;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
const struct mbag_typedef capwap80211_type_rateset = {
|
||||
.name = "Biary",
|
||||
.del = free,
|
||||
.from_str = from_str,
|
||||
.to_str = to_str,
|
||||
.get = get
|
||||
|
||||
};
|
5
src/cw/mbag_type_bstr.c
Normal file
5
src/cw/mbag_type_bstr.c
Normal file
@ -0,0 +1,5 @@
|
||||
const struct mbag_typedef mbag_type_bstr = {
|
||||
"bstr",free
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user