Browse Source

Linux Symulation DDOS Targets to SafeShore Server

AGP
Evgeny Gagua 7 years ago
parent
commit
ab4f9ccf15
  1. 16
      Projects/LRF_Server/Debug/default.conf
  2. 2
      lib/App/3dSERVER/LRF_DefenderHandler.cpp
  3. 103
      lib/App/3dSERVER/LRF_HardwareManager.cpp
  4. 13
      lib/App/3dSERVER/LRF_HardwareManager.h
  5. 8
      lib/App/3dSERVER/LRF_Kernel.cpp
  6. 14
      lib/App/3dSERVER/LRF_SafeShoreHandler.cpp
  7. 12
      lib/data/curl/curlRequestsManager.cpp
  8. 2
      lib/data/curl/curlRequestsManager.h
  9. 4
      lib/data/protocol/protocolHTTP.cpp
  10. 1
      lib/data/protocol/protocolSafeShore.cpp
  11. 15
      lib/hardware/soc/general/3DLRF.h
  12. 24
      lib/hardware/soc/modules/pru/pru_ss.c

16
Projects/LRF_Server/Debug/default.conf

@ -34,17 +34,17 @@ HARDWARE_MANAGER :
};
KERNEL :
{
ENABLE_SAFE_SHORE = false;
ENABLE_DEFENDER = true;
ENABLE_SAFE_SHORE = true;
ENABLE_DEFENDER = false;
DETECTOR_WIDTH = 1000;
ENABLED_LRF = 255;
DETECTOR_SST = 0;
SAFESHORE_CONNECTION :
{
CURL_POST_CONTENT_TYPE = "application/xml";
SCANNER_NAME = "LRF_2D_001";
SCANNER_DIMENTIONS = 2;
LCU_IP_ADDRESS = "192.168.200.204";
SCANNER_NAME = "LRF_3D_001";
SCANNER_DIMENTIONS = 3;
LCU_IP_ADDRESS = "192.168.200.103";
LCU_IP_PORT = 80;
};
DEFENDER_CONNECTION :
@ -52,7 +52,11 @@ KERNEL :
CURL_POST_CONTENT_TYPE = "application/json";
SCANNER_NAME = "LRF_3D_001";
SCANNER_DIMENTIONS = 3;
CEP_IP_ADDRESS = "192.168.200.125";
CEP_IP_ADDRESS = "192.168.200.103";
CEP_IP_PORT = 80;
LOCATION_LON = 35.0938962;
LOCATION_LAT = 32.904208;
USE_SSL = false;
ACCESS_URL = "/defender-eps/rest/simple-event/notify";
};
};

2
lib/App/3dSERVER/LRF_DefenderHandler.cpp

@ -32,10 +32,12 @@ void LRF_DefenderHandler::m_fThreadProc( void ){
StatusUpdate();
//m_lCycleCounter == 0;
};
/* No need for time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
StartTimeSynch();
//m_lCycleCounter == 0;
};
*/
SLEEP(100);
};
};

103
lib/App/3dSERVER/LRF_HardwareManager.cpp

