static int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, int silent) { mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1)); /* Get number of encryption elements */ int ncrypt = cw_get_byte(data + 2); if (ncrypt == 0) { if (conn->strict_capwap) { if (!silent) cw_dbg(DBG_ELEM_ERR, "Bad WTP Descriptor, number of encryption elements is 0."); return 0; } if (!silent) cw_dbg(DBG_RFC, "Non standard conform WTP Descriptor, number of encryptoin elements is 0."); } int pos = 3; int i; for (i = 0; i < ncrypt; i++) { // It's a dummy for now pos += 3; } return cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); }
int cw_in_cisco_add_wlan(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from) { int rid = cw_get_byte(data); mbag_t wlan = mbag_i_get_mbag(conn->radios,rid,NULL); if ( !wlan ) { printf("No Radio git\n"); } mbag_set_byte(wlan,"radio_id",rid); int mytype=mbag_get_byte(conn->config,CW_ITEM_AP_MODE_AND_TYPE,77) & 0xff; printf("My type: %d\n",mytype); exit(0); cw_cisco_get_wlan_legacy(wlan,data,len); return 0; }
static int cw_read_cisco_wtp_descriptor(mbag_t mbag, struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, int silent) { mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data)); mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE, cw_get_byte(data + 1)); int pos = 2; /* Encryption element, for now dumy XXX */ cw_get_word(data + pos + 2); pos += 2; return cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent); }
int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from) { if (a->itemtype == MBAG_BYTE) { mbag_set_byte(itemstore, a->item_id, *data); return 1; } if (a->itemtype == MBAG_WORD) { mbag_set_word(itemstore, a->item_id, cw_get_word(data)); return 1; } if (a->itemtype == MBAG_DWORD) { mbag_set_dword(itemstore, a->item_id, cw_get_dword(data)); return 1; } if (a->itemtype == MBAG_STR) { mbag_set_strn(itemstore, a->item_id, (char *) data, len); return 1; } if (a->itemtype == MBAG_BSTR) { mbag_set_bstrn(itemstore, a->item_id, data, len); return 1; } if (a->itemtype == MBAG_BSTR16) { mbag_set_bstr16n(itemstore, a->item_id, data, len); return 1; } /* if (a->itemtype == MBAG_DATA) { mbag_set_data(itemstore, a->item_id, data, len); return 1; } */ if (a->itemtype == MBAG_VENDORSTR) { mbag_set_bstrv(itemstore, a->item_id, cw_get_dword(data), data + 4, len - 4); return 1; } cw_log(LOG_ERR, "Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.", a->itemtype, a->msg_id, cw_strmsg(a->msg_id), a->elem_id); return 0; }
int cw_radio_set_admin_state(mbag_t radios,int rid, int state, int cause) { mbag_t radio = mbag_i_get_mbag(radios,rid,NULL); if (!radio) { cw_dbg(DBG_ELEM_ERR,"Can't set radio administrative state for radio %d - radio does't exists",rid); return 0; } mbag_set_byte(radio,CW_RADIO_ADMIN_STATE,state); if (cause < 0) return 1; /* Set operational state for next config update response. */ mbag_set_word(radio,CW_RADIO_OPER_STATE, (state<<8) | 3); return 1; }
void update_reboot_stats(struct conn * conn, int cause) { mbag_t rs = mbag_get_mbag(conn->config,CW_ITEM_WTP_REBOOT_STATISTICS,NULL); switch (cause){ case CW_REBOOT_TYPE_NOT_SUPPORTED: break; case CW_REBOOT_TYPE_AC_INITIATED: mbag_inc_word(rs,CW_ITEM_REBOOT_AC_INITIATED_COUNT,1); break; case CW_REBOOT_TYPE_OTHER_FAILURE: mbag_inc_word(rs,CW_ITEM_REBOOT_OTHER_FAILURE_COUNT,1); break; } mbag_inc_word(rs,CW_ITEM_REBOOT_COUNT,1); mbag_set_byte(rs,CW_ITEM_REBOOT_LAST_FAILURE_TYPE,cause); cfg_to_json(); }
int cw_cisco_get_wlan_(mbag_t wlan, uint8_t *data, int len) { mbag_set_word(wlan,"enc_capab", cw_get_word(data+1)); int wlan_id=cw_get_word(data+3); mbag_set_word(wlan,"wlan_id",wlan_id); mbag_set_dword(wlan,"enc_policy",cw_get_dword(data+5)); mbag_set_bstr16n(wlan,"key",data+9,32); mbag_set_byte(wlan,"key_index",cw_get_byte(data+41)); mbag_set_byte(wlan,"key_shared",cw_get_byte(data+42)); mbag_set_byte(wlan,"wpa_len",cw_get_byte(data+43)); mbag_set_bstr16n(wlan,"wpa_data",data+44,32); mbag_set_byte(wlan,"rsn_len",cw_get_byte(data+76)); mbag_set_bstr16n(wlan,"rsn_data",data+77,64); mbag_set_bstr16n(wlan,"reserved",data+141,49); mbag_set_byte(wlan,"wme_len",cw_get_byte(data+190)); mbag_set_bstr16n(wlan,"wme_data",data+191,32); mbag_set_byte(wlan,"dot11e_len",cw_get_byte(data+223)); mbag_set_bstr16n(wlan,"dot11e_data",data+224,32); mbag_set_byte(wlan,"qos",cw_get_byte(data+256)); // mbag_set_byte(wlan,"ssid_broadcast",cw_get_byte(data+257)); mbag_set_byte(wlan,"ssid_broadcast",cw_get_byte(data+435)); mbag_set_byte(wlan,"aironet_ie",cw_get_byte(data+436)); mbag_set_bstr16n(wlan,"reserved2",data+258,40); mbag_set_byte(wlan,"dtim_period",cw_get_byte(data+554)); mbag_set_bstr16n(wlan,"wlan_name",data+558,32); mbag_set_byte(wlan,"allow_aaa_override",cw_get_byte(data+591)); mbag_set_byte(wlan,"max_clients",cw_get_byte(data+593)); mbag_set_bstr16n(wlan,"ssid",data+622,len-622); return 0; }
static int run_discovery(struct conn *conn) { // conn->incomming = mbag_create(); conn->capwap_state = CW_STATE_DISCOVERY; mbag_set_byte(conn->outgoing, CW_ITEM_DISCOVERY_TYPE, CW_DISCOVERY_TYPE_UNKNOWN); cw_init_request(conn, CW_MSG_DISCOVERY_REQUEST); cw_put_msg(conn, conn->req_buffer); conn_send_msg(conn, conn->req_buffer); time_t timer = cw_timer_start(0); while (!cw_timer_timeout(timer) && conn->capwap_state == CW_STATE_DISCOVERY) { mavl_del_all(conn->incomming); int rc = cw_read_from(conn); if (rc<0) { if (errno==EAGAIN) continue; cw_log(LOG_ERROR,"Error reading messages: %s",strerror(errno)); break; } } mbag_t discs; discs = mbag_get_mavl(conn->remote, CW_ITEM_DISCOVERIES); if (!discs) { cw_log(LOG_ERR,"No discovery responses received"); return 0; } int i; cw_aciplist_t list = cw_select_ac(conn, discs); DEFINE_AVLITER(ii,list); avliter_foreach(&ii){ cw_acip_t * ip = avliter_get(&ii); } mavl_del_all(conn->remote); mbag_set_mavl(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list); return 1; }
int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from) { const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE); if (!idef) { cw_log(LOG_ERR,"No itemdef found for %s",a->item_id); return 0; } if (idef->type == MBAG_BYTE) { mbag_set_byte(itemstore, a->item_id, *data); return 1; } if (idef->type == MBAG_WORD) { mbag_set_word(itemstore, a->item_id, cw_get_word(data)); return 1; } if (idef->type == MBAG_DWORD) { mbag_set_dword(itemstore, a->item_id, cw_get_dword(data)); return 1; } if (idef->type == MBAG_STR) { mbag_set_strn(itemstore, a->item_id, (char *) data, len); return 1; } if (idef->type == MBAG_BSTR) { mbag_set_bstrn(itemstore, a->item_id, data, len); return 1; } if (idef->type == MBAG_BSTR16) { mbag_set_bstr16n(itemstore, a->item_id, data, len); return 1; } /* if (idef->type == MBAG_DATA) { mbag_set_data(itemstore, a->item_id, data, len); return 1; } */ if (idef->type == MBAG_VENDORSTR) { mbag_set_bstrv(itemstore, a->item_id, cw_get_dword(data), data + 4, len - 4); return 1; } // printf("Idef: %s\n",idef->type->name); cw_log(LOG_ERR, "Can't handle item type %d in definition for incomming msg %d (%s) - %d, cw_in_generic.", idef->type, a->msg_id, cw_strmsg(a->msg_id), a->elem_id); return 0; }
int main() { signal (SIGINT, sig_handler); wtpconf_preinit(); if (!read_config("./wtp_uci.conf")) { return 1; } // cw_dbg_opt_level = conf_dbg_level; if (!wtpconf_init()){ return 1; }; cw_dbg_opt_display = DBG_DISP_ASC_DMP | DBG_DISP_COLORS; dtls_init(); the_conn = conn_create_noq(-1, NULL); struct conn *conn = the_conn; conn->radios = mbag_i_create(); conn->radios_upd=mbag_i_create(); mbag_i_set_mbag(conn->radios,0,mbag_create()); mbag_i_set_mbag(conn->radios_upd,0,mbag_create()); #define CWMOD "cisco" #define CWBIND "cisco" //#define CWMOD "capwap" //#define CWBIND "capwap80211" struct mod_wtp *mod = modload_wtp(CWMOD); if (!mod) { printf("Can't load mod capwap\n"); exit(0); } mod->init(); mod->register_actions(&capwap_actions,MOD_MODE_CAPWAP); mod = modload_wtp(CWBIND); if (!mod) { printf("Can't load mod capwap80211\n"); exit(0); } int rc = mod->register_actions(&capwap_actions,MOD_MODE_BINDINGS); conn->detected = 1; conn->dtls_verify_peer=0; conn->dtls_mtu = 12000; conn->actions = &capwap_actions; conn->outgoing = mbag_create(); conn->incomming = mbag_create(); conn->local = mbag_create(); conn->config = mbag_create(); the_conn->strict_capwap = 0; cfg_from_json(conn); setup_conf(conn); mbag_t r; // r = mbag_i_get_mbag(conn->radios,0,NULL); r = conn->radios; MAVLITER_DEFINE(it,r); mavliter_foreach(&it){ struct mbag_item *i=mavliter_get(&it); printf("RID = %d\n",i->iid); printf("DATA: %p\n",i->data); mbag_t radio= (mbag_t)i->data; struct mbag_item *mri = mbag_get(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION); if (!mri){ printf("Setting to 8 %p %p\n",mri,r); mbag_set_dword(radio,CW_RADIOITEM80211_WTP_RADIO_INFORMATION,1); } else{ printf("MRI %p\n",mri); } } mod_init_config(mod,conn->config); cfg_to_json(); mbag_t mb = mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA, NULL); printf("mbag %p\n", mb); cw_acpriolist_t acprios = cw_acpriolist_create(); cw_acpriolist_set(acprios, "Master AC", strlen("Master AC"), 1); cw_acpriolist_set(acprios, "AC8new", strlen("AC8new"), 12); mbag_set_byte(conn->local, CW_ITEM_WTP_MAC_TYPE, CW_WTP_MAC_TYPE_SPLIT); mbag_set_byte(conn->local, CW_ITEM_WTP_FRAME_TUNNEL_MODE, CW_WTP_FRAME_TUNNEL_MODE_E); conn->wbid=1; // cw_set_msg_end_callback(conn->actions,CW_STATE_RUN,CW_MSG_CONFIGURATION_UPDATE_REQUEST,handle_update_req); if (!discovery()) return -1; if (!join()) return -1; if (!configure()) return -1; cw_dbg(DBG_X,"Saveing config 0"); cfg_to_json(); changestate(); run(); //image_update(); return 0; }