Improved CAPWAP AC Descriptr handling

This commit is contained in:
7u83 2022-08-22 20:11:33 +02:00
parent 05963edc98
commit 23360febfa
7 changed files with 101 additions and 79 deletions

View File

@ -36,7 +36,7 @@ actube/ipv6: false
#actube/mod.2: capwap80211 #actube/mod.2: capwap80211
# #
actube/mod.0: cisco #actube/mod.0: cisco
actube/mod.1: capwap actube/mod.1: capwap
actube/mod.2: capwap80211 actube/mod.2: capwap80211

View File

@ -158,9 +158,14 @@ int cw_header_len(struct cw_ElemHandler * handler)
/**
int cw_put_ac_status(cw_Cfg_t ** cfg_list, uint8_t *dst, const char * parent_key){ * Put the "status part" of an an AC Descriptor to memory
stop(); * @param cfg_list Cfg list to read status from
* @param dst Where to put the status to
* @param parent_key prefix to each key
*/
int
cw_put_ac_status(uint8_t *dst, cw_Cfg_t ** cfg_list, const char * parent_key){
uint8_t *d = dst; uint8_t *d = dst;
@ -174,26 +179,92 @@ int cw_put_ac_status(cw_Cfg_t ** cfg_list, uint8_t *dst, const char * parent_key
sprintf(key,"%s/%s",parent_key,"station-limit"); sprintf(key,"%s/%s",parent_key,"station-limit");
d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,key,0)); d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,key,0));
/* Put number of active WTPS */ /* Put number of active WTPs */
sprintf(key,"%s/%s",parent_key,"active-wtps"); sprintf(key,"%s/%s",parent_key,"active-wtps");
d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,key,0)); d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,key,0));
d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,"ac-descriptor/max-wtps",0)); /* Put max WTPs */
sprintf(key,"%s/%s",parent_key,"max-wtps");
d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,"ac-descriptor/security",0)); d += cw_put_word(d,cw_cfg_get_word_l(cfg_list,key,0));
sprintf(key,"%s/%s",parent_key,CW_SKEY_RMAC_FIELD); /* Put security flags */
sprintf(key,"%s/%s",parent_key,"security");
d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,key,0));
/* Put rmac-filed */
sprintf(key,"%s/%s",parent_key,"rmac-field");
d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,key,0)); d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,key,0));
/* reserved field, must be zero - RFC5415 */ /* reserved field, must be zero - RFC5415 */
d += cw_put_byte(d,0); d += cw_put_byte(d,0);
sprintf(key,"%s/%s",parent_key,"dtls-policy");
sprintf(key,"%s/%s",parent_key,CW_SKEY_DTLS_POLICY);
d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,key,0)); d += cw_put_byte(d,cw_cfg_get_byte_l(cfg_list,key,0));
return d - dst; return d - dst;
} }
/**
* Put a descripter sub element like harware vendor/version etc.
* Used when putting AC Descriptors or WTP Descriptors
* @param dst Where to write to
* @param cfg_list list of cfgs
* @subelem_id Id of subelement
* @parent_key parent key
*/
int
cw_put_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
int subelem_id, const char * parent_key )
{
char key[256];
uint32_t vendor;
//bstr16_t version;
const char *vendor_s;
uint8_t *d;
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
*/
sprintf (key, "%s/%s", parent_key, CW_SKEY_VENDOR);
vendor_s = cw_cfg_get_l (cfg_list, key, NULL);
if (vendor_s == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, no value of type Dword found.", key);
return 0;
}
vendor = atoi(vendor_s);
sprintf (key, "%s/%s", parent_key, CW_SKEY_VERSION);
cw_Val_t * val = cw_cfg_get_val_l(cfg_list, key, CW_TYPE_BSTR16);
//version = cw_cfg_get_bstr16 (cfg, key, NULL);
if (val == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, no value of type Bstr16 found.", key);
return 0;
}
d = dst;
/* put vendor */
d += cw_put_dword(d, vendor); //->type->put (vendor, d);
/* put version */
d += cw_put_dword (d, (subelem_id << 16) | val->type->len(val));
// d += cw_put_bstr16(d, version);
d += val->type->put(val,d);
cw_val_destroy(val);
// free(version);
return d-dst;
}

View File

