2022-05-19 02:23:40 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2021-2022 - Roberto V. Rampim
|
|
|
|
*
|
|
|
|
* RetroArch 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 Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch 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 RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2018-05-12 15:56:33 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-19 02:23:40 +00:00
|
|
|
#ifndef __RARCH_NATT_H
|
|
|
|
#define __RARCH_NATT_H
|
|
|
|
|
|
|
|
#include <libretro.h>
|
|
|
|
#include <boolean.h>
|
2018-05-12 15:56:33 +00:00
|
|
|
|
|
|
|
#include <net/net_compat.h>
|
|
|
|
#include <net/net_socket.h>
|
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
enum natt_forward_type
|
2018-05-12 15:56:33 +00:00
|
|
|
{
|
2021-12-09 04:52:42 +00:00
|
|
|
NATT_FORWARD_TYPE_NONE,
|
|
|
|
NATT_FORWARD_TYPE_ANY
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Use this enum to implement a higher-level interface. */
|
|
|
|
enum nat_traversal_status
|
|
|
|
{
|
|
|
|
NAT_TRAVERSAL_STATUS_DISCOVERY,
|
|
|
|
NAT_TRAVERSAL_STATUS_SELECT_DEVICE,
|
|
|
|
NAT_TRAVERSAL_STATUS_QUERY_DEVICE,
|
|
|
|
NAT_TRAVERSAL_STATUS_EXTERNAL_ADDRESS,
|
|
|
|
NAT_TRAVERSAL_STATUS_OPEN,
|
|
|
|
NAT_TRAVERSAL_STATUS_OPENING,
|
|
|
|
NAT_TRAVERSAL_STATUS_OPENED,
|
|
|
|
NAT_TRAVERSAL_STATUS_CLOSE,
|
|
|
|
NAT_TRAVERSAL_STATUS_CLOSING,
|
|
|
|
NAT_TRAVERSAL_STATUS_CLOSED
|
2018-05-12 15:56:33 +00:00
|
|
|
};
|
|
|
|
|
2022-01-17 12:46:03 +00:00
|
|
|
struct natt_discovery
|
|
|
|
{
|
|
|
|
retro_time_t timeout;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
struct natt_device
|
|
|
|
{
|
2022-01-10 14:52:15 +00:00
|
|
|
struct sockaddr_in addr;
|
2021-12-25 12:42:22 +00:00
|
|
|
struct sockaddr_in ext_addr;
|
2022-01-10 14:52:15 +00:00
|
|
|
char desc [256];
|
|
|
|
char control [256];
|
|
|
|
char service_type[256];
|
2021-12-09 04:52:42 +00:00
|
|
|
bool busy;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct natt_request
|
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
2021-12-25 12:42:22 +00:00
|
|
|
struct natt_device *device;
|
2021-12-09 04:52:42 +00:00
|
|
|
enum socket_protocol proto;
|
|
|
|
bool success;
|
|
|
|
};
|
|
|
|
|
2022-01-10 14:52:15 +00:00
|
|
|
/* Use this struct to implement a higher-level interface. */
|
2021-12-09 04:52:42 +00:00
|
|
|
struct nat_traversal_data
|
|
|
|
{
|
|
|
|
struct natt_request request;
|
|
|
|
enum natt_forward_type forward_type;
|
|
|
|
enum nat_traversal_status status;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* natt_init:
|
|
|
|
*
|
2022-01-17 12:46:03 +00:00
|
|
|
* @discovery : Pointer to a discovery object that will be written to.
|
|
|
|
*
|
2021-12-09 04:52:42 +00:00
|
|
|
* Starts a multicast discovery for UPnP devices.
|
|
|
|
*
|
|
|
|
* Returns: true if the discovery was started.
|
|
|
|
*/
|
2022-01-17 12:46:03 +00:00
|
|
|
bool natt_init(struct natt_discovery *discovery);
|
2018-05-12 15:56:33 +00:00
|
|
|
|
2021-12-04 14:45:29 +00:00
|
|
|
/**
|
2021-12-09 04:52:42 +00:00
|
|
|
* natt_device_next:
|
|
|
|
*
|
2022-01-17 12:46:03 +00:00
|
|
|
* @discovery : Pointer to a discovery object.
|
|
|
|
* @device : Pointer to a device object that will be written to.
|
2021-12-09 04:52:42 +00:00
|
|
|
*
|
|
|
|
* Grabs the next device that has reported in to our discovery.
|
|
|
|
*
|
|
|
|
* Returns: true if we've retrieved a new device or
|
|
|
|
* if timeout has not yet been reached. If device->desc is not an empty string,
|
2022-01-17 12:46:03 +00:00
|
|
|
* a new valid device was retrieved.
|
2021-12-09 04:52:42 +00:00
|
|
|
*/
|
2022-01-17 12:46:03 +00:00
|
|
|
bool natt_device_next(struct natt_discovery *discovery,
|
|
|
|
struct natt_device *device);
|
2021-12-04 14:45:29 +00:00
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* natt_device_end:
|
|
|
|
*
|
2022-01-17 12:46:03 +00:00
|
|
|
* @discovery : Pointer to a discovery object.
|
|
|
|
*
|
2021-12-09 04:52:42 +00:00
|
|
|
* Stop checking for new devices and close the discovery socket.
|
|
|
|
*
|
|
|
|
*/
|
2022-01-17 12:46:03 +00:00
|
|
|
void natt_device_end(struct natt_discovery *discovery);
|
2018-05-12 15:56:33 +00:00
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* natt_query_device:
|
|
|
|
*
|
|
|
|
* @device : Pointer to a device to query into.
|
|
|
|
* @block : Blocks until the HTTP task is finished.
|
|
|
|
*
|
|
|
|
* Query an IGD for its service type and control URL.
|
|
|
|
*
|
|
|
|
* Returns: true if the task was successfully started.
|
|
|
|
* If both device->service_type and device->control are not empty strings,
|
|
|
|
* the task completed successfully.
|
|
|
|
*/
|
|
|
|
bool natt_query_device(struct natt_device *device, bool block);
|
2018-05-12 15:56:33 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-09 04:52:42 +00:00
|
|
|
* natt_external_address:
|
|
|
|
*
|
|
|
|
* @device : Pointer to a device to retrieve its external address.
|
|
|
|
* @block : Blocks until the HTTP task is finished.
|
|
|
|
*
|
|
|
|
* Retrieve the external IP address of an IGD.
|
2022-01-17 12:46:03 +00:00
|
|
|
* natt_query_device must have been successfully called.
|
2021-12-09 04:52:42 +00:00
|
|
|
*
|
|
|
|
* Returns: true if the task was successfully started.
|
|
|
|
* If device->ext_addr.sin_family is AF_INET,
|
|
|
|
* the task completed successfully.
|
|
|
|
*/
|
|
|
|
bool natt_external_address(struct natt_device *device, bool block);
|
2018-05-12 15:56:33 +00:00
|
|
|
|
2021-12-04 14:45:29 +00:00
|
|
|
/**
|
2021-12-09 04:52:42 +00:00
|
|
|
* natt_open_port:
|
|
|
|
*
|
|
|
|
* @device : Pointer to a device to forward a port.
|
|
|
|
* @request : Port forwarding request information.
|
|
|
|
* @forward_type : UPnP port forwarding command type.
|
|
|
|
* @block : Blocks until the HTTP task is finished.
|
|
|
|
*
|
|
|
|
* Forward a port.
|
2022-01-17 12:46:03 +00:00
|
|
|
* natt_query_device must have been successfully called.
|
2021-12-09 04:52:42 +00:00
|
|
|
*
|
|
|
|
* Returns: true if the task was successfully started.
|
|
|
|
* If request->success is true, the task completed successfully.
|
|
|
|
*/
|
|
|
|
bool natt_open_port(struct natt_device *device,
|
|
|
|
struct natt_request *request, enum natt_forward_type forward_type,
|
|
|
|
bool block);
|
2021-12-04 14:45:29 +00:00
|
|
|
|
2021-12-09 04:52:42 +00:00
|
|
|
/**
|
|
|
|
* natt_close_port:
|
|
|
|
*
|
|
|
|
* @device : Pointer to a device to unforward a port.
|
|
|
|
* @request : Port unforwarding request information.
|
|
|
|
* @block : Blocks until the HTTP task is finished.
|
|
|
|
*
|
|
|
|
* Unforward a port.
|
2022-01-17 12:46:03 +00:00
|
|
|
* natt_query_device must have been successfully called.
|
2021-12-09 04:52:42 +00:00
|
|
|
*
|
|
|
|
* Returns: true if the task was successfully started.
|
|
|
|
* If request->success is true, the task completed successfully.
|
|
|
|
*/
|
|
|
|
bool natt_close_port(struct natt_device *device,
|
|
|
|
struct natt_request *request, bool block);
|
2018-05-12 15:56:33 +00:00
|
|
|
|
2022-05-19 02:23:40 +00:00
|
|
|
#endif /* __RARCH_NATT_H */
|