IOTC Platform  Ver: 4.3.6.2-0-ge1f616e
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
P2PTunnelAgent.h File Reference
#include "P2PTunnelCommon.h"

Typedefs

typedef void(__stdcall * tunnelAgentAuthCB )(char *cszAccount, uint32_t nAccountMaxLength, char *cszPassword, uint32_t nPasswordMaxLength, const void *pArg)
 

Functions

TUNNEL_API_DEPRECATED int32_t P2PTunnelAgentInitialize (uint32_t nMaxConnection)
 Initialize P2PTunnel module in a tunnel agent.
 
TUNNEL_API int32_t P2PTunnelAgentInitialize2 (uint32_t nMaxConnection, uint8_t bEnableLanDirect)
 Initialize P2PTunnel module in a tunnel agent.
 
TUNNEL_API int32_t P2PTunnelAgentDeInitialize (void)
 Deinitialize P2PTunnel module in a tunnel agent.
 
TUNNEL_API int32_t P2PTunnelAgent_GetFreeSession (void)
 Used by an agent to get a free session ID.
 
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Connect (const char *cszUID, const void *cpAuthData, int32_t nAuthDataLength, int32_t *pnErrFromDeviceCB)
 Connect to a tunnel server.
 
TUNNEL_API int32_t P2PTunnelAgent_Connect_Ex (const char *cszUID, tunnelAgentAuthCB pfxTunnelAgentAuthFn, const void *pArg)
 Connect to a tunnel server with DTLS mode.
 
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Attach_Connect (const int32_t SID, const int32_t CHID, const void *cpAuthData, int32_t nAuthDataLength, int32_t *pnErrFromDeviceCB)
 Use the existed IOTC session to request P2PTunnel connection.
 
TUNNEL_API int32_t P2PTunnelAgent_Attach_Connect_Ex (int32_t SID, int32_t CHID, tunnelAgentAuthCB pfxTunnelAgentAuthFn, const void *pArg)
 Use the existed IOTC session to request P2PTunnel connection with DTLS mode.
 
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Connect_Parallel (const char *cszUID, const int32_t SID, const void *cpAuthData, int32_t nAuthDataLength, int32_t *pnErrFromDeviceCB)
 Connect to a tunnel server and bind to a specified session ID.
 
TUNNEL_API int32_t P2PTunnelAgent_Connect_Parallel_Ex (const char *cszUID, int32_t SID, tunnelAgentAuthCB pfxTunnelAgentAuthFn, const void *pArg)
 Connect to a tunnel server and bind to a specified session ID with DTLS mode.
 
TUNNEL_API int32_t P2PTunnelAgent_Disconnect (int32_t nSessionID)
 Disconnect to a tunnel server.
 
TUNNEL_API int32_t P2PTunnelAgent_Abort (int32_t nSessionID)
 Abort the connection with a tunnel server.
 
TUNNEL_API int32_t P2PTunnelAgent_PortMapping (int32_t nSessionID, uint16_t nLocalPort, uint16_t nRemotePort)
 Start port mapping service.
 
TUNNEL_API int32_t P2PTunnelAgent_ServiceMapping (int32_t nSessionID, uint16_t nLocalPort, const char *cszServiceID)
 Start connection for bacchus service.
 
TUNNEL_API void P2PTunnelAgent_StopPortMapping (uint32_t nPortMappingIdx)
 Stop port mapping service.
 
TUNNEL_API void P2PTunnelAgent_StopServiceMapping (uint32_t nServiceMappingIdx)
 Stop service.
 
TUNNEL_API int32_t P2PTunnelAgent_StopPortMapping_byIndexArray (uint32_t *indexArray, uint32_t indexNum)
 Stop port mapping service.
 
TUNNEL_API void P2PTunnelAgent_GetStatus (tunnelStatusCB pfxTunnelStatusFn, void *pArg)
 Used by a tunnel agent to get the tunnel status.
 
TUNNEL_API int32_t P2PTunnelAgent_Connect_Stop (const char *cszUID)
 It's to stop the progressing of connection.
 