@ -552,6 +552,9 @@ int cw_write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len);
int cw_header_len(struct cw_ElemHandler * handler); int cw_header_len(struct cw_ElemHandler * handler);
int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout); int cw_compose_message(struct cw_Conn *conn, uint8_t * rawout);
int cw_put_ac_status(uint8_t *dst, cw_Cfg_t ** cfg_list, const char * parent_key);
int cw_put_descriptor_subelem (uint8_t *dst, cw_Cfg_t ** cfg_list,
int subelem_id, const char * parent_key );
/** /**

View File

@ -9,15 +9,12 @@ int capwap_in_ac_descriptor(struct cw_ElemHandler *eh,
struct cw_ElemHandlerParams *params, struct cw_ElemHandlerParams *params,
uint8_t * data, int len) uint8_t * data, int len)
{ {
stop();
static struct cw_DescriptorSubelemDef allowed[] = { static struct cw_DescriptorSubelemDef allowed[] = {
{0,CAPWAP_SUBELEM_AC_HARDWARE_VERSION, "hardware", 1024,1}, {0,CAPWAP_SUBELEM_AC_HARDWARE_VERSION, "hardware", 1024,1},
{0,CAPWAP_SUBELEM_AC_SOFTWARE_VERSION, "software", 1024,1}, {0,CAPWAP_SUBELEM_AC_SOFTWARE_VERSION, "software", 1024,1},
{0,0, NULL,0, 0} {0,0, NULL,0, 0}
}; };
return cw_read_ac_descriptor(params->cfg,eh,params,data,len,allowed); return cw_read_ac_descriptor(params->cfg,eh,params,data,len,allowed);
} }

View File

@ -3,74 +3,27 @@
#include "cw/dbg.h" #include "cw/dbg.h"
#include "cw/conn.h" #include "cw/conn.h"
#include "cw/capwap.h" #include "cw/capwap.h"
#include "cw/cw.h" #include "cw/cw.h"
#include "cw/val.h"
#include "cw/keys.h" #include "cw/keys.h"
#include "mod_capwap.h"
static int put_ac_status(mavl_t global, mavl_t local, uint8_t *dst, const char * parent_key){
stop();
uint8_t *d = dst;
char key[CW_CFG_MAX_KEY_LEN];
d += cw_put_word(d,cw_ktv_get_word(global,"ac-descriptor/stations",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac-descriptor/station-limit",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac-descriptor/active-wtps",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac-descriptor/max-wtps",0));
d += cw_put_byte(d,cw_ktv_get_byte(global,"ac-descriptor/security",0));
/*
security = 0;
if (cw_ktv_get(local,"dtls-cert-file",CW_TYPE_BSTR16))
security |= CAPWAP_FLAG_AC_SECURITY_X;
if (cw_ktv_get(local,"dtls-psk",CW_TYPE_BSTR16))
security |= CAPWAP_FLAG_AC_SECURITY_S;
if (security == 0){
cw_log(LOG_WARNING,"No AC security selected");
}
d += cw_put_byte(dst,security);
*/
sprintf(key,"%s/%s",parent_key,CW_SKEY_RMAC_FIELD);
d += cw_put_byte(d,cw_ktv_get_byte(local,key,0));
d += cw_put_byte(d,0);
sprintf(key,"%s/%s",parent_key,CW_SKEY_DTLS_POLICY);
d += cw_put_byte(d,cw_ktv_get_byte(local,key,0));
return d - dst;
}
int capwap_out_ac_descriptor(struct cw_ElemHandler * eh, int capwap_out_ac_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst) struct cw_ElemHandlerParams * params, uint8_t * dst)
{ {
stop(); int len,l;
/* int len,l;
uint8_t *d = dst+4; uint8_t *d = dst+4;
char key[CW_CFG_MAX_KEY_LEN]; char key[CW_CFG_MAX_KEY_LEN];
d+=put_ac_status(params->cfg, d+=cw_put_ac_status(d, params->cfg_list, eh->key);
params->global_cfg,
d, eh->key);
sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE); sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE);
d+=cw_write_descriptor_subelem (d, params->cfg, d+=cw_put_descriptor_subelem (d, params->cfg_list,
CAPWAP_SUBELEM_AC_HARDWARE_VERSION, key); CAPWAP_SUBELEM_AC_HARDWARE_VERSION, key);
sprintf(key,"%s/%s",eh->key,CW_SKEY_SOFTWARE); sprintf(key,"%s/%s",eh->key,CW_SKEY_SOFTWARE);
d+=cw_write_descriptor_subelem (d, params->cfg, d+=cw_put_descriptor_subelem (d, params->cfg_list,
CAPWAP_SUBELEM_AC_SOFTWARE_VERSION, key); CAPWAP_SUBELEM_AC_SOFTWARE_VERSION, key);
len = d-dst-4; len = d-dst-4;
@ -78,6 +31,5 @@ int capwap_out_ac_descriptor(struct cw_ElemHandler * eh,
l = len + cw_put_elem_hdr(dst,eh->id,len); l = len + cw_put_elem_hdr(dst,eh->id,len);
cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,eh,dst,l); cw_dbg_elem(DBG_ELEM_OUT,NULL,params->msgdata->type,eh,dst,l);
return l; return l;
*/
return 0;
} }

View File

