int ac_global_init() { // mod_set_actions_registered_cb(setup_actions); ac_config = mbag_create(); mbag_set_str(ac_config, CW_ITEM_AC_NAME, conf_acname); mbag_set_ptr(ac_config, CW_ITEM_AC_STATUS, &ac_status); ac_status.stations = 0; ac_status.limit = 1000; ac_status.active_wtps = 10; ac_status.max_wtps = 200; ac_status.security = CW_FLAG_AC_SECURITY_X | CW_FLAG_AC_SECURITY_S; ac_status.rmac_field = CW_FLAG_RMAC_SUPPORTED; ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C; // | CW_FLAG_DTLS_POLICY_D; mbag_set_bstrv(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0, bstr_data(conf_hardware_version), bstr_len(conf_hardware_version)); mbag_set_bstrv(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0, bstr_data(conf_software_version), bstr_len(conf_software_version)); mbag_set_str(ac_config,CW_ITEM_AC_IMAGE_DIR,conf_image_dir); // mbag_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist); mbag_set_fun(ac_config, CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST, get_iplist,release_iplist,(void*)771); return 1; }
int cw_in_cisco_image_identifier(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len,struct sockaddr *from) { if (len<a->min_len) { cw_dbg(DBG_ELEM_ERR,"Message element too short, %d < %d", len,a->min_len); return 0; } uint32_t vendor_id = cw_get_dword(data); int dstart; switch (vendor_id) { case CW_VENDOR_ID_ZYXEL: case CW_VENDOR_ID_CISCO: case CW_VENDOR_ID_FSF: case 0: dstart=4; len-=4; break; default: vendor_id=CW_VENDOR_ID_CISCO; dstart=0; } // mbag_set(conn->remote,a->item_id,a->itemtype,data+dstart,len); mbag_set_bstrv(conn->incomming,a->item_id,vendor_id,data+dstart,len); 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) { 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 image_update() { struct conn *conn = get_conn(); if (conn->capwap_state != CW_STATE_CONFIGURE) { cw_log(LOG_ERR, "Current state not image update"); return 0; } const char *ii = "/c1130"; mbag_set_bstrv(conn->outgoing, CW_ITEM_IMAGE_IDENTIFIER, CW_VENDOR_ID_CISCO, (uint8_t *) ii, strlen(ii)); int rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST); if (rc < 0) { } if (rc != 0) { cw_log(LOG_ERR, "AC rejected Image Data Request with code: %d - %s", rc, cw_strresult(rc)); return 0; } cw_dbg(DBG_INFO,"Ready to receive image ..."); conn->capwap_state=CW_STATE_IMAGE_DATA; rc=-11; while (conn->capwap_state == CW_STATE_IMAGE_DATA) { rc = cw_read_messages(conn); if (rc < 0) { if (errno != EAGAIN) break; } } printf("RC: %d %s\n",rc,strerror(errno)); 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; }