TUNNEL_API int32_t P2PTunnelAgent_Connect_Stop_Parallel (const char *cszUID, const int32_t nSessionID)
 It's to stop the progressing of connection.
 
TUNNEL_API int32_t P2PTunnelAgent_Attach_Connect_Stop (int32_t nIOTCSessionID, int32_t nIOTCChannelID)
 It's to stop the progressing of attach.
 

Detailed Description

This file describes P2PTunnel module APIs for agent.

Typedef Documentation

typedef void(__stdcall * tunnelAgentAuthCB)(char *cszAccount, uint32_t nAccountMaxLength, char *cszPassword, uint32_t nPasswordMaxLength, const void *pArg)

The prototype of authenticating connect informations, used by a tunnel agent to be notified when connection start.

Parameters
cszAccount[out] The account input by user
nAccountMaxLength[in] Max size of cszAccount
cszPassword[out] The password input by user
nPasswordMaxLength[in] Max size of cszPassword
pArg[in] Tunnel agent pass user data
Attention
Set empty string "" to cszPassword meas reject this tunnel connection

Function Documentation

TUNNEL_API int32_t P2PTunnelAgent_Abort ( int32_t  nSessionID)

Abort the connection with a tunnel server.

This function used by a tunnel agent to disconnect to a tunnel server directly

Parameters
nSessionID[in] Which session ID of the P2PTunnel session to be disconnect
Returns
- TUNNEL_ER_NoERROR if connect successfully
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Attach_Connect ( const int32_t  SID,
const int32_t  CHID,
const void *  cpAuthData,
int32_t  nAuthDataLength,
int32_t *  pnErrFromDeviceCB 
)

Use the existed IOTC session to request P2PTunnel connection.

In order to use the same iotc session with other modules, please make sure you use different channel id for each module, for example, you can use channel 0 for AV connections and channel 1 for P2PTunnel connections

Parameters
SID[in] Base on which IOTC session id you want to build P2PTunnel connection
CHID[in] Base on which IOTC channel id you want to build P2PTunnel connection
cpAuthData[in] Send authentication data to tunnel server for connection.
nAuthDataLength[in] The length of the byte buffer. It cannot be larger than MAX_AUTH_DATA_LEN
pnErrFromDeviceCB[out] The reason why tunnel server rejects this connection. It's returned from tunnelSessionInfoCB of the tunnel server.
Returns
Tunnel Session ID if return value >= 0
Error code if return value < 0
See Also
P2PTunnelSetConnectionOption(), P2PTunnelServer_Listen()
Attention
Must be called after P2PTunnelSetConnectionOption is set as TUNNEL_CONNECT_MANUAL mode
TUNNEL_API int32_t P2PTunnelAgent_Attach_Connect_Ex ( int32_t  SID,
int32_t  CHID,
tunnelAgentAuthCB  pfxTunnelAgentAuthFn,
const void *  pArg 
)

Use the existed IOTC session to request P2PTunnel connection with DTLS mode.

In order to use the same iotc session with other modules, please make sure you use different channel id for each module, for example, you can use channel 0 for AV connections and channel 1 for P2PTunnel connections

Parameters
SID[in] Base on which IOTC session id you want to build P2PTunnel connection
CHID[in] Base on which IOTC channel id you want to build P2PTunnel connection
pfxTunnelAgentAuthFn[in] The function pointer of authenticate account function if IOTC session is crate by Nebula, this param can be NULL.
pArg[in] User can give data pointer to pass to pfxTunnelAgentAuthFn when this call back function is triggered. Can be NULL.
Returns
Tunnel Session ID if return value >= 0
Error code if return value < 0
See Also
P2PTunnelSetConnectionOption(), P2PTunnelServer_Listen()
Attention
(1) Must be called after P2PTunnelSetConnectionOption is set as TUNNEL_CONNECT_MANUAL mode (2) If IOTC session is created by Nebula, pfxTunnelAgentAuthFn will NOT invoke when this API called.
TUNNEL_API int32_t P2PTunnelAgent_Attach_Connect_Stop ( int32_t  nIOTCSessionID,
int32_t  nIOTCChannelID 
)

