int cfg_json_put_radios(char *dst, const char *name, mbag_item_t * i, int n) { struct conn *conn = get_conn(); char *d = dst; memset(d, '\t', n); d += n; d += sprintf(d, "\"radios\":{\n"); MAVLITER_DEFINE(radios, conn->radios); const char *comma = ""; mavliter_foreach(&radios) { mbag_item_t *i = mavliter_get(&radios); // int rid = i->iid; //mbag_t radio = i->data; d += sprintf(d, "%s", comma); comma = ",\n"; memset(d, '\t', n + 1); d += n + 1; d += sprintf(d, "\"%d\":", i->iid); //d += mbag_tojson(d, i->data, radio_cfg, n + 1); } d += sprintf(d, "\n"); memset(d, '\t', n); d += n; d += sprintf(d, "}"); return d - dst; }
void props_to_sql(struct conn *conn, mbag_t mb, const char *mid) { // XXX for the now we use just the IP adress as ID char *wtp_id = sock_addr2str(&conn->addr); // cw_dbg(DBG_X, "WTPID: %s\n", wtp_id); MAVLITER_DEFINE(it, mb); mavliter_foreach(&it) { mbag_item_t *i = mavliter_get(&it); const struct cw_itemdef *cwi; if (!mid){ cwi = cw_itemdef_get(conn->actions->items, i->id, NULL); } else{ cwi = cw_itemdef_get(conn->actions->items, mid,i->id); } if (!cwi){ cw_dbg(DBG_WARN,"No definition for item %s found.",i->id); continue; } if (i->type==MBAG_MBAG){ if (mid){ cw_log(LOG_ERROR,"Depth for %s",i->id); continue; } props_to_sql(conn,i->data,i->id); continue; } DBGX("SQL ID %s,%s", i->id, cwi->id); DBGX("SQL Type %s,Typecwd %s", i->type->name, cwi->type->name); // printf("%s != %s ?\n",i->type->name,cwi->type->name); char str[256]; if (i->type->to_str) { i->type->to_str(i, str); db_put_wtp_prop(wtp_id, cwi->id, cwi->sub_id, str); } else { cw_log(LOG_ERR, "Can't converto to str for %s", cwi->id, cwi->sub_id); } } }
void radios_to_sql(struct conn *conn) { char *wtp_id = sock_addr2str(&conn->addr); MAVLITER_DEFINE(it, conn->radios); mavliter_foreach(&it) { struct mbag_item * i = mavliter_get(&it); int rid = i->iid; radio_to_sql(conn,wtp_id,rid,i->data); } }
int cw_out_radio_administrative_states(struct conn *conn, struct cw_action_out *a, uint8_t * dst) { int l=0; MAVLITER_DEFINE(it,conn->radios); mavliter_foreach(&it){ struct mbag_item *i = mavliter_get(&it); if ( i->type != MBAG_MBAG ) { continue; } l+=cw_put_elem_radio_administrative_state(dst+l,i->iid,i->data); } return l; }
/** * Update all radio operational states. * @param radios definitiion of radios * @param cause cause to set */ int cw_radio_update_oper_states(mbag_t radios,int cause) { MAVLITER_DEFINE(it,radios); mavliter_foreach(&it){ mbag_item_t * i = mavliter_get(&it); /* Get admin state of the radio, set disabled (2) if admin state is not defined */ int admin_state = mbag_get_byte(i->data,CW_RADIO_ADMIN_STATE,2); mbag_set_word(i->data,CW_RADIO_OPER_STATE,(admin_state<<8) | cause ); } return 1; }
static void update_radios(struct conn * conn, mbag_t result) { MAVLITER_DEFINE (it,conn->radios_upd); mavliter_foreach(&it){ struct mbag_item * item = mavliter_get(&it); int rid = item->iid; mbag_t radio = mbag_i_get_mbag(conn->radios,rid,NULL); if (!radio){ cw_dbg(DBG_ELEM_ERR,"Can't find radio with id %d",rid); continue; } mbag_t iresult = mbag_create(); mbag_i_set_mbag(result,rid,iresult); update_radio(conn,rid,item->data,radio,iresult); } }
void show_cfg (FILE *out, mavl_t ktv) { char value[500]; struct cw_KTV * data; mavliter_t it; const struct cw_Type * type; mavliter_init(&it,ktv); mavliter_foreach(&it){ data = mavliter_get(&it); type = data->type; type->to_str(data,value,0); fprintf(out,"%s :%s: %s\n",data->key,type->get_type_name(data), value); } }
void config_to_sql(struct conn *conn) { // XXX for the moment we use just the IP adress as ID char *wtp_id = sock_addr2str(&conn->addr); // cw_dbg(DBG_X, "WTPID: %s\n", wtp_id); MAVLITER_DEFINE(it, conn->incomming); mavliter_foreach(&it) { mbag_item_t *i = mavliter_get(&it); const struct cw_itemdef *cwi = cw_itemdef_get(conn->actions->items, i->id, NULL); cw_dbg(DBG_X,"ID GOT: %s",i->id); if (cwi) { DBGX("SQL ID %s,%s", i->id, cwi->id); DBGX("SQL Type %s,Typecwd %s", i->type->name, cwi->type->name); // printf("%s != %s ?\n",i->type->name,cwi->type->name); char str[256]; if (i->type->to_str) { i->type->to_str(i, str); db_put_wtp_prop(wtp_id, cwi->id, cwi->sub_id, str); } else { cw_log(LOG_ERR, "Can't converto to str for %s", cwi->id, cwi->sub_id); } } else { // DBGX("ID %d",i->id); } } }
void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio) { MAVLITER_DEFINE(it, radio); mavliter_foreach(&it) { mbag_item_t *i = mavliter_get(&it); const struct cw_itemdef *cwi = cw_itemdef_get(conn->actions->radioitems, i->id, NULL); if (cwi) { char str[4096]; if (i->type->to_str) { i->type->to_str(i, str); // printf("I would put RID: %d, %s=>%s\n",rid,cwi->id,str); char srid[6]; sprintf(srid,"%d",rid); db_put_radio_prop(wtp_id,srid,cwi->id,cwi->sub_id,str); // db_put_wtp_prop(wtp_id, cwi->id, cwi->sub_id, str); } else { cw_log(LOG_ERR, "Can't converto to str for %s", cwi->id, cwi->sub_id); } } else { // DBGX("ID %d",i->id); } } // int rid = ((struct mbag_item*)mavliter_get(&it))->iid; }
int handle_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from) { if (a->msg_id == CW_MSG_CONFIGURATION_UPDATE_REQUEST){ update =1; } return 0; MAVLITER_DEFINE(it, conn->incomming); mavliter_foreach(&it) { mbag_item_t *item = mavliter_get(&it); } cw_dbg(DBG_X,"Saving configuration ..."); cfg_to_json(); return 0; }
int cw_ktv_save(mavl_t ktvstore, const char * filename){ mavliter_t it; FILE * outfile; outfile = fopen(filename,"w"); if (outfile == NULL) return 0; mavliter_init(&it,ktvstore); mavliter_foreach(&it){ cw_KTV_t * val; char buf[4000]; val = mavliter_get(&it); val->type->to_str(val,buf,4000); write_str(outfile,val->key); fprintf(outfile," :%s: ",val->type->name); write_str(outfile,buf); fprintf(outfile,"\n"); } fclose(outfile); return 1; }
void conn_clear_upd(struct conn *conn, int merge) { if (merge){ mavl_merge(conn->config, conn->config_upd); MAVLITER_DEFINE (it,conn->radios_upd); mavliter_foreach(&it){ struct mbag_item * ruitem = mavliter_get(&it); mavl_t radio_upd = ruitem->data; mbag_t radio = mbag_i_get_mbag(conn->radios,ruitem->iid,NULL); if (radio){ mavl_merge(radio,radio_upd); } } } mavl_del_all(conn->config_upd); mavl_del_all(conn->radios_upd); }
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; }
int mbag_tojson(char *dst, mbag_t m, cw_itemdef_t *defs, int n) { char *d; d = dst; d += sprintf(d, "%s", "{\n"); MAVLITER_DEFINE(it, m); const char *delim = ""; mavliter_foreach(&it) { mbag_item_t *i = mavliter_get(&it); d += sprintf(d, "%s", delim); delim = ",\n"; // memset(d,'\t',n+1); d+=n+1; d+=sprintf(d,"\"%s\":",i->id); // d+=sprintf(d,"\"%s(%s)\":",i->id,i->type->name); if (i->type==MBAG_MBAG){ d+=mbag_tojson(d,i->data,defs,n+1); } else{ d+=sprintf(d,"\""); if (i->type->to_str){ d+=i->type->to_str(i,d); } d+=sprintf(d,"\""); } } if (n==0){ struct conn * conn; conn = get_conn(); MAVLITER_DEFINE(ir,conn->radios); memset(d, '\t', n); d += n; d += sprintf(d, "%s", delim); d+=sprintf(d,"\t\"radios\":{\n"); char *delim=""; mavliter_foreach(&ir){ memset(d, '\t', n); d += n; d += sprintf(d, "%s", delim); delim = ",\n"; mbag_item_t *radio = mavliter_get(&ir); d+=sprintf(d,"\t\t\"%d\":",radio->iid); d+=mbag_tojson(d,radio->data,defs,n+2); } d += sprintf(d, "\n\t}"); } d += sprintf(d, "\n"); memset(d, '\t', n); d += n; d += sprintf(d, "%s", "}"); return d - dst; }