@ -50,7 +50,6 @@ int static setup_cfg(struct cw_Conn * conn)
security = cw_setup_dtls(conn,conn->local_cfg,"capwap",CAPWAP_CIPHER); security = cw_setup_dtls(conn,conn->local_cfg,"capwap",CAPWAP_CIPHER);
printf ("ROLE: %d\n",conn->role);
// stop(); // stop();
// cw_ktv_set_byte(conn->local_cfg,"ac-descriptor/security",security); // cw_ktv_set_byte(conn->local_cfg,"ac-descriptor/security",security);

View File

@ -6,8 +6,8 @@ ac-name-with-index.0:
ac-name-with-index.1: ac-name-with-index.1:
ac-name-with-index.2: ac-name-with-index.2:
capwap-local-ip-address: 192.168.0.13 capwap-local-ip-address: 192.168.0.13
capwap-timers/echo-interval: 30 capwap-timers/echo-interval: 0
capwap-timers/max-discovery-interval: 10 capwap-timers/max-discovery-interval: 0
capwap/ac-name: capwap/ac-name:
cisco-8011-assoc-limit/enable: false cisco-8011-assoc-limit/enable: false
cisco-8011-assoc-limit/interval: 500 cisco-8011-assoc-limit/interval: 500
@ -117,7 +117,7 @@ radio.0/cisco/elem146: .x690f
radio.0/cisco/elem153: .x00 radio.0/cisco/elem153: .x00
radio.0/cisco/elem156: .x020100 radio.0/cisco/elem156: .x020100
radio.0/cisco/elem16: .x02040b0c radio.0/cisco/elem16: .x02040b0c
radio.0/cisco/elem19: .xc0a800a10001000cc0a800a103000101001ecd774fc43bd27db633509934957d3acb000000000000000052464d000000000000000000000000000000000000000000000000000000000001060b010101 radio.0/cisco/elem19: .xc0a800a10001000cc0a800a103000101003ccd774fc43bd27db633509934957d3acb000000000000000052464d000000000000000000000000000000000000000000000000000000000001060b010101
radio.0/cisco/elem22: .x0d00b400320102030405060708090a0b0c0d radio.0/cisco/elem22: .x0d00b400320102030405060708090a0b0c0d
radio.0/cisco/elem24: .x003c000c radio.0/cisco/elem24: .x003c000c
radio.0/cisco/elem47: .x0100000000000000000000000000000000 radio.0/cisco/elem47: .x0100000000000000000000000000000000
@ -170,7 +170,7 @@ radio.0/wlan.1/add-wlan/scan-defer-time: 100
radio.0/wlan.1/add-wlan/session-timout: 1800 radio.0/wlan.1/add-wlan/session-timout: 1800
radio.0/wlan.1/add-wlan/ssid: tubeC radio.0/wlan.1/add-wlan/ssid: tubeC
radio.0/wlan.1/add-wlan/wep-encryption: false radio.0/wlan.1/add-wlan/wep-encryption: false
radio.0/wlan.1/add-wlan/wep-key: .xe90245968787036bf1e1756fc8 radio.0/wlan.1/add-wlan/wep-key: .x31772582ab25934f97c565949f
radio.0/wlan.1/add-wlan/wep-key-index: 1 radio.0/wlan.1/add-wlan/wep-key-index: 1
radio.0/wlan.1/add-wlan/wlan-capability: 1073 radio.0/wlan.1/add-wlan/wlan-capability: 1073
radio.0/wlan.1/add-wlan/wlan-id: 1 radio.0/wlan.1/add-wlan/wlan-id: 1
@ -187,7 +187,7 @@ radio.0/wlan.13/add-wlan/scan-defer-time: 100
radio.0/wlan.13/add-wlan/session-timout: 1800 radio.0/wlan.13/add-wlan/session-timout: 1800
radio.0/wlan.13/add-wlan/ssid: SuperSSID radio.0/wlan.13/add-wlan/ssid: SuperSSID
radio.0/wlan.13/add-wlan/wep-encryption: false radio.0/wlan.13/add-wlan/wep-encryption: false
radio.0/wlan.13/add-wlan/wep-key: .xe90245968787036bf1e1756fc8 radio.0/wlan.13/add-wlan/wep-key: .x31772582ab25934f97c565949f
radio.0/wlan.13/add-wlan/wep-key-index: 1 radio.0/wlan.13/add-wlan/wep-key-index: 1
radio.0/wlan.13/add-wlan/wlan-capability: 1057 radio.0/wlan.13/add-wlan/wlan-capability: 1057
radio.0/wlan.13/add-wlan/wlan-id: 13 radio.0/wlan.13/add-wlan/wlan-id: 13
@ -205,12 +205,12 @@ radio.1/cisco/antenna-payload/unknown: 3
radio.1/cisco/channel-power: .x0808102408221c16100a04fefe2808221c16100a04fefe2c08221c16100a04fefe3008221c16100a04fefe3408221c16100a04fefe3808221c16100a04fefe3c08221c16100a04fefe4008221c16100a04fefe6408221c16100a04fefe6808221c16100a04fefe6c08221c16100a04fefe7008221c16100a04fefe7408221c16100a04fefe8408221c16100a04fefe8808221c16100a04fefe8c08221c16100a04fefe radio.1/cisco/channel-power: .x0808102408221c16100a04fefe2808221c16100a04fefe2c08221c16100a04fefe3008221c16100a04fefe3408221c16100a04fefe3808221c16100a04fefe3c08221c16100a04fefe4008221c16100a04fefe6408221c16100a04fefe6808221c16100a04fefe6c08221c16100a04fefe7008221c16100a04fefe7408221c16100a04fefe8408221c16100a04fefe8808221c16100a04fefe8c08221c16100a04fefe
radio.1/cisco/elem145: .x01 radio.1/cisco/elem145: .x01
radio.1/cisco/elem15/cfg-type: 1 - global radio.1/cisco/elem15/cfg-type: 1 - global
radio.1/cisco/elem15/channel: 48 radio.1/cisco/elem15/channel: 140
radio.1/cisco/elem15/rest: .x07ffffffce000000 radio.1/cisco/elem15/rest: .x07ffffffce010101
radio.1/cisco/elem153: .x00 radio.1/cisco/elem153: .x00
radio.1/cisco/elem156: .x020100 radio.1/cisco/elem156: .x020100
radio.1/cisco/elem16: .x0c121824 radio.1/cisco/elem16: .x0c121824
radio.1/cisco/elem19: .xc0a800a10001000bc0a800a110000101001ecd774fc43bd27db633509934957d3acb000000000000000052464d000000000000000000000000000000000000000000000000000000000024282c3034383c4064686c707484888c01010101010101010101010101010101 radio.1/cisco/elem19: .xc0a800a10001000bc0a800a110000101003ccd774fc43bd27db633509934957d3acb000000000000000052464d000000000000000000000000000000000000000000000000000000000024282c3034383c4064686c707484888c01010101010101010101010101010101
radio.1/cisco/elem22: .x1000b4003224282c3034383c4064686c707484888c radio.1/cisco/elem22: .x1000b4003224282c3034383c4064686c707484888c
radio.1/cisco/elem24: .x003c000c radio.1/cisco/elem24: .x003c000c
radio.1/cisco/elem47: .x0100000000000000000000000000000000 radio.1/cisco/elem47: .x0100000000000000000000000000000000
@ -263,7 +263,7 @@ radio.1/wlan.1/add-wlan/scan-defer-time: 100
radio.1/wlan.1/add-wlan/session-timout: 1800 radio.1/wlan.1/add-wlan/session-timout: 1800
radio.1/wlan.1/add-wlan/ssid: tubeC radio.1/wlan.1/add-wlan/ssid: tubeC
radio.1/wlan.1/add-wlan/wep-encryption: false radio.1/wlan.1/add-wlan/wep-encryption: false
radio.1/wlan.1/add-wlan/wep-key: .x495089a65b115670f2f2bd7c99 radio.1/wlan.1/add-wlan/wep-key: .x4b0706ccd5d0a8b98b0b4084f1
radio.1/wlan.1/add-wlan/wep-key-index: 1 radio.1/wlan.1/add-wlan/wep-key-index: 1
radio.1/wlan.1/add-wlan/wlan-capability: 17 radio.1/wlan.1/add-wlan/wlan-capability: 17
radio.1/wlan.1/add-wlan/wlan-id: 1 radio.1/wlan.1/add-wlan/wlan-id: 1
@ -280,7 +280,7 @@ radio.1/wlan.13/add-wlan/scan-defer-time: 100
radio.1/wlan.13/add-wlan/session-timout: 1800 radio.1/wlan.13/add-wlan/session-timout: 1800
radio.1/wlan.13/add-wlan/ssid: SuperSSID radio.1/wlan.13/add-wlan/ssid: SuperSSID
radio.1/wlan.13/add-wlan/wep-encryption: false radio.1/wlan.13/add-wlan/wep-encryption: false
radio.1/wlan.13/add-wlan/wep-key: .x495089a65b115670f2f2bd7c99 radio.1/wlan.13/add-wlan/wep-key: .x4b0706ccd5d0a8b98b0b4084f1
radio.1/wlan.13/add-wlan/wep-key-index: 1 radio.1/wlan.13/add-wlan/wep-key-index: 1
radio.1/wlan.13/add-wlan/wlan-capability: 1 radio.1/wlan.13/add-wlan/wlan-capability: 1
radio.1/wlan.13/add-wlan/wlan-id: 13 radio.1/wlan.13/add-wlan/wlan-id: 13