static int ac_session_action_addwlan(struct ac_session_t* session, struct ac_notify_addwlan_t* notify) { struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_80211_addwlan_element addwlan; ASSERT(session->requestfragmentpacket->count == 0); /* Check if WLAN id is valid and not used */ if (!IS_VALID_RADIOID(notify->radioid) || !IS_VALID_WLANID(notify->wlanid)) { return AC_NO_ERROR; } else if (ac_wlans_get_bssid_with_wlanid(session, notify->radioid, notify->wlanid)) { return AC_NO_ERROR; } /* */ memset(&addwlan, 0, sizeof(struct capwap_80211_addwlan_element)); addwlan.radioid = notify->radioid; addwlan.wlanid = notify->wlanid; addwlan.capability = notify->capability; addwlan.qos = notify->qos; addwlan.authmode = notify->authmode; addwlan.macmode = notify->macmode; addwlan.tunnelmode = notify->tunnelmode; addwlan.suppressssid = notify->suppressssid; addwlan.ssid = (uint8_t*)notify->ssid; /* Build packet */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, session->binding); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_IEEE80211_WLAN_CONFIGURATION_REQUEST, session->localseqnumber, session->mtu); /* Add message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_ADD_WLAN, &addwlan); /* CAPWAP_ELEMENT_80211_IE */ /* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */ /* WLAN Configuration Request complete, get fragment packets */ capwap_packet_txmng_get_fragment_packets(txmngpacket, session->requestfragmentpacket, session->fragmentid); if (session->requestfragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send WLAN Configuration Request to WTP */ if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->requestfragmentpacket)) { session->retransmitcount = 0; capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL); } else { capwap_logging_debug("Warning: error to send WLAN Configuration Request packet"); ac_free_reference_last_request(session); ac_session_teardown(session); } return AC_NO_ERROR; }
static int ac_session_action_station_configuration_ieee8011_delete_station(struct ac_session_t* session, struct ac_notify_station_configuration_ieee8011_delete_station* notify) { struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_deletestation_element deletestation; ASSERT(session->requestfragmentpacket->count == 0); /* Check if RADIO id is valid */ if (!IS_VALID_RADIOID(notify->radioid)) { return AC_NO_ERROR; } /* */ memset(&deletestation, 0, sizeof(struct capwap_deletestation_element)); deletestation.radioid = notify->radioid; deletestation.length = MACADDRESS_EUI48_LENGTH; deletestation.address = notify->address; /* Build packet */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, session->binding); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_STATION_CONFIGURATION_REQUEST, session->localseqnumber, session->mtu); /* Add message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_DELETESTATION, &deletestation); /* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */ /* Station Configuration Request complete, get fragment packets */ capwap_packet_txmng_get_fragment_packets(txmngpacket, session->requestfragmentpacket, session->fragmentid); if (session->requestfragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send Station Configuration Request to WTP */ if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->requestfragmentpacket)) { session->retransmitcount = 0; capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL); } else { capwap_logging_debug("Warning: error to send Station Configuration Request packet"); ac_free_reference_last_request(session); ac_session_teardown(session); } return AC_NO_ERROR; }
static int ac_session_action_resetwtp(struct ac_session_t* session, struct ac_notify_reset_t* reset) { struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_imageidentifier_element imageidentifier; ASSERT(session->requestfragmentpacket->count == 0); /* */ imageidentifier.vendor = reset->vendor; imageidentifier.name = reset->name; /* Build packet */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, session->binding); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_RESET_REQUEST, session->localseqnumber, session->mtu); /* Add message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_IMAGEIDENTIFIER, &imageidentifier); /* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */ /* Reset request complete, get fragment packets */ capwap_packet_txmng_get_fragment_packets(txmngpacket, session->requestfragmentpacket, session->fragmentid); if (session->requestfragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send Reset Request to WTP */ if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->requestfragmentpacket)) { session->retransmitcount = 0; ac_dfa_change_state(session, CAPWAP_RESET_STATE); capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL); } else { capwap_logging_debug("Warning: error to send Reset Request packet"); ac_free_reference_last_request(session); ac_session_teardown(session); } return AC_NO_ERROR; }
static void ac_send_invalid_request(struct ac_session_t* session, uint32_t errorcode) { struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_list* responsefragmentpacket; struct capwap_fragment_packet_item* packet; struct capwap_header* header; struct capwap_resultcode_element resultcode = { .code = errorcode }; ASSERT(session != NULL); ASSERT(session->rxmngpacket != NULL); ASSERT(session->rxmngpacket->fragmentlist->first != NULL); /* */ packet = (struct capwap_fragment_packet_item*)session->rxmngpacket->fragmentlist->first->item; header = (struct capwap_header*)packet->buffer; /* Odd message type */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, GET_WBID_HEADER(header)); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, session->rxmngpacket->ctrlmsg.type + 1, session->rxmngpacket->ctrlmsg.seq, session->mtu); /* Add message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode); /* Unknown response complete, get fragment packets */ responsefragmentpacket = capwap_list_create(); capwap_packet_txmng_get_fragment_packets(txmngpacket, responsefragmentpacket, session->fragmentid); if (responsefragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send unknown response */ capwap_crypt_sendto_fragmentpacket(&session->dtls, responsefragmentpacket); /* Don't buffering a packets sent */ capwap_list_free(responsefragmentpacket); }
static int ac_session_action_authorizestation_response(struct ac_session_t* session, struct ac_soap_response* response, struct ac_notify_station_configuration_ieee8011_add_station* notify) { int result = -1; int ifindex = -1; uint16_t vlan = 0; struct ac_if_datachannel* datachannel; struct ac_wlan* wlan; struct json_object* jsonroot; struct json_object* jsonsection; struct json_object* jsonelement; struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_addstation_element addstation; struct capwap_80211_station_element station; /* Receive SOAP response with JSON result { DataChannelInterface: { Index: [int], VLAN: [int/string] }, } */ /* */ jsonroot = ac_soapclient_parse_json_response(response); if (!jsonroot) { return -1; } /* */ jsonsection = compat_json_object_object_get(jsonroot, "DataChannelInterface"); if (jsonsection && (json_object_get_type(jsonsection) == json_type_object)) { jsonelement = compat_json_object_object_get(jsonsection, "Index"); if (jsonelement && (json_object_get_type(jsonelement) == json_type_int)) { unsigned long index = (unsigned long)json_object_get_int(jsonelement); /* Retrieve interface index */ capwap_rwlock_rdlock(&g_ac.ifdatachannellock); datachannel = (struct ac_if_datachannel*)capwap_hash_search(g_ac.ifdatachannel, &index); if (datachannel) { ifindex = datachannel->ifindex; } capwap_rwlock_unlock(&g_ac.ifdatachannellock); /* Prepare request */ if (ifindex >= 0) { wlan = ac_wlans_get_bssid_with_wlanid(session, notify->radioid, notify->wlanid); if (wlan) { memset(&addstation, 0, sizeof(struct capwap_addstation_element)); addstation.radioid = notify->radioid; addstation.length = MACADDRESS_EUI48_LENGTH; addstation.address = notify->address; if (wlan->tunnelmode == CAPWAP_ADD_WLAN_TUNNELMODE_LOCAL) { jsonelement = compat_json_object_object_get(jsonsection, "VLAN"); if (jsonelement && (json_object_get_type(jsonelement) == json_type_string)) { const char* wtpvlan = json_object_get_string(jsonelement); if (wtpvlan && (strlen(wtpvlan) < CAPWAP_ADDSTATION_VLAN_MAX_LENGTH)) { addstation.vlan = (uint8_t*)wtpvlan; /* Free with jsonroot */ } } } /* */ memset(&station, 0, sizeof(struct capwap_80211_station_element)); station.radioid = notify->radioid; station.associationid = notify->associationid; memcpy(station.address, notify->address, MACADDRESS_EUI48_LENGTH); station.capabilities = notify->capabilities; station.wlanid = notify->wlanid; station.supportedratescount = notify->supportedratescount; memcpy(station.supportedrates, notify->supportedrates, station.supportedratescount); /* Build packet */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, session->binding); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_STATION_CONFIGURATION_REQUEST, session->localseqnumber, session->mtu); /* Add message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_ADDSTATION, &addstation); capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_80211_STATION, &station); /* CAPWAP_ELEMENT_VENDORPAYLOAD */ /* TODO */ /* Station Configuration Request complete, get fragment packets */ capwap_packet_txmng_get_fragment_packets(txmngpacket, session->requestfragmentpacket, session->fragmentid); if (session->requestfragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send Station Configuration Request to WTP */ if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->requestfragmentpacket)) { /* Retrive VLAN */ if (wlan->tunnelmode != CAPWAP_ADD_WLAN_TUNNELMODE_LOCAL) { jsonelement = compat_json_object_object_get(jsonroot, "DataChannelInterface.VLAN"); if (jsonelement && (json_object_get_type(jsonelement) == json_type_int)) { int acvlan = json_object_get_int(jsonelement); if ((acvlan > 0) && (acvlan < VLAN_MAX)) { vlan = (uint16_t)acvlan; } } } /* Authorize station also into kernel module */ if (!ac_kmod_authorize_station(&session->sessionid, addstation.address, ifindex, notify->radioid, notify->wlanid, vlan)) { result = 0; session->retransmitcount = 0; capwap_timeout_set(session->timeout, session->idtimercontrol, AC_RETRANSMIT_INTERVAL, ac_dfa_retransmition_timeout, session, NULL); } else { capwap_logging_warning("Unable to authorize station into kernel module data channel"); ac_free_reference_last_request(session); ac_session_teardown(session); } } else { capwap_logging_debug("Warning: error to send Station Configuration Request packet"); ac_free_reference_last_request(session); ac_session_teardown(session); } } } } } /* */ json_object_put(jsonroot); return result; }
static void ac_discovery_run(void) { int sizedata; struct capwap_list_item* itempacket; struct ac_discovery_packet* acpacket; struct capwap_parsed_packet packet; struct capwap_packet_rxmng* rxmngpacket; while (!g_ac_discovery.endthread) { /* Get packet */ capwap_lock_enter(&g_ac_discovery.packetslock); itempacket = NULL; if (g_ac_discovery.packets->count > 0) { itempacket = capwap_itemlist_remove_head(g_ac_discovery.packets); } capwap_lock_exit(&g_ac_discovery.packetslock); if (!itempacket) { /* Wait packet with timeout*/ if (!capwap_event_wait_timeout(&g_ac_discovery.waitpacket, AC_DISCOVERY_CLEANUP_TIMEOUT)) { ac_discovery_cleanup(); } continue; } /* */ acpacket = (struct ac_discovery_packet*)itempacket->item; sizedata = itempacket->itemsize - sizeof(struct ac_discovery_packet); /* Accept only discovery request don't fragment */ rxmngpacket = capwap_packet_rxmng_create_message(); if (capwap_packet_rxmng_add_recv_packet(rxmngpacket, acpacket->data, sizedata) == CAPWAP_RECEIVE_COMPLETE_PACKET) { /* Validate message */ if (capwap_check_message_type(rxmngpacket) == VALID_MESSAGE_TYPE) { /* Parsing packet */ if (capwap_parsing_packet(rxmngpacket, &packet) == PARSING_COMPLETE) { /* Validate packet */ if (!capwap_validate_parsed_packet(&packet, NULL)) { struct capwap_packet_txmng* txmngpacket; /* */ capwap_logging_debug("Receive discovery request packet"); /* Creare discovery response */ txmngpacket = ac_create_discovery_response(&packet); if (txmngpacket) { struct capwap_list* responsefragmentpacket; /* Discovery response complete, get fragment packets */ responsefragmentpacket = capwap_list_create(); capwap_packet_txmng_get_fragment_packets(txmngpacket, responsefragmentpacket, g_ac_discovery.fragmentid); if (responsefragmentpacket->count > 1) { g_ac_discovery.fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Send discovery response to WTP */ if (!capwap_sendto_fragmentpacket(acpacket->sendsock, responsefragmentpacket, &acpacket->sender)) { capwap_logging_debug("Warning: error to send discovery response packet"); } /* Don't buffering a packets sent */ capwap_list_free(responsefragmentpacket); } } } /* Free resource */ capwap_free_parsed_packet(&packet); } } /* Free resource */ capwap_packet_rxmng_free(rxmngpacket); /* Free packet */ capwap_itemlist_free(itempacket); } }
void ac_dfa_state_join(struct ac_session_t* session, struct capwap_parsed_packet* packet) { unsigned short binding; struct ac_soap_response* response; struct capwap_header_data capwapheader; struct capwap_packet_txmng* txmngpacket; struct capwap_sessionid_element* sessionid; struct capwap_wtpboarddata_element* wtpboarddata; struct capwap_resultcode_element resultcode = { .code = CAPWAP_RESULTCODE_FAILURE }; ASSERT(session != NULL); ASSERT(packet != NULL); /* Check binding */ binding = GET_WBID_HEADER(packet->rxmngpacket->header); if (ac_valid_binding(binding)) { if (packet->rxmngpacket->ctrlmsg.type == CAPWAP_JOIN_REQUEST) { /* Get sessionid and verify unique id */ sessionid = (struct capwap_sessionid_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_SESSIONID); if (!ac_has_sessionid(sessionid)) { char* wtpid; /* Checking macaddress for detect if WTP already connected */ wtpboarddata = (struct capwap_wtpboarddata_element*)capwap_get_message_element_data(packet, CAPWAP_ELEMENT_WTPBOARDDATA); /* Get printable WTPID */ wtpid = ac_get_printable_wtpid(wtpboarddata); if (wtpid && !ac_has_wtpid(wtpid)) { /* Request authorization of Backend for complete join */ response = ac_soap_authorizewtpsession(session, wtpid); if (response) { resultcode.code = ac_dfa_state_join_check_authorizejoin(session, response); ac_soapclient_free_response(response); } else { resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_UNKNOWN_SOURCE; } } else { capwap_logging_info("WTP Id %s already used in another session", wtpid); resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_UNKNOWN_SOURCE; } /* */ if (CAPWAP_RESULTCODE_OK(resultcode.code)) { session->wtpid = wtpid; memcpy(&session->sessionid, sessionid, sizeof(struct capwap_sessionid_element)); session->binding = binding; } else if (wtpid) { capwap_free(wtpid); } } else { char sessionname[33]; capwap_sessionid_printf(sessionid, sessionname); capwap_logging_info("Session Id %s already used in another session", sessionname); resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_ID_ALREADY_IN_USE; } } else { resultcode.code = CAPWAP_RESULTCODE_MSG_UNEXPECTED_INVALID_CURRENT_STATE; } } else { resultcode.code = CAPWAP_RESULTCODE_JOIN_FAILURE_BINDING_NOT_SUPPORTED; } /* Create response */ capwap_header_init(&capwapheader, CAPWAP_RADIOID_NONE, binding); txmngpacket = capwap_packet_txmng_create_ctrl_message(&capwapheader, CAPWAP_JOIN_RESPONSE, packet->rxmngpacket->ctrlmsg.seq, session->mtu); /* */ if (CAPWAP_RESULTCODE_OK(resultcode.code)) { response = ac_dfa_state_join_parsing_request(session, packet); if (response) { resultcode.code = ac_dfa_state_join_create_response(session, packet, response, txmngpacket); ac_soapclient_free_response(response); } } /* Add always result code message element */ capwap_packet_txmng_add_message_element(txmngpacket, CAPWAP_ELEMENT_RESULTCODE, &resultcode); /* Join response complete, get fragment packets */ ac_free_reference_last_response(session); capwap_packet_txmng_get_fragment_packets(txmngpacket, session->responsefragmentpacket, session->fragmentid); if (session->responsefragmentpacket->count > 1) { session->fragmentid++; } /* Free packets manager */ capwap_packet_txmng_free(txmngpacket); /* Save remote sequence number */ session->remotetype = packet->rxmngpacket->ctrlmsg.type; session->remoteseqnumber = packet->rxmngpacket->ctrlmsg.seq; /* Send Join response to WTP */ if (capwap_crypt_sendto_fragmentpacket(&session->dtls, session->responsefragmentpacket)) { if (CAPWAP_RESULTCODE_OK(resultcode.code)) { ac_dfa_change_state(session, CAPWAP_POSTJOIN_STATE); capwap_timeout_set(session->timeout, session->idtimercontrol, AC_JOIN_INTERVAL, ac_dfa_teardown_timeout, session, NULL); } else { ac_session_teardown(session); } } else { /* Error to send packets */ capwap_logging_debug("Warning: error to send join response packet"); ac_session_teardown(session); } }