It's to stop the progressing of attach.

This API is for a manually agnet to stop connecting to a device. We can use it to stop connecting when client blocks in P2PTunnelAgent_Attach_Connect() or P2PTunnelAgent_Attach_Connect_Ex().

Parameters
nIOTCSessionID[in] Session ID
nIOTCChannelID[in] Channel ID
Returns
TUNNEL_ER_NoERROR if stop successfully
Error code if return value < 0
See Also
P2PTunnelAgent_Attach_Connect(), P2PTunnelAgent_Attach_Connect_Ex()
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Connect ( const char *  cszUID,
const void *  cpAuthData,
int32_t  nAuthDataLength,
int32_t *  pnErrFromDeviceCB 
)

Connect to a tunnel server.

This function used by a tunnel agent to connect the tunnel server with specified UID

Parameters
cszUID[in] The UID of that tunnel server to be connected
cpAuthData[in] Send authentication data to tunnel server for connection.
nAuthDataLength[in] The length of the byte buffer. It cannot be larger than MAX_AUTH_DATA_LEN
pnErrFromDeviceCB[out] The reason why tunnel server rejects this connection. It's returned from tunnelSessionInfoCB of the tunnel server.
Returns
Tunnel Session ID if return value >= 0
TUNNEL_ER_NoERROR if connect successfully
Error code if return value < 0
TUNNEL_API int32_t P2PTunnelAgent_Connect_Ex ( const char *  cszUID,
tunnelAgentAuthCB  pfxTunnelAgentAuthFn,
const void *  pArg 
)

Connect to a tunnel server with DTLS mode.

This function used by a tunnel agent to connect the tunnel server with specified UID

Parameters
cszUID[in] The UID of that tunnel server to be connected
pfxTunnelAgentAuthFn[in] The function pointer of authenticate account function
pArg[in] User can give data pointer to pass to pfxTunnelAgentAuthFn when this call back function is triggered. Can be NULL.
Returns
Tunnel Session ID if return value >= 0
TUNNEL_ER_NoERROR if connect successfully
Error code if return value < 0
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgent_Connect_Parallel ( const char *  cszUID,
const int32_t  SID,
const void *  cpAuthData,
int32_t  nAuthDataLength,
int32_t *  pnErrFromDeviceCB 
)

Connect to a tunnel server and bind to a specified session ID.

This function is for a tunnel agent to connect a device by specifying the UID of that device, and bind to a free session ID from P2PTunnelAgent_GetFreeSession(). If connection is established with the help of IOTC servers, the TUNNEL_ER_NoERROR will be returned in this function and then device and client can communicate for the other later by using this tunnel session ID. If this function is called by multiple threads, the connections will be processed concurrently.

Parameters
cszUID[in] The UID of that tunnel server to be connected
SID[in] The SID got from P2PTunnelAgent_GetFreeSession() the connection should bind to.
cpAuthData[in] Send authentication data to tunnel server for connection.
nAuthDataLength[in] The length of the byte buffer. It cannot be larger than MAX_AUTH_DATA_LEN
pnErrFromDeviceCB[out] The reason why tunnel server rejects this connection. It's returned from tunnelSessionInfoCB of the tunnel server.
Returns
Tunnel session ID if return value >= 0 and equal to the input parameter SID.
TUNNEL_ER_NoERROR if connect successfully
Error code if return value < 0
TUNNEL_API int32_t P2PTunnelAgent_Connect_Parallel_Ex ( const char *  cszUID,
int32_t  SID,
tunnelAgentAuthCB  pfxTunnelAgentAuthFn,
const void *  pArg 
)

Connect to a tunnel server and bind to a specified session ID with DTLS mode.

This function is for a tunnel agent to connect a device by specifying the UID of that device, and bind to a free session ID from P2PTunnelAgent_GetFreeSession(). If connection is established with the help of IOTC servers, the TUNNEL_ER_NoERROR will be returned in this function and then device and client can communicate for the other later by using this tunnel session ID. If this function is called by multiple threads, the connections will be processed concurrently.

