2017-03-30 17:53:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2016,2017 Maschell
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef _TCPSERVER_WINDOW_H_
|
|
|
|
#define _TCPSERVER_WINDOW_H_
|
|
|
|
|
|
|
|
#include "../utils/ControllerPatcherThread.hpp"
|
|
|
|
#include "dynamic_libs/socket_functions.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
|
2017-04-10 15:39:58 +02:00
|
|
|
#define WIIU_CP_TCP_HANDSHAKE WIIU_CP_TCP_HANDSHAKE_VERSION_2
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_MIN WIIU_CP_TCP_HANDSHAKE_VERSION_1
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_MAX WIIU_CP_TCP_HANDSHAKE_VERSION_2
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_1 0x12
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_VERSION_2 0x13
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_HANDSHAKE_ABORT 0x30
|
|
|
|
|
|
|
|
#define ATTACH 0x01
|
|
|
|
#define DETACH 0x00
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_ATTACH 0x01
|
|
|
|
#define WIIU_CP_TCP_DETACH 0x02
|
|
|
|
#define WIIU_CP_TCP_PING 0xF0
|
|
|
|
#define WIIU_CP_TCP_PONG 0xF1
|
|
|
|
|
|
|
|
#define WIIU_CP_TCP_ATTACH_CONFIG_FOUND 0xE0
|
|
|
|
#define WIIU_CP_TCP_ATTACH_CONFIG_NOT_FOUND 0xE1
|
|
|
|
#define WIIU_CP_TCP_ATTACH_USER_DATA_OKAY 0xE8
|
|
|
|
#define WIIU_CP_TCP_ATTACH_USER_DATA_BAD 0xE9
|
|
|
|
|
2017-03-30 17:53:36 +02:00
|
|
|
#define DEFAULT_TCP_PORT 8112
|
|
|
|
|
|
|
|
class TCPServer{
|
|
|
|
friend class ControllerPatcher;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static TCPServer *getInstance() {
|
|
|
|
if(!instance)
|
|
|
|
instance = new TCPServer(DEFAULT_TCP_PORT);
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroyInstance() {
|
|
|
|
if(instance){
|
|
|
|
delete instance;
|
|
|
|
instance = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
TCPServer(s32 port);
|
2017-03-30 17:53:36 +02:00
|
|
|
~TCPServer();
|
|
|
|
|
|
|
|
void CloseSockets();
|
|
|
|
void ErrorHandling();
|
|
|
|
|
|
|
|
void StartTCPThread(TCPServer * server);
|
|
|
|
static void DoTCPThread(ControllerPatcherThread *thread, void *arg);
|
|
|
|
void DoTCPThreadInternal();
|
|
|
|
static void DetachConnectedNetworkController();
|
2017-04-10 11:00:55 +02:00
|
|
|
static void AttachDetach(s32 attach);
|
2017-03-30 17:53:36 +02:00
|
|
|
void DetachAndDelete();
|
|
|
|
static TCPServer *instance;
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
s32 RunTCP();
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
struct sockaddr_in sock_addr;
|
2017-04-10 11:00:55 +02:00
|
|
|
volatile s32 sockfd = -1;
|
|
|
|
volatile s32 clientfd = -1;
|
2017-03-30 17:53:36 +02:00
|
|
|
|
|
|
|
|
2017-04-10 11:00:55 +02:00
|
|
|
volatile s32 exitThread = 0;
|
2017-03-30 17:53:36 +02:00
|
|
|
static ControllerPatcherThread *pThread;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_TCPSERVER_WINDOW_H_
|