static void wtpman_remove(struct wtpman *wtpman) { wtplist_lock(); wtplist_remove(wtpman); wtplist_unlock(); wtpman_destroy(wtpman); }
void process_cw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, int len) { int sock = socklist[index].reply_sockfd; char hdrstr[1024]; hdr_print(hdrstr,buffer,len); cw_log_debug2("Header for packet from %s\n%s",sock_addr2str(addr),hdrstr); /* first of all check preamble */ int preamble = CWTH_GET_PREAMBLE(buffer); #ifdef WITH_DTLS if (preamble != CAPWAP_PACKET_PREAMBLE && preamble != CAPWAP_DTLS_PACKET_PREAMBLE){ #else if (preamble != CAPWAP_PACKET_PREAMBLE ){ #endif cw_log_debug1("Discarding packet, wrong preamble, preamble = 0x%01X",preamble); return; } wtplist_lock(); struct wtpman * wtpman = wtplist_get(addr); if (!wtpman){ wtpman = wtpman_create(index,addr); if (!wtpman ){ cw_log(LOG_ERR,"Error creating wtpman: %s",strerror(errno)); wtplist_unlock(); return; } if (!wtplist_add(wtpman)){ cw_log(LOG_ERR,"Error adding wtpman: Too many wtp connections"); wtpman_destroy(wtpman); wtplist_unlock(); return; }; wtpman_start(wtpman,preamble & 0xf); } wtpman_addpacket(wtpman,buffer,len); wtplist_unlock(); } void process_lw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, int len) { int sock = socklist[index].reply_sockfd; uint8_t * m = buffer+6; uint32_t val = ntohl(*((uint32_t*)(m))); printf ("VAL: %08X\n",val); /* first of all check preamble */ int version = LWTH_GET_VERSION(m); if (version != LW_VERSION){ cw_log_debug1("Discarding LWAPP packet, wrong verson"); return; } int l = LWTH_GET_LENGTH(m); printf ("LEN = %d\n",l); if (l+12 != len){ cw_log_debug1("Discarding LWAPP packet, wrong length"); return; } wtplist_lock(); struct wtpman * wtpman = wtplist_get(addr); if (!wtpman){ wtpman = wtpman_create(index,addr); if (!wtpman ){ cw_log(LOG_ERR,"Error creating wtpman: %s",strerror(errno)); wtplist_unlock(); return; } if (!wtplist_add(wtpman)){ cw_log(LOG_ERR,"Error adding wtpman: Too many wtp connections"); wtpman_destroy(wtpman); wtplist_unlock(); return; }; wtpman_lw_start(wtpman); } wtpman_lw_addpacket(wtpman,buffer,len); wtplist_unlock(); }
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr, int dtlsmode) { struct sockaddr dbgaddr; socklen_t dbgaddrl; int sockfd, replyfd; char sock_buf[SOCK_ADDR_BUFSIZE]; struct wtpman *wtpman; wtpman = malloc(sizeof(struct wtpman)); if (!wtpman) return 0; memset(wtpman, 0, sizeof(struct wtpman)); if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) { int port = sock_getport(&socklist[socklistindex].addr); replyfd = socklist_find_reply_socket(srcaddr, port); if (replyfd == -1) { cw_log(LOG_ERR, "Can't find reply socket for request from %s", sock_addr2str(srcaddr,sock_buf)); free(wtpman); return NULL; } } else { replyfd = socklist[socklistindex].sockfd; } sockfd = replyfd; /*//socklist[socklistindex].reply_sockfd;*/ dbgaddrl = sizeof(dbgaddr); getsockname(sockfd, &dbgaddr, &dbgaddrl); cw_dbg(DBG_INFO, "Creating wtpman on socket %d, %s:%d", sockfd, sock_addr2str(&dbgaddr,sock_buf), sock_getport(&dbgaddr)); wtpman->conn = conn_create(sockfd, srcaddr, 100); wtpman->conn->role = CW_ROLE_AC; wtpman->conn->data_sock = socklist[socklistindex].data_sockfd; sock_copyaddr(&wtpman->conn->data_addr, (struct sockaddr *) &wtpman->conn->addr); if (!wtpman->conn) { wtpman_destroy(wtpman); return NULL; } wtpman->conn->mods = conf_mods; wtpman->conn->strict_capwap = conf_strict_capwap; wtpman->conn->strict_hdr = conf_strict_headers; /* // wtpman->conn->radios = mbag_i_create(); // wtpman->conn->radios_upd = mbag_i_create(); // wtpman->conn->local = ac_config; //wtpman->conn->capwap_mode=0; //CW_MODE_STD; //CISCO; // wtpman->conn->capwap_mode = CW_MODE_CISCO; //wtpman->conn->strict_capwap_hdr=0; */ wtpman->conn->local_cfg = cw_ktv_create(); wtpman->conn->global_cfg = actube_global_cfg; wtpman->conn->local_cfg = actube_global_cfg; /* when created caused by a packet in DTLS mode, we try * to find out the modules to load, for detected connection * from discovery request */ if (dtlsmode){ int rc; struct cw_Mod *cmod, *bmod; rc = discovery_cache_get(discovery_cache,srcaddr,&cmod,&bmod); if (rc){ cw_dbg(DBG_INFO, "Initializing with mod %s %s",cmod->name,bmod->name); wtpman->conn->msgset = cw_mod_get_msg_set(wtpman->conn,cmod,bmod); wtpman->conn->detected=1; cmod->setup_cfg(wtpman->conn); } } return wtpman; }
struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr) { struct wtpman *wtpman; wtpman = malloc(sizeof(struct wtpman)); if (!wtpman) return 0; memset(wtpman, 0, sizeof(struct wtpman)); int replyfd; if (socklist[socklistindex].type != SOCKLIST_UNICAST_SOCKET) { int port = sock_getport(&socklist[socklistindex].addr); replyfd = socklist_find_reply_socket(srcaddr, port); if (replyfd == -1) { cw_log(LOG_ERR, "Can't find reply socket for request from %s", sock_addr2str(srcaddr)); free(wtpman); return NULL; } } else { replyfd = socklist[socklistindex].sockfd; } int sockfd = replyfd; //socklist[socklistindex].reply_sockfd; struct sockaddr dbgaddr; socklen_t dbgaddrl = sizeof(dbgaddr); getsockname(sockfd, &dbgaddr, &dbgaddrl); cw_dbg(DBG_INFO, "Creating wtpman on socket %d, %s:%d", sockfd, sock_addr2str(&dbgaddr), sock_getport(&dbgaddr)); //extern int conn_process_packet2(struct conn *conn, uint8_t * packet, int len, // struct sockaddr *from); wtpman->conn = conn_create(sockfd, srcaddr, 100); wtpman->conn->data_sock = socklist[socklistindex].data_sockfd; sock_copyaddr(&wtpman->conn->data_addr, (struct sockaddr *) &wtpman->conn->addr); // wtpman->conn->process_packet = conn_process_packet2; if (!wtpman->conn) { wtpman_destroy(wtpman); return NULL; } wtpman->conn->mods = conf_mods; wtpman->conn->strict_capwap = conf_strict_capwap; wtpman->conn->strict_hdr = conf_strict_headers; wtpman->conn->radios = mbag_i_create(); wtpman->conn->radios_upd = mbag_i_create(); wtpman->conn->local = ac_config; //wtpman->conn->capwap_mode=0; //CW_MODE_STD; //CISCO; wtpman->conn->capwap_mode = CW_MODE_CISCO; //wtpman->conn->strict_capwap_hdr=0; return wtpman; }