Parameters
cszUID[in] The UID of that tunnel server to be connected
SID[in] The SID got from P2PTunnelAgent_GetFreeSession() the connection should bind to.
pfxTunnelAgentAuthFn[in] The function pointer of authenticate account function if IOTC session is crate by Nebula, this param can be NULL.
pArg[in] User can give data pointer to pass to pfxTunnelAgentAuthFn when this call back function is triggered. Can be NULL.
Returns
Tunnel session ID if return value >= 0 and equal to the input parameter SID.
TUNNEL_ER_NoERROR if connect successfully
Error code if return value < 0
Attention
If IOTC session is created by Nebula, pfxTunnelAgentAuthFn will NOT invoke when this API called.
TUNNEL_API int32_t P2PTunnelAgent_Connect_Stop ( const char *  cszUID)

It's to stop the progressing of connection.

This API is for a client to stop connecting to a device. We can use it to stop connecting when client blocks in P2PTunnelAgent_Connect_Ex().

Parameters
cszUID[in] The UID of that tunnel server
Returns
0 if success
Error code if return value < 0
TUNNEL_API int32_t P2PTunnelAgent_Connect_Stop_Parallel ( const char *  cszUID,
const int32_t  nSessionID 
)

It's to stop the progressing of connection.

This API is for a client to stop connecting to a device. We can use it to stop connecting when client blocks in P2PTunnelAgent_Connect_Parallel_Ex().

Parameters
cszUID[in] The UID of that tunnel server
nSessionID[in] Session ID
Returns
0 if success
Error code if return value < 0
TUNNEL_API int32_t P2PTunnelAgent_Disconnect ( int32_t  nSessionID)

Disconnect to a tunnel server.

This function used by a tunnel agent to disconnect to a tunnel server gracefully

Parameters
nSessionID[in] Which session ID of the P2PTunnel session to be disconnect
Returns
- TUNNEL_ER_NoERROR if connect successfully
TUNNEL_API int32_t P2PTunnelAgent_GetFreeSession ( void  )

Used by an agent to get a free session ID.

This function is for an agent to get a free session ID used for a parameter of P2PTunnelAgent_Connect_Parallel_Ex().

Returns
Tunnel Session ID if return value >= 0
Error code if return value < 0
TUNNEL_API void P2PTunnelAgent_GetStatus ( tunnelStatusCB  pfxTunnelStatusFn,
void *  pArg 
)

Used by a tunnel agent to get the tunnel status.

This function will set a callback function pointer in P2PTunnel module for a tunnel agent to get the tunnel status from given callback function. Whenever tunnel status changes, P2PTunnel module will invoke the given callback function to notify tunnel agent with corresponding status.

Parameters
pfxTunnelStatusFn[in] The function pointer to getting tunnel status function
pArg[in] User can give data pointer to pass to pfxSessionInfoFn when this call back function is triggered. Can be NULL.
TUNNEL_API int32_t P2PTunnelAgent_PortMapping ( int32_t  nSessionID,
uint16_t  nLocalPort,
uint16_t  nRemotePort 
)

Start port mapping service.

This function used by a tunnel agent to start port mapping service provided by P2PTunnel module. The tunnel agent specifies the local port in local host through which a tunnel is created with the remote port defined in the tunnel server.

Parameters
nSessionID[in] Which session ID of the P2PTunnel session to process the port mapping service
nLocalPort[in] The local port used to create a tunnel with the tunnel server
nRemotePort[in] The remote port defined in the tunnel server to create a tunnel
Returns
The port mapping index if return value >= 0
Error code if return value < 0
TUNNEL_API int32_t P2PTunnelAgent_ServiceMapping ( int32_t  nSessionID,
uint16_t  nLocalPort,
const char *  cszServiceID 
)

Start connection for bacchus service.

This function used by a tunnel agent to start connection for a bacchus service provided by P2PTunnel module. The tunnel agent specifies the local port in local host through which a tunnel is created with the service id defined in the tunnel server.

