Inital commit

FossilOrigin-Name: 86776c67b03ba8881130efdac7f5044f87534fe03f3323814322d5f5b07fa4dc
This commit is contained in:
7u83@mail.ru 2016-04-04 05:25:00 +00:00
parent 48a23c9e89
commit b89990a8c0
4 changed files with 271 additions and 0 deletions

31
src/cw/mbag_get_upd.c Normal file
View 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
View 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
View File

@ -0,0 +1,5 @@
const struct mbag_typedef mbag_type_bstr = {
"bstr",free
};

View File

@ -0,0 +1,117 @@
#include "cw/mbag.h"
#include "cw/action.h"
#include "cw/dbg.h"
#include "cw/cw.h"
#include "cisco_items.h"
#include "include/cipwap_items.h"
#include "cw/capwap80211_items.h"
//int mbag_get_upd(mbag_t b, mbag_t b_upd, const char *id,
// uint8_t * dst, struct mbag_typedef * deftype, uint8_t * def, int deflen);
int mbag_get_upd(mbag_t b, mbag_t b_upd, const char *id, uint8_t *dst, int *found);
int cisco80211_out_wtp_radio_configuration(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
cw_dbg(DBG_X,"The update beginns ***************************************************************");
int count=0;
int n;
uint8_t *d = dst+10;
MAVLITER_DEFINE(it,conn->radios_upd);
mavliter_foreach(&it){
struct mbag_item *r = mavliter_get(&it);
mbag_t radio_upd = r->data;
mbag_t radio = mbag_i_get_mbag(conn->radios,r->iid,NULL);
radio = radio_upd;
d+=cw_put_byte(d,r->iid);
// mbag_t radio = mbag_i_get(conn->radios,radio_upd->data->iid);
n = mbag_get_upd(radio,radio_upd,CISCO_RADIOITEM80211_CFG_TYPE,d,&count);
d += n==-1 ? cw_put_byte(dst,0) : n;
n = mbag_get_upd(radio,radio_upd,CIPWAP_RADIOITEM80211_OCCUPANCY_LIMIT,d,&count);
d += n==-1 ? cw_put_word(dst,100) : n;
n = mbag_get_upd(radio,radio_upd,CIPWAP_RADIOITEM80211_CFP_PERIOD,d,&count);
d += n==-1 ? cw_put_byte(dst,4) : n;
n = mbag_get_upd(radio,radio_upd,CIPWAP_RADIOITEM80211_CFP_MAXIMUM_DURATION,d,&count);
d += n==-1 ? cw_put_word(dst,60) : n;
n = mbag_get_upd(radio,radio_upd,CW_RADIOITEM80211_BSSID,d,&count);
if (n==-1){
char defbssid[6]={1,2,3,4,5,6};
memcpy(d,defbssid,6);
d+=6;
}
else
d+=n;
n = mbag_get_upd(radio,radio_upd,CW_RADIOITEM80211_BEACON_PERIOD,d,&count);
d += n==-1 ? cw_put_word(dst,100) : n;
int dcount = 0;
n = mbag_get_upd(radio,radio_upd,CISCO_RADIOITEM80211_COUNTRY_STR1,d,&dcount);
if (!dcount){
n = mbag_get_upd(radio,radio_upd,CW_RADIOITEM80211_COUNTRY_STRING,d,&count);
d += n==-1 ? cw_put_data(d,(uint8_t*)"DE ",3) : n;
}
else
d+=n;
dcount=0;
n = mbag_get_upd(radio,radio_upd,CISCO_RADIOITEM80211_COUNTRY_STR2,d,&dcount);
if (!dcount){
n = mbag_get_upd(radio,radio_upd,CW_RADIOITEM80211_COUNTRY_STRING,d,&count);
d += n==-1 ? cw_put_data(d,(uint8_t*)"DE ",3) : n;
}
else
d+=n;
count +=dcount;
d+=cw_put_byte(d,10);
d+=cw_put_word(d,1);
d+=cw_put_word(d,0);
d+=cw_put_word(d,177<<8);
}
if (!count){
cw_dbg(DBG_X,"Return 0, because no item was in radio");
return 0;
}
cw_dbg(DBG_X,"Yupp we do!");
int l = d-dst-10;
return l + cw_put_elem_vendor_hdr(dst, a->vendor_id, a->elem_id, l);
/*
mbag_set_word(r,CW_RADIOITEM80211_BEACON_PERIOD,cw_get_word(data+13));
mbag_set_bstr16n(r,CW_RADIOITEM80211_COUNTRY_STRING,data+15,3);
mbag_set_bstr16n(r,CISCO_RADIOITEM80211_COUNTRY_STR1,data+15,3);
mbag_set_bstr16n(r,CISCO_RADIOITEM80211_COUNTRY_STR2,data+18,3);
*/
// mbag_set_byte(r,CISCO_RADIOITEM80211_CFG_TYPE,cw_get_byte(data+1));
}