NetTunnelWindows/NetTunnelSDK/include/tunnel.h

289 lines
10 KiB
C
Raw Normal View History

2023-06-15 01:35:37 +00:00
#pragma once
#include "common.h"
2023-06-15 01:35:37 +00:00
#include <Windows.h>
#ifdef NETTUNNELSDK_EXPORTS
#define TUNNEL_API __declspec(dllexport)
2023-06-15 01:35:37 +00:00
#else
#define TUNNEL_API __declspec(dllimport)
2023-06-15 01:35:37 +00:00
#endif
/**
* @brief
*
*/
typedef enum {
ICS_SHARE_MODE = 0, ///< Internet Share Mode(ICS) 模式
NAT_SHARE_MODE = 1 ///< Net Address Translation(NAT) 模式
} NET_SHARE_MODE;
typedef struct {
CHECK_FUNCTION chk;
bool result;
TCHAR errMsg[MAX_PATH];
} CHK_RESULT, *PCHK_RESULT;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
int ListenPort; ///< WireGuard 服务端监听端口
// 根据系统设计,不支持多个客户端同时连接
TCHAR CliPubKey[64]; ///< WireGuard 客户端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
} WGSERVER_CONFIG, *PWGSERVER_CONFIG;
/**
* @brief WireGuard
*/
typedef struct {
TCHAR Name[64]; ///< WireGuard 网卡名称
TCHAR PrivateKey[64]; ///< WireGuard 本机私钥
TCHAR Address[32]; ///< WireGuard 本地网络IP地址
// Peer Server
TCHAR SvrPubKey[64]; ///< WireGuard 服务端公钥
TCHAR AllowNet[256]; ///< WireGuard 允许对端访问本地网络的配置
TCHAR ServerURL[256]; ///< WireGuard 服务端IP地址和端口
} WGCLIENT_CONFIG, *PWGCLIENT_CONFIG;
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus // If used by C++ code,
extern "C" {
// we need to export the C interface
#endif
/**
* @brief
* @return @see NET_SHARE_MODE
*/
TUNNEL_API NET_SHARE_MODE __cdecl GetCurrentNetShareMode();
/**
* @brief
* @param shareMode @see NET_SHARE_MODE
*/
TUNNEL_API void __cdecl SetCurrentNetShareMode(NET_SHARE_MODE shareMode);
/**
* @brief SDK
* @param[in] pWorkDir
* @param[in] pSvrUrl URL example: http://localhost:2313, https://localhost:2313
* @param[in] pLogFile /
* @param[in] level
* @param[in] isWorkServer SDK
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_ITEM_EXISTS WireGuard
* - -ERR_SYS_CALL
* - -ERR_CREATE_FILE
* - -ERR_ITEM_UNEXISTS WireGuard
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl TunnelSDKInitEnv(const TCHAR *pWorkDir,
const TCHAR *pSvrUrl,
const TCHAR *pLogFile,
LOG_LEVEL level,
bool isWorkServer);
/**
* @brief CRYPTO_NONE
* @param[in] type @see PROTO_CRYPTO_TYPE
* @param[in] pProKey CRYPTO_NONE CRYPTO_BASE64
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl SetProtocolEncryptType(const PROTO_CRYPTO_TYPE type, const TCHAR *pProKey);
/**
* @brief / SDK
* @param enLog
* - TRUE
* - FALSE
*/
TUNNEL_API void __cdecl TunnelLogEnable(bool enLog);
/**
* @brief WireGuard
* @param[in] pWgConfig @see WGSERVER_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardCreateServerConfig(const PWGSERVER_CONFIG pWgConfig);
/**
* @brief WireGuard
* @param[in] pWgConfig @see WGCLIENT_CONFIG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - -ERR_OPEN_FILE
* - -ERR_MEMORY_STR
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardCreateClientConfig(const PWGCLIENT_CONFIG pWgConfig);
/**
* @brief WireGuard
* @param pInterfaceName
* @param pWGConfigFilePath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_OPEN_SCM
* - -ERR_OPEN_SERVICE
* - -ERR_CREATE_SERVICE
* - -ERR_CONFIG_SERVICE
* - -ERR_START_SERVICE
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl CreateWireGuardService(const TCHAR *pInterfaceName, const TCHAR *pWGConfigFilePath);
/**
* @brief WireGuard
* @param pTunnelName
* @param pIsRunning pIsRunning WireGuard
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_SCM
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetWireGuardServiceStatus(const TCHAR *pTunnelName, bool *pIsRunning);
TUNNEL_API int __cdecl GetWireGuradTunnelInfo(const TCHAR *pTunnelName);
/**
* @brief WireGuard
* @param pTunnelName
* @param bIsWaitStop TRUE: , FALSE:
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_SCM
* - -ERR_OPEN_SERVICE
* - -ERR_STOP_SERVICE
* - -ERR_DELETE_SERVICE
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl RemoveGuardService(const TCHAR *pTunnelName, bool bIsWaitStop);
/**
* @brief / WireGuard
* @param[in] bInstall TRUE , FALSE
* @return 0: 0 @see USER_ERRNO
*/
TUNNEL_API int __cdecl WireGuardInstallDefaultServerService(bool bInstall);
/**
* @brief WireGuard
* @param[in] pTunnelCfgPath
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL WireGuard
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardInstallServerService(const TCHAR *pTunnelCfgPath);
/**
* @brief WireGuard
* @param[in] pTunnelName
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_CALL_SHELL WireGuard
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl WireGuardUnInstallServerService(const TCHAR *pTunnelName);
/**
* @brief /
* @param[out] pIsWorkServer
* - TRUE
* - FALSE
2023-06-21 10:04:16 +00:00
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl GetWireGuardWorkMode(bool *pIsWorkServer);
2023-06-21 10:04:16 +00:00
/**
* @brief WireGuard
* @param[out] pIsInstalled WireGuard
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_OPEN_SCM,
* - -ERR_OPEN_SERVICE,
* - -ERR_GET_SERVICESSTATUS,
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsWireGuardServerInstalled(bool *pIsInstalled);
/**
* @brief WireGuard
* @param[in] pIfName WireGuard
* @param[out] pIsRunning WireGuard
* - TRUE
* - FALSE
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_MALLOC_MEMORY
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl IsWireGuardServerRunning(const TCHAR *pIfName, bool *pIsRunning);
/**
* @brief SDK
*/
TUNNEL_API void __cdecl TunnelSDKUnInit();
/**
* @brief SCG
* @param isEnable TRUE: SCG , FALSE: SCG
* @param pSCGIpAddr SCG IP
* @param scgPort SCG
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl EnableSCGProxy(bool isEnable, const TCHAR* pSCGIpAddr, int scgPort);
/**
* @brief SCG
* @return TRUE: SCG , FALSE: SCG
*/
TUNNEL_API bool __cdecl UsedSCGProxy();
/**
* @brief Hash
* @param[in] type Hash @see HASH_TYPE
* @param[in] pPath Hash
* @param[out] outHash
* @return 0: 0 @see USER_ERRNO
* - -ERR_INPUT_PARAMS
* - -ERR_ITEM_UNEXISTS
* - -ERR_OPEN_FILE
* - -ERR_BCRYPT_OPEN
* - -ERR_BCRYPT_GETPROPERTY
* - -ERR_BCRYPT_CREATEHASH Hash
* - -ERR_BCRYPT_HASHDATA Hash
* - -ERR_BCRYPT_FINISHHASH Hash
* - ERR_SUCCESS
*/
TUNNEL_API int __cdecl CalcFileHash(const HASH_TYPE type, const TCHAR *pPath, TCHAR outHash[]);
2023-06-15 01:35:37 +00:00
#ifdef __cplusplus
}
#endif