@ -65,7 +65,8 @@ LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){
LOG_ERROR("Cannot Allocate Flip Protector Mutex!");
};
#endif
#ifdef THREADED_MOTORS_START
#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_MOTORS_START
m_pMotorCtrlThreadHandler = NULL;
m_pMotorCtrlMutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
if( m_pMotorCtrlMutex != NULL ) {
@ -90,6 +91,9 @@ LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){
} else {
LOG_ERROR("Cannot Allocate Motor Ctrl Protector Mutex!");
};
#endif
#else
LOG("Motors are disabled by Build - TOTTAL SIMULATION BUILD!");
#endif
@ -107,6 +111,7 @@ LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){
m_vMemoryBlock[1] = NULL;
m_vMemoryBlock[2] = NULL;
m_vMemoryBlock[3] = NULL;
#ifndef ONPC_TOTTAL_SIMULATOR
m_pSOC = classSOC::getInstance();
if( m_pSOC!= NULL ) {
m_bInitOK = readPercs();
@ -116,6 +121,7 @@ LRF_HardwareManager::LRF_HardwareManager( config_setting_t *SNode ){
if( m_bInitOK && m_pSettings!= NULL ){
m_bInitOK = create( m_pSettings );
};
#endif
};
// Destructor implementation
@ -588,6 +594,7 @@ bool LRF_HardwareManager::create( HW_PARAMS &HS ){
void LRF_HardwareManager::beginService( void ){
m_bInitOK = false;
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC != NULL ) {
LOG("Begin HW init process");
LOG("Stoping all PRU Cores");
@ -983,8 +990,13 @@ void LRF_HardwareManager::beginService( void ){
m_bInitOK = true;
};
};
#else //#ifndef ONPC_TOTTAL_SIMULATOR
LOG("Dummy Init of Hardware");
m_bInitOK = true;
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
};
void LRF_HardwareManager::endService( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!=NULL ){
if( m_sPARAMETERS.flags.isMaster ) {
#ifndef NO_MOTORS
@ -1046,8 +1058,13 @@ void LRF_HardwareManager::endService( void ){
LOG_ERROR("PRU 1 1 HALT - FAILURE");
};
};
#else //#ifndef ONPC_TOTTAL_SIMULATOR
LOG("Dummy Shutdown Hardware");
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
};
#ifdef THREADED_MOTORS_START
#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_MOTORS_START
void LRF_HardwareManager::performStartMotors( void ){
if( m_sPARAMETERS.flags.TGZ_canENA ) {
LOG("Starting TGZ device");
@ -1504,10 +1521,15 @@ bool LRF_HardwareManager::stopMotors( bool Auto ){
#endif // THREADED_MOTORS_START
return true;
};
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
static uint32_t nMemoryDumpID = 0;
static uint32_t nMemoryDumpID = 0;
#ifdef ONPC_TOTTAL_SIMULATOR
static thresholdNode * DUMMY_TH_MEMORY = NULL;
#endif
thresholdNode *LRF_HardwareManager::getWorkingMemory( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!= NULL ){
thresholdNode *tNode;
thresholdNode *rNode;
@ -1536,7 +1558,15 @@ thresholdNode *LRF_HardwareManager::getWorkingMemory( void ){
};
return rNode;
};
return NULL;
return NULL;
#else
if( DUMMY_TH_MEMORY == NULL ) {
LOG("Allocate Dummy buffer for TH memories");
DUMMY_TH_MEMORY = (thresholdNode *)malloc( 2 * KERNEL_COUNT * TH_SIZE_NODES * sizeof(thresholdNode));
};
return DUMMY_TH_MEMORY;
#endif
};
int LRF_HardwareManager::getWorkingMemoryID( void ){
@ -1544,22 +1574,29 @@ int LRF_HardwareManager::getWorkingMemoryID( void ){
};
uint32_t *LRF_HardwareManager::getEventMemory( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!= NULL ){
return m_pSOC->getEVT_MEMORY();
};
#endif
return NULL;
};
bool LRF_HardwareManager::getDetectionStatus( DT_STATUS &Status ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!=NULL ){
*((uint32_t*)&m_sCS_Detector) = m_pSOC->getThCoreStatus();
Status = m_sCS_Detector;
if( Status.online ) return true;
};
return false;
#else
return true;
#endif
};
bool LRF_HardwareManager::getDetectionParams( TH_PARAMS &Params ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!=NULL ){
*((uint32_t*)&m_sCP_Detector) = m_pSOC->getThCoreParams();
Params = m_sCP_Detector;
@ -1569,11 +1606,15 @@ bool LRF_HardwareManager::getDetectionParams( TH_PARAMS &Params ){
return true;
};
return false;
#else
return true;
#endif
};
bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){
if(Params == NULL) return false;
memcpy( &m_sPARAMETERS, Params, sizeof(LGS_PARAMETERS) );
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC!=NULL ){
// Save into settings
m_sCP_Detector.delta = m_sPARAMETERS.nDelta;
@ -1607,6 +1648,9 @@ bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){
return true;
};
return false;
#else
return true;
#endif
};
#ifdef SIMULATE_FLIPS
@ -1615,12 +1659,11 @@ bool LRF_HardwareManager::setDetectionParams( TH_PARAMS *Params ){
//static uint32_t stam = 0;
bool LRF_HardwareManager::validateCores( void ){
if( !m_bInitOK ) return false;
#ifdef SIMULATE_FLIPS
pips_counter++;
#endif
#ifndef ONPC_TOTTAL_SIMULATOR
if( !m_bInitOK ) return false;
if( m_pSOC != NULL ){
*((uint32_t*)&m_sCS_Motors) = m_pSOC->getMotorStatus();
if( m_sCS_Motors.online ){
@ -1740,6 +1783,9 @@ bool LRF_HardwareManager::validateCores( void ){
LOG_ERROR( "SOC Not Defined!");
};
return false;
#else //#ifndef ONPC_TOTTAL_SIMULATOR
return true;
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
};
void LRF_HardwareManager::restartService( void ){
@ -1817,23 +1863,24 @@ bool LRF_HardwareManager::reset( bool Hard ){
};
return true;
};
#ifdef THREADED_MOTORS_START
void *LRF_HardwareManager::m_fMotorStartThreadFunction( void *ptr ){
LRF_HardwareManager *me;
me = (LRF_HardwareManager*)ptr;
me->performStartMotors();
pthread_exit( NULL );
return NULL;
};
void *LRF_HardwareManager::m_fMotorStopThreadFunction( void *ptr ){
LRF_HardwareManager *me;
me = (LRF_HardwareManager*)ptr;
me->performStopMotors();
pthread_exit( NULL );
return NULL;
};
#endif
#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_MOTORS_START
void *LRF_HardwareManager::m_fMotorStartThreadFunction( void *ptr ){
LRF_HardwareManager *me;
me = (LRF_HardwareManager*)ptr;
me->performStartMotors();
pthread_exit( NULL );
return NULL;
};
void *LRF_HardwareManager::m_fMotorStopThreadFunction( void *ptr ){
LRF_HardwareManager *me;
me = (LRF_HardwareManager*)ptr;
me->performStopMotors();
pthread_exit( NULL );
return NULL;
};
#endif
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_FLIP
void *LRF_HardwareManager::m_fFlipThreadFunction( void *ptr ){
@ -1853,6 +1900,7 @@ static uint32_t m_sgnFlipCounter = 0;
bool LRF_HardwareManager::performFlip( void ){
if( !m_bInitOK ) return false;
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC != NULL ){
char Buffer[256];//Used also in Event!!
volatile thresholdNode * th_node[16];
@ -2071,6 +2119,9 @@ bool LRF_HardwareManager::performFlip( void ){
LOG_ERROR("No SOC Object!");
};
return false;
#else //#ifndef ONPC_TOTTAL_SIMULATOR
return true;
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
};
#else // TH_NEW_FLIP_FUNC == 0
@ -2349,6 +2400,7 @@ bool LRF_HardwareManager::loadHibernatedTH( CSTR fname ){
#endif
bool LRF_HardwareManager::cleanTH( uint8_t tID ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pSOC != NULL ) {
uint32_t *thPtr;
thPtr = m_pSOC->getTH_MEMORY();
@ -2360,6 +2412,9 @@ bool LRF_HardwareManager::cleanTH( uint8_t tID ){
};
};
return false;
#else //#ifndef ONPC_TOTTAL_SIMULATOR
return true;
#endif //#ifndef ONPC_TOTTAL_SIMULATOR
};
void LRF_HardwareManager::saveCurrentParameters( void ){

13
lib/App/3dSERVER/LRF_HardwareManager.h

@ -124,7 +124,9 @@ class LRF_HardwareManager {
uint32_t m_iDataIndex;
uint32_t m_nKernelFilter;
void *m_vMemoryBlock[4];
#ifndef ONPC_TOTTAL_SIMULATOR
classSOC *m_pSOC;
#endif
bool performFlip();
uint8_t m_bTHSteadyCounter[KERNEL_COUNT];
@ -145,21 +147,26 @@ class LRF_HardwareManager {
bool m_bFlipUnlockRequested;
bool m_bWaitFirstFlip;
#endif
#ifdef THREADED_MOTORS_START
#ifndef ONPC_TOTTAL_SIMULATOR
#ifdef THREADED_MOTORS_START
pthread_t *m_pMotorCtrlThreadHandler;
static void *m_fMotorStartThreadFunction(void *);
static void *m_fMotorStopThreadFunction(void *);
pthread_mutex_t *m_pMotorCtrlMutex;
void performStartMotors( void );
void performStopMotors( void );
#endif
#endif
public:
// Constructor
explicit LRF_HardwareManager( config_setting_t *SNode = NULL );
// Destructor
virtual ~LRF_HardwareManager();
#ifndef ONPC_TOTTAL_SIMULATOR
bool isSitara( void ){ return m_eSOC>SOC_UNKNOWN; };
#else
bool isSitara( void ){ return true; };
#endif
bool isMaster( void ){ return (bool)m_sPARAMETERS.flags.isMaster; };
bool getDetectionStatus( DT_STATUS &Status );
@ -178,8 +185,10 @@ class LRF_HardwareManager {
bool create( HW_PARAMS &HardwareSettings );
bool create( config_setting_t *SNode );
bool validateCores( void );
#ifndef ONPC_TOTTAL_SIMULATOR
bool startMotors( bool Auto = true );
bool stopMotors( bool Auto = true );
#endif
void setKernelFilter( uint32_t KF ){ m_nKernelFilter = KF; };
#ifdef HIBERNATE_ENABLE
bool saveHibernatedTH( CSTR fname = "hibernate.dat" );

8
lib/App/3dSERVER/LRF_Kernel.cpp

@ -761,17 +761,25 @@ bool LRF_Kernel::shutdown( bool Restart ){
};
bool LRF_Kernel::stopMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->stopMotors( false );
};
return false;
#else
return true;
#endif
};
bool LRF_Kernel::startMotors( void ){
#ifndef ONPC_TOTTAL_SIMULATOR
if( m_pHardwareManager!= NULL ) {
return m_pHardwareManager->startMotors( false );
};
return false;
#else
return true;
#endif
};

14
lib/App/3dSERVER/LRF_SafeShoreHandler.cpp

@ -32,18 +32,30 @@ void LRF_SafeShoreHandler::m_fThreadProc( void ){
StatusUpdate();
//m_lCycleCounter == 0;
};
/* No need for Time Sync
if( m_llTicks % 350 == 0 ) { // each 35 seconds
StartTimeSynch();
//m_lCycleCounter == 0;
};
*/
SLEEP(100);
};
};
void LRF_SafeShoreHandler::dispatchEvent( basicEvent *Evt ){
#ifdef DEBUG
LOG( "CLIENT's DISPATCHER");
if( Evt == NULL ) return;
#endif
if( Evt == NULL ) {
LOG( "Evt NULL");
return;
};
if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
#ifdef DEBUG
char tBuffer[256];
sprintf( tBuffer, "Event Class %d Type %d ", Evt->m_eClass , Evt->m_eType );
LOG( tBuffer );
#endif
switch( Evt->m_eType ) {
case EVT_TARGET_WHITE:
case EVT_TARGET_BLACK:

12
lib/data/curl/curlRequestsManager.cpp

@ -47,9 +47,9 @@ DWORD WINAPI curlRequestsManager::m_fReaperEntryPoint( LPVOID ptr){
int mStillRunning;
mThis = (curlRequestsManager *)ptr;
SLOG("Reaper Thread Entry Point Enter.");
mThis->m_bThreadStatus = 2;
while (mThis->m_bThreadStatus < 3){
SLOG("Starting Finished Requests Reaper");
mThis->m_bThreadStatus = TH_WORKING;
while (mThis->m_bThreadStatus < TH_ENDED ){
/* we start some action by calling perform right away */
curl_multi_perform( mThis->m_pCURLM, &mStillRunning );
@ -58,7 +58,7 @@ DWORD WINAPI curlRequestsManager::m_fReaperEntryPoint( LPVOID ptr){
curl_multi_timeout( mThis->m_pCURLM, &mCURLTimeOut );
if (mCURLTimeOut < 0) mCURLTimeOut = 1000;
if ( mCURLTimeOut < 0 ) mCURLTimeOut = 1000;
mTimeOut.tv_sec = mCURLTimeOut / 1000;
mTimeOut.tv_usec = (mCURLTimeOut % 1000) * 1000;
@ -109,7 +109,7 @@ DWORD WINAPI curlRequestsManager::m_fReaperEntryPoint( LPVOID ptr){
};
};
};
SLOG("Reaper Thread Entry Point Exit.");
SLOG("Ending Finished Requests Reaper");
#ifdef __linux__
pthread_exit(NULL);
return NULL;
@ -140,7 +140,7 @@ DWORD WINAPI curlRequestsManager::m_fRequestEntryPoint(LPVOID ptr){
bool curlRequestsManager::get(curlRequest *RC){
if (RC != NULL){
CURLMcode RetCode;
//LOG("Get Request.");
LOG("New Request");
m_vRequestPool.push_back(RC);
RetCode = curl_multi_add_handle( m_pCURLM, RC->getEH());
/*

2
lib/data/curl/curlRequestsManager.h

@ -2,7 +2,7 @@
#define __CURLREQUESTSMANAGER_H_INCL__
#include "curlRequest.h"
#include "../../components/base/basicThread.h"
/**
* TODO: Add class description
*

4
lib/data/protocol/protocolHTTP.cpp

@ -29,7 +29,7 @@ bool protocolHTTP::issueGet(CSTR URL){
if (tRequest != NULL){
tRequest->setHandler(this, &protocolHTTP::requestFinished, tRequest);
if (m_pHttpAccessManager->get(tRequest)){
//LOG("GET Req");
LOG("GET Req");
} else {
LOG_ERROR("Cannot issue request!");
};
@ -43,7 +43,7 @@ bool protocolHTTP::issuePost(CSTR URL, char *Buffer, int &BufferSize ){
tRequest->setPOST( Buffer, BufferSize );
tRequest->setHandler(this, &protocolHTTP::requestFinished, tRequest );
if (m_pHttpAccessManager->get(tRequest)){
//LOG("POST Req");
LOG("POST Req");
} else {
LOG_ERROR("Cannot issue request!");
};

1
lib/data/protocol/protocolSafeShore.cpp

@ -375,6 +375,7 @@ bool protocolSafeShore::Alarm3D( int Angle1, int Angle2, int Range, int ID ){
UID = buildUniqID();
if( UID!= NULL ){
URL = buildURL( SERVICE_URL_TEMPLATE_EVENT, m_nScannerDimentions, m_pScannerName );
LOG( URL );
RetVal = buildEvent3DPackage( ( unsigned char *) Buffer, BufferSize, UID, ID, Angle1, Angle2, Range );
if( URL != NULL ){
RetVal = issuePost( URL, Buffer, BufferSize );

15
lib/hardware/soc/general/3DLRF.h

@ -28,6 +28,8 @@ typedef enum E_LRF_WORK_MODE{
#define TH_NEW_FLIP_FUNC
#define STRONG_STAT
#define TRACKER_INSTANT_TARGET
#define ONPC_TOTTAL_SIMULATOR
//#define TRACKER_FULL_COMPARE
//#define SIMULATE_TARGETS
//#define SIMULATE_FLIPS
@ -38,6 +40,15 @@ typedef enum E_LRF_WORK_MODE{
//#define SHIFT_50 683
#define TGD
#ifdef ONPC_TOTTAL_SIMULATOR
#define SIMULATE_TARGETS
#define SIMULATE_DOS_TARGETS
#define NO_MOTORS
#define NO_SOC
#define NO_PRU
#undef TGD
#define PRU_SLAVE
#endif
#ifdef TGD
#define ENCODER_8192
@ -52,13 +63,13 @@ typedef enum E_LRF_WORK_MODE{
#endif
#ifdef SIMULATE_TARGETS
#define SIMULATE_DOS_TARGETS
//#define SIMULATE_DOS_TARGETS
#endif
#define MINIMAL_DISTANCE_ADC 400 //~30 meters
//#define NO_MOTORS
#define PRU_SLAVE
//#define PRU_SLAVE
#ifndef ENCODER_8192
#define ENCODER_7200

24
lib/hardware/soc/modules/pru/pru_ss.c

@ -532,26 +532,42 @@ bool pru_save( uint8_t system, uint8_t unit, char *fileName ){
if( pru_disable( system, unit ) ) {
if( c_pIRAM != NULL ) {
ssize_t rCount;
printf( " Save image from PRU IRAM 0x%08x\n",( uint32_t )c_pIRAM );
#ifdef __x86_64__
printf( " Save image from PRU IRAM 0x%016x\n",( uint64_t )c_pIRAM );
#else
printf( " Save image from PRU IRAM 0x%08x\n",( uint32_t )c_pIRAM );
#endif
rCount = write( mFID, (void *)c_pIRAM, IRAM_SIZE );
if( rCount != IRAM_SIZE ) {
close( mFID );
return false;
};
printf( " Save image from PRU RAM0 0x%08x\n",( uint32_t )c_pRAM0 );
#ifdef __x86_64__
printf( " Save image from PRU RAM0 0x%016x\n",( uint64_t )c_pRAM0 );
#else
printf( " Save image from PRU RAM0 0x%08x\n",( uint32_t )c_pRAM0 );
#endif
rCount = write( mFID, (void *)c_pRAM0, RAM0_SIZE );
if( rCount != RAM0_SIZE ) {
close( mFID );
return false;
};
#ifdef SAVE_WITH_REGS
printf( " Save image from PRUSS CONF 0x%08x\n",( uint32_t )c_pPRUSS );
#ifdef __x86_64__
printf( " Save image from PRUSS CONF 0x%016x\n",( uint64_t )c_pPRUSS );
#else
printf( " Save image from PRUSS CONF 0x%08x\n",( uint32_t )c_pPRUSS );
#endif
rCount = write( mFID, (void *)c_pPRUSS, sizeof( pruCfg ) );
if( rCount != sizeof( pruCfg ) ) {
close( mFID );
return false;
};
printf( " Save image from PRU CONF 0x%08x\n",( uint32_t )c_pPRU );
#ifdef __x86_64__
printf( " Save image from PRU CONF 0x%016x\n",( uint64_t )c_pPRU );
#else
printf( " Save image from PRU CONF 0x%08x\n",( uint32_t )c_pPRU );
#endif
rCount = write( mFID, (void *)c_pPRU, sizeof( pruCtrl ) );
if( rCount != sizeof( pruCtrl ) ) {
close( mFID );

Loading…
Cancel
Save