Parameters
nSessionID[in] Which session ID of the P2PTunnel session to process the port mapping service
nLocalPort[in] The local port used to create a tunnel with the tunnel server
cszServiceID[in] The remote service id defined in the tunnel server to create a tunnel. Max length is MAX_SERVICE_ID_LEN(16).
Returns
The service index if return value >= 0
Error code if return value < 0
TUNNEL_API void P2PTunnelAgent_StopPortMapping ( uint32_t  nPortMappingIdx)

Stop port mapping service.

This function used by a tunnel agent to stop port mapping service on a given port mapping index which is started by P2PTunnelAgent_PortMapping()

Parameters
nPortMappingIdx[in] The port mapping index started in P2PTunnelAgent_PortMapping()
Attention
If not call P2PTunnelAgent_StopPortMapping local port can't be used until OS release it.
TUNNEL_API int32_t P2PTunnelAgent_StopPortMapping_byIndexArray ( uint32_t *  indexArray,
uint32_t  indexNum 
)

Stop port mapping service.

This function used by a tunnel agent to stop multiple port mapping service on an integer array set of given port mapping index which is started by P2PTunnelAgent_PortMapping()

Parameters
indexArray[in] An integer array of the port mapping index in P2PTunnelAgent_PortMapping()
indexNum[in] The number of the port mapping index in indexArray
Returns
0 if success
Error code if return value < 0
Attention
If not call P2PTunnelAgent_StopPortMapping local port can't be used until OS release it.
TUNNEL_API void P2PTunnelAgent_StopServiceMapping ( uint32_t  nServiceMappingIdx)

Stop service.

This function used by a tunnel agent to stop service on a given port mapping index which is started by P2PTunnelAgent_ServiceMapping()

Parameters
nServiceMappingIdx[in] The port mapping index started in P2PTunnelAgent_ServiceMapping()
Attention
If not call P2PTunnelAgent_ServiceMapping local port can't be used until OS release it.
TUNNEL_API int32_t P2PTunnelAgentDeInitialize ( void  )

Deinitialize P2PTunnel module in a tunnel agent.

This function will deinitialize P2PTunnel module in a tunnel agent

Returns
TUNNEL_ER_NoERROR if deinitialize successfully
Error code if return value < 0
See Also
P2PTunnelAgentInitialize()
Attention
Must call P2PTunnelAgent_Disconnect() before calling this function, otherwise resource in P2PTunnel module will not be freed and connection will not be closed (the remote site will have connection timeout event eventually).
This function can't be called simultaneously from multiple threads.
TUNNEL_API_DEPRECATED int32_t P2PTunnelAgentInitialize ( uint32_t  nMaxConnection)

Initialize P2PTunnel module in a tunnel agent.

This function is used by a tunnel agent to initialize P2PTunnel module and shall be called before any P2PTunnel module related function is invoked.

Parameters
nMaxConnection[in] Specify max number of tunnel agents that can connect to tunnel servers
Returns
TUNNEL_ER_NoERROR if initializing successfully
Error code if return value < 0
See Also
P2PTunnelAgentDeInitialize()
Attention
This function can't be called simultaneously from multiple threads.
TUNNEL_API int32_t P2PTunnelAgentInitialize2 ( uint32_t  nMaxConnection,
uint8_t  bEnableLanDirect 
)

Initialize P2PTunnel module in a tunnel agent.

This function is used by a tunnel agent to initialize P2PTunnel module and shall be called before any P2PTunnel module related function is invoked.

Parameters
nMaxConnection[in] Specify max number of tunnel agents that can connect to tunnel servers
bEnableLanDirect[in] Transport data directly without TUTK forward mechanism when P2PTunnelAgent and P2PTunnelSever are on the same LAN.
Returns
TUNNEL_ER_NoERROR if initializing successfully
Error code if return value < 0
See Also
P2PTunnelAgentDeInitialize()
Attention
This function can't be called simultaneously from multiple threads.
Lan direct isn't working with service mapping.