/** * Reads CAPWAP DTLS data from a connection object. * @param conn conn object * @param out where to write data to * @param maxlen maximum number of bytes to read * @return the number of bytes read */ int dtls_bio_read(struct conn *conn, char *out, int maxlen) { if (conn->dtls_buffer_len == 0) { int len = conn->recv_packet(conn, conn->dtls_buffer, 2048); if (len < 4) return 0; conn->dtls_buffer_len = len - 4; conn->dtls_buffer_pos = 4; } if (conn->dtls_buffer_len > maxlen) { memcpy(out, conn->dtls_buffer + conn->dtls_buffer_pos, maxlen); conn->dtls_buffer_len -= maxlen; conn->dtls_buffer_pos += maxlen; cw_dbg(DBG_DTLS_BIO, "SSL BIO read: (maxlen = %d), read %d, remain %d", maxlen, maxlen, conn->dtls_buffer_len); cw_dbg_dmp(DBG_DTLS_BIO_DMP, (uint8_t *) out, maxlen, "Dump..."); return maxlen; } memcpy(out, conn->dtls_buffer + conn->dtls_buffer_pos, conn->dtls_buffer_len); int ret = conn->dtls_buffer_len; conn->dtls_buffer_len = 0; cw_dbg(DBG_DTLS_BIO, "SSL BIO read: (maxlen = %d), read %d, remain %d", maxlen, ret, conn->dtls_buffer_len); cw_dbg_dmp(DBG_DTLS_BIO_DMP, (uint8_t *) out, ret, "Dump..."); return ret; }
static int process_elem(void *w,int type,uint8_t* msgelem,int len) { struct wtpinfo * wtpinfo = (struct wtpinfo*)w; cw_dbg(DBG_CW_MSGELEM,"Process conf status req msgelem, type=%d (%s), len=%d",type,cw_msgelemtostr(type),len); cw_dbg_dmp(DBG_CW_MSGELEM_DMP,msgelem,len,"Dump for msgelem ..."); if (wtpinfo_readelem_ac_name(wtpinfo,type,msgelem,len)) return 1; if (cw_readelem_wtp_reboot_statistics(&wtpinfo->reboot_statistics,type,msgelem,len)) return 1; /* if (wtpinfo_readelem_location_data(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_board_data(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_descriptor(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_name(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_session_id(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_frame_tunnel_mode(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_mac_type(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_wtp_radio_info(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_ecn_support(wtpinfo,type,msgelem,len)) return 1; if (wtpinfo_readelem_cw_local_ip_addr(wtpinfo,type,msgelem,len)) return 1; */ return 0; }
/** * Write DTLS data to a CAPWAP connection. * @param conn the connection * @param data data to write * @param len number of bytes to write * @return the number of bytes written */ int dtls_bio_write(struct conn *conn, const char *data, int len) { uint8_t buffer[2048]; *((uint32_t *) buffer) = htonl(1 << 24); memcpy(buffer + 4, data, len); int rc = conn->send_packet(conn, buffer, len + 4); if (rc>=0) rc-=4; cw_dbg(DBG_DTLS_BIO, "SSL BIO write: %d bytes, wrote=%d, ptr: %p", len, rc, data); cw_dbg_dmp(DBG_DTLS_BIO_DMP, (uint8_t *) data, len, "Dump ..."); if (rc < 0) return rc; return rc ; }
static void readsubelems_wtp_board_data(mbag_t itemstore, uint8_t * msgelem, int len) { if (len<4) return; int i = 0; // uint32_t val; do { // val = ntohl(*((uint32_t *) (msgelem + i))); // int subtype = (val >> 16) & 0xffff; // int sublen = val & 0xffff; // int subtype = cw_get_word(msgelem+i); int sublen = cw_get_word(msgelem+i+2); i += 4; if (sublen + i > len) { cw_dbg(DBG_ELEM_ERR, "WTP Board data sub-element too long, type=%d,len=%d", subtype, sublen); return; } cw_dbg(DBG_SUBELEM, "board data sub-element, type=%d (%s), len=%d", subtype, cw_strboardelem(subtype),sublen); cw_dbg_dmp(DBG_SUBELEM,msgelem+i,sublen,"Dump..."); switch (subtype) { case CW_BOARDDATA_MODELNO: mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MODELNO, msgelem + i, sublen); break; case CW_BOARDDATA_SERIALNO: mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_SERIALNO, msgelem + i, sublen); break; case CW_BOARDDATA_MACADDRESS: mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MACADDRESS, msgelem + i, sublen); break; case CW_BOARDDATA_BOARDID: mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID, msgelem + i, sublen); break; case CW_BOARDDATA_REVISION: mbag_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_REVISION, msgelem + i, sublen); default: break; } i += sublen; } while (i < len); }