-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
134 changed files
with
41,713 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,307 @@ | ||
/******************************************************************************************* | ||
* Copyright (c) 2006-7 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica * | ||
* Universita' Campus BioMedico - Italy * | ||
* * | ||
* This program 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 2 of the License, or (at your option) any later version. * | ||
* * | ||
* This program 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 this * | ||
* program; if not, write to the: * | ||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * | ||
* MA 02111-1307, USA. * | ||
* * | ||
* --------------------------------------------------------------------------------------- * | ||
* Project: Capwap * | ||
* * | ||
* Author : Ludovico Rossi ([email protected]) * | ||
* Del Moro Andrea ([email protected]) * | ||
* Giovannini Federica ([email protected]) * | ||
* Massimo Vellucci ([email protected]) * | ||
* Mauro Bisson ([email protected]) * | ||
*******************************************************************************************/ | ||
|
||
|
||
|
||
#include "CWAC.h" | ||
#include "CWCommon.h" | ||
|
||
#ifdef DMALLOC | ||
#include "../dmalloc-5.5.0/dmalloc.h" | ||
#endif | ||
|
||
/*_________________________________________________________*/ | ||
/* *******************___VARIABLES___******************* */ | ||
CWThreadMutex gCreateIDMutex; | ||
|
||
/* array that stores per WTPs infos */ | ||
CWWTPManager gWTPs[CW_MAX_WTP]; | ||
CWThreadMutex gWTPsMutex; | ||
|
||
int gEnabledLog = 1; | ||
|
||
int gMaxLogFileSize; | ||
char gLogFileName[]=AC_LOG_FILE_NAME; | ||
|
||
/* number of active WTPs */ | ||
int gActiveWTPs = 0; | ||
CWThreadMutex gActiveWTPsMutex; | ||
|
||
/* max WTPs */ | ||
int gMaxWTPs; | ||
/* The Radio MAC Field of the discovery response */ | ||
int gRMACField = 0; | ||
/* The Wireless Field of the discovery response */ | ||
int gWirelessField = 0; | ||
/* DTLS Policy for data channel */ | ||
int gDTLSPolicy=DTLS_ENABLED_DATA; | ||
/* special socket to handle multiple network interfaces */ | ||
CWMultiHomedSocket gACSocket; | ||
/* AC's network interfaces */ | ||
CWProtocolNetworkInterface *gInterfaces = NULL; | ||
int gInterfacesCount = 0; | ||
/* DTLS Context */ | ||
CWSecurityContext gACSecurityContext; | ||
int gActiveStations = 0; | ||
/* max stations */ | ||
int gLimit; | ||
char **gMulticastGroups; | ||
int gMulticastGroupsCount; | ||
CWAuthSecurity gACDescriptorSecurity; | ||
int gACHWVersion; | ||
int gACSWVersion; | ||
char *gACName = NULL; | ||
|
||
int gDiscoveryTimer=20; | ||
int gEchoRequestTimer=CW_ECHO_INTERVAL_DEFAULT; | ||
/* PROVVISORIO: Il valore e' scelto a caso */ | ||
int gIdleTimeout=10; | ||
|
||
/*_________________________________________________________*/ | ||
/* *******************___FUNCTIONS___******************* */ | ||
int main (int argc, const char * argv[]) { | ||
|
||
/* Daemon mode */ | ||
|
||
if (argc <= 1) | ||
printf("Usage: AC working_path !!!\n"); | ||
|
||
if (daemon(1, 0) < 0) | ||
{ | ||
printf("daemon fail"); | ||
exit(1); | ||
} | ||
|
||
if (chdir(argv[1]) != 0) | ||
{ | ||
printf("chdir fail"); | ||
exit(1); | ||
} | ||
|
||
CWLog("CWACInit begin...\n"); | ||
CWACInit(); | ||
CWLog("CWACEnterMainLoop begin...\n"); | ||
CWACEnterMainLoop(); | ||
CWLog("CWACDestroy begin...\n"); | ||
CWACDestroy(); | ||
CWLog("main over...\n"); | ||
return 0; | ||
} | ||
|
||
int CWACSemPostForOpenSSLHack(void *s) { | ||
|
||
CWThreadTimedSem *semPtr = (CWThreadTimedSem*) s; | ||
|
||
if(!CWThreadTimedSemIsZero(semPtr)) { | ||
CWLog("This Semaphore's Value should really be 0"); | ||
/* note: we can consider setting the value to 0 and going on, | ||
* that is what we do here | ||
*/ | ||
if(!CWErr(CWThreadTimedSemSetValue(semPtr, 0))) return 0; | ||
} | ||
|
||
if(!CWErr(CWThreadTimedSemPost(semPtr))) { | ||
return 0; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
void CWACInit() { | ||
int i; | ||
CWNetworkLev4Address *addresses = NULL; | ||
struct sockaddr_in *IPv4Addresses = NULL; | ||
|
||
CWLogInitFile(AC_LOG_FILE_NAME); | ||
|
||
#ifndef CW_SINGLE_THREAD | ||
CWDebugLog("Use Threads"); | ||
#else | ||
CWDebugLog("Don't Use Threads"); | ||
#endif | ||
//线程中需要存储特殊值 | ||
CWErrorHandlingInitLib(); | ||
|
||
if(!CWParseSettingsFile()) | ||
{ | ||
CWLog("Can't start AC"); | ||
exit(1); | ||
} | ||
|
||
CWLog("Starting AC"); | ||
|
||
//阻塞信号 | ||
CWThreadSetSignals(SIG_BLOCK, 1, SIGALRM); | ||
if (timer_init() == 0) { | ||
CWLog("Can't init timer module"); | ||
exit(1); | ||
} | ||
|
||
if(!CWErr(CWParseConfigFile()) || | ||
#ifndef CW_NO_DTLS | ||
!CWErr(CWSecurityInitLib()) || | ||
#endif | ||
!CWErr(CWNetworkInitSocketServerMultiHomed(&gACSocket, CW_CONTROL_PORT, gMulticastGroups, gMulticastGroupsCount)) || | ||
!CWErr(CWNetworkGetInterfaceAddresses(&gACSocket, &addresses, &IPv4Addresses)) || | ||
!CWErr(CWCreateThreadMutex(&gWTPsMutex)) || | ||
!CWErr(CWCreateThreadMutex(&gActiveWTPsMutex))) { | ||
|
||
/* error starting */ | ||
CWLog("Can't start AC"); | ||
exit(1); | ||
} | ||
|
||
#ifndef CW_NO_DTLS | ||
if(gACDescriptorSecurity == CW_X509_CERTIFICATE) { | ||
|
||
if(!CWErr(CWSecurityInitContext(&gACSecurityContext, | ||
"root.pem", | ||
"server.pem", | ||
"prova", | ||
CW_FALSE, | ||
CWACSemPostForOpenSSLHack))) { | ||
|
||
CWLog("Can't start AC"); | ||
exit(1); | ||
} | ||
} else { /* preshared */ | ||
if(!CWErr(CWSecurityInitContext(&gACSecurityContext, | ||
NULL, | ||
NULL, | ||
NULL, | ||
CW_FALSE, | ||
CWACSemPostForOpenSSLHack))) { | ||
CWLog("Can't start AC"); | ||
exit(1); | ||
} | ||
} | ||
#endif | ||
CW_FREE_OBJECTS_ARRAY(gMulticastGroups, gMulticastGroupsCount); | ||
|
||
for(i = 0; i < CW_MAX_WTP; i++) { | ||
gWTPs[i].isNotFree = CW_FALSE; | ||
} | ||
|
||
/* store network interface's addresses */ | ||
gInterfacesCount = CWNetworkCountInterfaceAddresses(&gACSocket); | ||
CWLog("Found %d Network Interface(s)", gInterfacesCount); | ||
|
||
if (gInterfacesCount<=0){ | ||
CWLog("Can't start AC"); | ||
exit(1); | ||
} | ||
|
||
CW_CREATE_ARRAY_ERR(gInterfaces, | ||
gInterfacesCount, | ||
CWProtocolNetworkInterface, | ||
CWLog("Out of Memory"); return;); | ||
|
||
for(i = 0; i < gInterfacesCount; i++) { | ||
gInterfaces[i].WTPCount = 0; | ||
CW_COPY_NET_ADDR_PTR(&(gInterfaces[i].addr), ((CWNetworkLev4Address*)&((addresses)[i])) ); | ||
if(IPv4Addresses != NULL) { | ||
CW_COPY_NET_ADDR_PTR(&(gInterfaces[i].addrIPv4), &((IPv4Addresses)[i])); | ||
} | ||
} | ||
CW_FREE_OBJECT(addresses); | ||
CW_FREE_OBJECT(IPv4Addresses); | ||
|
||
if(!CWErr(CWCreateThreadMutex(&gCreateIDMutex))) { | ||
exit(1); | ||
} | ||
|
||
CWLog("AC Started"); | ||
} | ||
|
||
|
||
void CWACDestroy() { | ||
|
||
CWNetworkCloseMultiHomedSocket(&gACSocket); | ||
|
||
/* | ||
for(i = 0; i < CW_MAX_WTP; i++) { | ||
//CW_FREE_OBJECT(gWTPs[i].addr); | ||
} | ||
*/ | ||
|
||
CWSslCleanUp(); | ||
|
||
CWDestroyThreadMutex(&gWTPsMutex); | ||
CWDestroyThreadMutex(&gCreateIDMutex); | ||
CWDestroyThreadMutex(&gActiveWTPsMutex); | ||
|
||
CW_FREE_OBJECT(gACName); | ||
CW_FREE_OBJECT(gInterfaces); | ||
|
||
CWLog("AC Destroyed"); | ||
} | ||
|
||
|
||
__inline__ unsigned int CWGetSeqNum() { | ||
|
||
static unsigned int seqNum = 0; | ||
unsigned int r; | ||
|
||
if(!CWThreadMutexLock(&gCreateIDMutex)) { | ||
|
||
CWDebugLog("Error Locking a mutex"); | ||
} | ||
|
||
r = seqNum; | ||
|
||
if (seqNum==CW_MAX_SEQ_NUM) | ||
seqNum=0; | ||
else | ||
seqNum++; | ||
|
||
CWThreadMutexUnlock(&gCreateIDMutex); | ||
return r; | ||
} | ||
|
||
|
||
__inline__ int CWGetFragmentID() { | ||
|
||
static int fragID = 0; | ||
int r; | ||
|
||
if(!CWThreadMutexLock(&gCreateIDMutex)) { | ||
|
||
CWDebugLog("Error Locking a mutex"); | ||
} | ||
|
||
r = fragID; | ||
|
||
if (fragID==CW_MAX_FRAGMENT_ID) | ||
fragID=0; | ||
else | ||
fragID++; | ||
|
||
CWThreadMutexUnlock(&gCreateIDMutex); | ||
return r; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* appsToAcProtocol.h | ||
* | ||
* | ||
* Created by Antonio Davoli on 03/03/09. | ||
* Copyright 2009 La Sapienza. All rights reserved. | ||
* | ||
*/ | ||
|
||
/* Macro Definition */ | ||
|
||
/* AC Request Message */ | ||
|
||
/**************************************** | ||
* For LIST, QUIT (without argument) * | ||
* * | ||
* 0 7 * | ||
* +-+-+-+-+-+-+-+-+ * | ||
* | Cmd_msg | * | ||
* +-+-+-+-+-+-+-+-+ * | ||
* * | ||
****************************************/ | ||
|
||
/* CMD_MSG Types */ | ||
|
||
#define FULL_CLIENT_CONNECTED -1 | ||
#define CONNECTION_OK 1 | ||
#define QUIT_MSG 0 | ||
#define LIST_MSG 1 | ||
#define CONF_UPDATE_MSG 2 | ||
|
||
/******************************************************************************************************************************** | ||
* List Response Message: * | ||
* * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* | Active# | WTP_ID 1 | NameLength 1 | WTP Name 1 | ... | WTP ID N | NameLength N | WTP Name N | * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* * | ||
* where N is equal to Active# (Number of Active WTPs) * | ||
********************************************************************************************************************************/ | ||
|
||
|
||
/******************************************************************************************************** | ||
* For CONF_UPDATE_MSG type: * | ||
* * | ||
* 0 7 15 23 X * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* | cmd_msg | msg_elem | WPT Index | Message Specific Payload | * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* * | ||
********************************************************************************************************/ | ||
|
||
#define PAYLOAD_START ((sizeof(unsigned char)*2) + sizeof(int)) | ||
#define ALL_ACTIVE_WTPS -1 | ||
|
||
#define MSG_ELEMENT_TYPE_OFDM 1 | ||
#define MSG_ELEMENT_TYPE_VENDOR_UCI 2 | ||
#define MSG_ELEMENT_TYPE_VENDOR_WUM 3 | ||
#define MSG_ELEMENT_TYPE_VENDOR_XML 4 | ||
|
||
/**************************************************************************************** | ||
* Message Specific Payload for MSG_ELEMENT_TYPE_OFDM TYPE (802.11 Binding Version) * | ||
* * | ||
* 0 1 2 3 * | ||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* | Radio ID | Reserved | Current Chan | Band Support | * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* | TI Threshold | * | ||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ||
* * | ||
****************************************************************************************/ | ||
|
||
/* Radio ID is filled in the creation message funcion (inside the AC) */ | ||
|
||
|
||
|
||
|
Oops, something went wrong.