Inital ...
FossilOrigin-Name: e6352b425bf6574bdaacc571723f7b54394e235d8b64bbaa504c9b7e529b7535
This commit is contained in:
		
							
								
								
									
										65
									
								
								src/capwap/acpriolist.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/capwap/acpriolist.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,65 @@
 | 
			
		||||
/*
 | 
			
		||||
    This file is part of libcapwap.
 | 
			
		||||
 | 
			
		||||
    libcapwap is free software: you can redistribute it and/or modify
 | 
			
		||||
    it under the terms of the GNU General Public License as published by
 | 
			
		||||
    the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
    (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    libcapwap is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
    GNU General Public License for more details.
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU General Public License
 | 
			
		||||
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include <netinet/in.h>
 | 
			
		||||
#include <arpa/inet.h>
 | 
			
		||||
 | 
			
		||||
#include "acpriolist.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static int acprio_cmp(const void *x1, const void *x2)
 | 
			
		||||
{
 | 
			
		||||
	cw_acprio_t * p1 = (cw_acprio_t*)x1;
 | 
			
		||||
	cw_acprio_t * p2 = (cw_acprio_t*)x2;
 | 
			
		||||
	return strcmp (p1->name,p2->name);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void acprio_del(void *d)
 | 
			
		||||
{
 | 
			
		||||
	cw_acprio_t *p = (cw_acprio_t*)d;
 | 
			
		||||
	if ( p->name ) 
 | 
			
		||||
		free (p->name);
 | 
			
		||||
	free(d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cw_acpriolist_t cw_acpriolist_create()
 | 
			
		||||
{
 | 
			
		||||
	return  avltree_create(acprio_cmp, acprio_del);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio)
 | 
			
		||||
{
 | 
			
		||||
		
 | 
			
		||||
	cw_acprio_t * s=malloc(sizeof(cw_acprio_t));
 | 
			
		||||
	if (!s)
 | 
			
		||||
		return 0;
 | 
			
		||||
	s->name=strndup(name,name_len);
 | 
			
		||||
	s->prio=prio;
 | 
			
		||||
 | 
			
		||||
	cw_acpriolist_del(l,s);
 | 
			
		||||
	return avltree_add(l,s);
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										31
									
								
								src/capwap/acpriolist.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/capwap/acpriolist.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
#ifndef __ACIPRIORITYLIST_H
 | 
			
		||||
#define __ACIPRIORITYLIST_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "avltree.h"
 | 
			
		||||
 | 
			
		||||
struct cw_acprio{
 | 
			
		||||
	char *name;
 | 
			
		||||
	uint8_t prio;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct cw_acprio cw_acprio_t;
 | 
			
		||||
typedef struct avltree * cw_acpriolist_t;
 | 
			
		||||
 | 
			
		||||
extern cw_acpriolist_t cw_acpriolist_create();
 | 
			
		||||
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio);
 | 
			
		||||
 | 
			
		||||
static inline int cw_acpriolist_get(cw_acpriolist_t l, char * acname){
 | 
			
		||||
	cw_acprio_t ps,*pf;
 | 
			
		||||
	ps.name=acname;
 | 
			
		||||
	
 | 
			
		||||
	pf=avltree_get(l,&ps);
 | 
			
		||||
	if (!pf)
 | 
			
		||||
		return 256;
 | 
			
		||||
	return pf->prio;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define cw_acpriolist_del(l,s) avltree_del(l,s)
 | 
			
		||||
#define cw_acpriolist_set(l,n,nl,p) cw_acpriolist_add(l,n,nl,p)
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										13
									
								
								src/capwap/capwap_80211_actions.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/capwap/capwap_80211_actions.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "capwap_80211.h"
 | 
			
		||||
#include "capwap_items.h"
 | 
			
		||||
 | 
			
		||||
#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION 	\
 | 
			
		||||
	CW_ELEM80211_WTP_RADIO_INFORMATION,		/* Element ID*/			\
 | 
			
		||||
	cw_in_generic, 0,				/* start/end callback */	\
 | 
			
		||||
	CW_ITEMTYPE_STR, 				/* Type of element */		\
 | 
			
		||||
	CW_ITEM_LOCATION_DATA,				/* ID to use store */		\
 | 
			
		||||
	5, 5						/* min/max length */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										39
									
								
								src/capwap/capwap_80211_actions_wtp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/capwap/capwap_80211_actions_wtp.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "action.h"
 | 
			
		||||
#include "capwap_80211_actions.h"
 | 
			
		||||
#include "capwap.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cw_action_in_t capwap_80211_actions_wtp_in[] = {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_RESPONSE,
 | 
			
		||||
	 CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
 | 
			
		||||
	,
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	{0, 0, 0}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	cw_actionlist_in_register_actions(def->in, capwap_80211_actions_wtp_in);
 | 
			
		||||
//	cw_actionlist_out_register_actions(def->out, capwap_actions_wtp_out);
 | 
			
		||||
 | 
			
		||||
	int rc;
 | 
			
		||||
	rc = cw_strheap_register_strings(def->strelem, capwap_strings_elem80211);
 | 
			
		||||
	printf("80211 Registerd %d\n",rc);
 | 
			
		||||
	/*rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								src/capwap/capwap_strings_elem80211.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/capwap/capwap_strings_elem80211.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#include "capwap_80211.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct cw_str capwap_strings_elem80211[] = {
 | 
			
		||||
 | 
			
		||||
	{CW_ELEM80211_WTP_RADIO_INFORMATION, "802.11 WTP Radio Information"},
 | 
			
		||||
	{CW_STR_STOP,"Unknown"}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										14
									
								
								src/capwap/capwap_strings_result.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/capwap/capwap_strings_result.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
#include "capwap.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct cw_str capwap_strings_result[] = {
 | 
			
		||||
 | 
			
		||||
	{CW_RESULT_SUCCESS,"Success"},							/* 0 */
 | 
			
		||||
	{CW_RESULT_MISSING_AC_LIST,"AC List Message Element MUST be Present"},		/* 1 */
 | 
			
		||||
	{CW_RESULT_SUCCESS_NAT,"Success - NAT Detected"},				/* 2 */
 | 
			
		||||
	{CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"},		/* 20 */
 | 
			
		||||
 | 
			
		||||
	{CW_STR_STOP,"Unknown Result Code"}
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
	
 | 
			
		||||
							
								
								
									
										9
									
								
								src/capwap/cw_in_ac_descriptor.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/capwap/cw_in_ac_descriptor.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int cw_in_ac_descriptor(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len)
 | 
			
		||||
{
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								src/capwap/cw_in_capwap_control_ipv4_address.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								src/capwap/cw_in_capwap_control_ipv4_address.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
#include "action.h"
 | 
			
		||||
#include "cw_log.h"
 | 
			
		||||
#include "itemstore.h"
 | 
			
		||||
#include "capwap.h"
 | 
			
		||||
#include "capwap_items.h"
 | 
			
		||||
#include "aciplist.h"
 | 
			
		||||
#include "sock.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a,
 | 
			
		||||
				 uint8_t * data, int len)
 | 
			
		||||
{
 | 
			
		||||
	cw_aciplist_t list =
 | 
			
		||||
	    cw_itemstore_get_avltree_c(conn->incomming,a->item_id,cw_aciplist_create);
 | 
			
		||||
 | 
			
		||||
	if (!list) {
 | 
			
		||||
		cw_log(LOG_ERR, "Error: Can't allocate CAWAP IP Adress List");
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cw_acip_t * acip;
 | 
			
		||||
	acip = malloc(sizeof(cw_acip_t));
 | 
			
		||||
	if (!acip) {
 | 
			
		||||
		cw_log(LOG_ERR,"Can't allocate memory for acv4ip: %s",strerror(errno));
 | 
			
		||||
			return 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct sockaddr_in addr;
 | 
			
		||||
	memcpy(&addr.sin_addr,data,4);
 | 
			
		||||
	addr.sin_family=AF_INET;
 | 
			
		||||
	sock_setport((struct sockaddr*)&addr,CAPWAP_CONTROL_PORT);
 | 
			
		||||
	memcpy(&acip->ip,&addr,sizeof(addr));
 | 
			
		||||
 | 
			
		||||
	acip->wtp_count = cw_get_word(data+4);
 | 
			
		||||
	cw_aciplist_replace(list,acip);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										37
									
								
								src/capwap/cw_in_check_join_resp.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/capwap/cw_in_check_join_resp.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
#include "capwap.h"
 | 
			
		||||
#include "intavltree.h"
 | 
			
		||||
#include "dbg.h"
 | 
			
		||||
#include "cw_log.h"
 | 
			
		||||
#include "capwap_items.h"
 | 
			
		||||
 | 
			
		||||
int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
 | 
			
		||||
			 int len)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
	cw_action_in_t * mlist[60];
 | 
			
		||||
 | 
			
		||||
	/* Check for mandatory elements */
 | 
			
		||||
	int n = cw_check_missing_mand(mlist,conn,a);
 | 
			
		||||
	if (n) {
 | 
			
		||||
		cw_dbg_missing_mand(DBG_ELEM,conn,mlist,n,a);
 | 
			
		||||
		conn->capwap_state=CW_STATE_JOIN;
 | 
			
		||||
		errno=EAGAIN;
 | 
			
		||||
		return -1; //CW_RESULT_MISSING_MAND_ELEM;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	cw_item_t * jresult = cw_itemstore_get(conn->incomming,	CW_ITEM_RESULT_CODE);
 | 
			
		||||
 | 
			
		||||
	if ( jresult ) {
 | 
			
		||||
		return jresult->dword;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* set result code to ok and change to configure state */
 | 
			
		||||
//	cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										44
									
								
								src/capwap/send.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/capwap/send.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,44 @@
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
 | 
			
		||||
#include "conn.h"
 | 
			
		||||
#include "capwap.h"
 | 
			
		||||
#include "cw_log.h"
 | 
			
		||||
#include "sock.h"
 | 
			
		||||
 | 
			
		||||
int cw_send_request(struct conn *conn,int msg_id)
 | 
			
		||||
{
 | 
			
		||||
	cw_init_request(conn, msg_id);
 | 
			
		||||
	if ( cw_put_msg(conn, conn->req_buffer) == -1 )
 | 
			
		||||
		return 0;
 | 
			
		||||
	conn_send_msg(conn, conn->req_buffer);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	int i;
 | 
			
		||||
	int rc=-1;
 | 
			
		||||
	for (i=0; i<conn->max_retransmit && rc<0; i++){
 | 
			
		||||
		time_t timer = cw_timer_start(conn->retransmit_interval);
 | 
			
		||||
		while (!cw_timer_timeout(timer) && rc<0){
 | 
			
		||||
	
 | 
			
		||||
        	        rc =cw_read_messages(conn);
 | 
			
		||||
			if(rc<0){
 | 
			
		||||
				if (errno!=EAGAIN)
 | 
			
		||||
					break;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		if (rc<0){
 | 
			
		||||
			if(errno!=EAGAIN)
 | 
			
		||||
				break;
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ( rc <0 ) {
 | 
			
		||||
		cw_log(LOG_ERR,"Error reading from %s:%s",sock_addr2str(&conn->addr),strerror(errno));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return rc;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user