1/* $Id: upnpcommands.h,v 1.29 2014/06/10 09:44:08 nanard Exp $ */
2/* Miniupnp project : http://miniupnp.free.fr/
3 * Author : Thomas Bernard
4 * Copyright (c) 2005-2014 Thomas Bernard
5 * This software is subject to the conditions detailed in the
6 * LICENCE file provided within this distribution */
7#ifndef UPNPCOMMANDS_H_INCLUDED
8#define UPNPCOMMANDS_H_INCLUDED
9
10#include "upnpreplyparse.h"
11#include "portlistingparse.h"
12#include "declspec.h"
13#include "miniupnpctypes.h"
14
15/* MiniUPnPc return codes : */
16#define UPNPCOMMAND_SUCCESS (0)
17#define UPNPCOMMAND_UNKNOWN_ERROR (-1)
18#define UPNPCOMMAND_INVALID_ARGS (-2)
19#define UPNPCOMMAND_HTTP_ERROR (-3)
20#define UPNPCOMMAND_INVALID_RESPONSE (-4)
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26MINIUPNP_LIBSPEC UNSIGNED_INTEGER
27UPNP_GetTotalBytesSent(const char * controlURL,
28					const char * servicetype);
29
30MINIUPNP_LIBSPEC UNSIGNED_INTEGER
31UPNP_GetTotalBytesReceived(const char * controlURL,
32						const char * servicetype);
33
34MINIUPNP_LIBSPEC UNSIGNED_INTEGER
35UPNP_GetTotalPacketsSent(const char * controlURL,
36					const char * servicetype);
37
38MINIUPNP_LIBSPEC UNSIGNED_INTEGER
39UPNP_GetTotalPacketsReceived(const char * controlURL,
40					const char * servicetype);
41
42/* UPNP_GetStatusInfo()
43 * status and lastconnerror are 64 byte buffers
44 * Return values :
45 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
46 * or a UPnP Error code */
47MINIUPNP_LIBSPEC int
48UPNP_GetStatusInfo(const char * controlURL,
49			       const char * servicetype,
50				   char * status,
51				   unsigned int * uptime,
52                   char * lastconnerror);
53
54/* UPNP_GetConnectionTypeInfo()
55 * argument connectionType is a 64 character buffer
56 * Return Values :
57 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
58 * or a UPnP Error code */
59MINIUPNP_LIBSPEC int
60UPNP_GetConnectionTypeInfo(const char * controlURL,
61                           const char * servicetype,
62						   char * connectionType);
63
64/* UPNP_GetExternalIPAddress() call the corresponding UPNP method.
65 * if the third arg is not null the value is copied to it.
66 * at least 16 bytes must be available
67 *
68 * Return values :
69 * 0 : SUCCESS
70 * NON ZERO : ERROR Either an UPnP error code or an unknown error.
71 *
72 * possible UPnP Errors :
73 * 402 Invalid Args - See UPnP Device Architecture section on Control.
74 * 501 Action Failed - See UPnP Device Architecture section on Control. */
75MINIUPNP_LIBSPEC int
76UPNP_GetExternalIPAddress(const char * controlURL,
77                          const char * servicetype,
78                          char * extIpAdd);
79
80/* UPNP_GetLinkLayerMaxBitRates()
81 * call WANCommonInterfaceConfig:1#GetCommonLinkProperties
82 *
83 * return values :
84 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
85 * or a UPnP Error Code. */
86MINIUPNP_LIBSPEC int
87UPNP_GetLinkLayerMaxBitRates(const char* controlURL,
88							const char* servicetype,
89							unsigned int * bitrateDown,
90							unsigned int * bitrateUp);
91
92/* UPNP_AddPortMapping()
93 * if desc is NULL, it will be defaulted to "libminiupnpc"
94 * remoteHost is usually NULL because IGD don't support it.
95 *
96 * Return values :
97 * 0 : SUCCESS
98 * NON ZERO : ERROR. Either an UPnP error code or an unknown error.
99 *
100 * List of possible UPnP errors for AddPortMapping :
101 * errorCode errorDescription (short) - Description (long)
102 * 402 Invalid Args - See UPnP Device Architecture section on Control.
103 * 501 Action Failed - See UPnP Device Architecture section on Control.
104 * 606 Action not authorized - The action requested REQUIRES authorization and
105 *                             the sender was not authorized.
106 * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be
107 *                                   wild-carded
108 * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded
109 * 718 ConflictInMappingEntry - The port mapping entry specified conflicts
110 *                     with a mapping assigned previously to another client
111 * 724 SamePortValuesRequired - Internal and External port values
112 *                              must be the same
113 * 725 OnlyPermanentLeasesSupported - The NAT implementation only supports
114 *                  permanent lease times on port mappings
115 * 726 RemoteHostOnlySupportsWildcard - RemoteHost must be a wildcard
116 *                             and cannot be a specific IP address or DNS name
117 * 727 ExternalPortOnlySupportsWildcard - ExternalPort must be a wildcard and
118 *                                        cannot be a specific port value
119 * 728 NoPortMapsAvailable - There are not enough free ports available to
120 *                           complete port mapping.
121 * 729 ConflictWithOtherMechanisms - Attempted port mapping is not allowed
122 *                                   due to conflict with other mechanisms.
123 * 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded
124 */
125MINIUPNP_LIBSPEC int
126UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
127		    const char * extPort,
128		    const char * inPort,
129		    const char * inClient,
130		    const char * desc,
131		    const char * proto,
132		    const char * remoteHost,
133		    const char * leaseDuration);
134
135/* UPNP_AddAnyPortMapping()
136 * if desc is NULL, it will be defaulted to "libminiupnpc"
137 * remoteHost is usually NULL because IGD don't support it.
138 *
139 * Return values :
140 * 0 : SUCCESS
141 * NON ZERO : ERROR. Either an UPnP error code or an unknown error.
142 *
143 * List of possible UPnP errors for AddPortMapping :
144 * errorCode errorDescription (short) - Description (long)
145 * 402 Invalid Args - See UPnP Device Architecture section on Control.
146 * 501 Action Failed - See UPnP Device Architecture section on Control.
147 * 606 Action not authorized - The action requested REQUIRES authorization and
148 *                             the sender was not authorized.
149 * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be
150 *                                   wild-carded
151 * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded
152 * 728 NoPortMapsAvailable - There are not enough free ports available to
153 *                           complete port mapping.
154 * 729 ConflictWithOtherMechanisms - Attempted port mapping is not allowed
155 *                                   due to conflict with other mechanisms.
156 * 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded
157 */
158MINIUPNP_LIBSPEC int
159UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
160		       const char * extPort,
161		       const char * inPort,
162		       const char * inClient,
163		       const char * desc,
164		       const char * proto,
165		       const char * remoteHost,
166		       const char * leaseDuration,
167		       char * reservedPort);
168
169/* UPNP_DeletePortMapping()
170 * Use same argument values as what was used for AddPortMapping().
171 * remoteHost is usually NULL because IGD don't support it.
172 * Return Values :
173 * 0 : SUCCESS
174 * NON ZERO : error. Either an UPnP error code or an undefined error.
175 *
176 * List of possible UPnP errors for DeletePortMapping :
177 * 402 Invalid Args - See UPnP Device Architecture section on Control.
178 * 606 Action not authorized - The action requested REQUIRES authorization
179 *                             and the sender was not authorized.
180 * 714 NoSuchEntryInArray - The specified value does not exist in the array */
181MINIUPNP_LIBSPEC int
182UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
183		       const char * extPort, const char * proto,
184		       const char * remoteHost);
185
186/* UPNP_DeletePortRangeMapping()
187 * Use same argument values as what was used for AddPortMapping().
188 * remoteHost is usually NULL because IGD don't support it.
189 * Return Values :
190 * 0 : SUCCESS
191 * NON ZERO : error. Either an UPnP error code or an undefined error.
192 *
193 * List of possible UPnP errors for DeletePortMapping :
194 * 606 Action not authorized - The action requested REQUIRES authorization
195 *                             and the sender was not authorized.
196 * 730 PortMappingNotFound - This error message is returned if no port
197 *			     mapping is found in the specified range.
198 * 733 InconsistentParameters - NewStartPort and NewEndPort values are not consistent. */
199MINIUPNP_LIBSPEC int
200UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
201        		    const char * extPortStart, const char * extPortEnd,
202        		    const char * proto,
203        		    const char * manage);
204
205/* UPNP_GetPortMappingNumberOfEntries()
206 * not supported by all routers */
207MINIUPNP_LIBSPEC int
208UPNP_GetPortMappingNumberOfEntries(const char* controlURL,
209                                   const char* servicetype,
210                                   unsigned int * num);
211
212/* UPNP_GetSpecificPortMappingEntry()
213 *    retrieves an existing port mapping
214 * params :
215 *  in   extPort
216 *  in   proto
217 *  in   remoteHost
218 *  out  intClient (16 bytes)
219 *  out  intPort (6 bytes)
220 *  out  desc (80 bytes)
221 *  out  enabled (4 bytes)
222 *  out  leaseDuration (16 bytes)
223 *
224 * return value :
225 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
226 * or a UPnP Error Code.
227 *
228 * List of possible UPnP errors for _GetSpecificPortMappingEntry :
229 * 402 Invalid Args - See UPnP Device Architecture section on Control.
230 * 501 Action Failed - See UPnP Device Architecture section on Control.
231 * 606 Action not authorized - The action requested REQUIRES authorization
232 *                             and the sender was not authorized.
233 * 714 NoSuchEntryInArray - The specified value does not exist in the array.
234 */
235MINIUPNP_LIBSPEC int
236UPNP_GetSpecificPortMappingEntry(const char * controlURL,
237                                 const char * servicetype,
238                                 const char * extPort,
239                                 const char * proto,
240                                 const char * remoteHost,
241                                 char * intClient,
242                                 char * intPort,
243                                 char * desc,
244                                 char * enabled,
245                                 char * leaseDuration);
246
247/* UPNP_GetGenericPortMappingEntry()
248 * params :
249 *  in   index
250 *  out  extPort (6 bytes)
251 *  out  intClient (16 bytes)
252 *  out  intPort (6 bytes)
253 *  out  protocol (4 bytes)
254 *  out  desc (80 bytes)
255 *  out  enabled (4 bytes)
256 *  out  rHost (64 bytes)
257 *  out  duration (16 bytes)
258 *
259 * return value :
260 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
261 * or a UPnP Error Code.
262 *
263 * Possible UPNP Error codes :
264 * 402 Invalid Args - See UPnP Device Architecture section on Control.
265 * 606 Action not authorized - The action requested REQUIRES authorization
266 *                             and the sender was not authorized.
267 * 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds
268 */
269MINIUPNP_LIBSPEC int
270UPNP_GetGenericPortMappingEntry(const char * controlURL,
271                                const char * servicetype,
272								const char * index,
273								char * extPort,
274								char * intClient,
275								char * intPort,
276								char * protocol,
277								char * desc,
278								char * enabled,
279								char * rHost,
280								char * duration);
281
282/* UPNP_GetListOfPortMappings()      Available in IGD v2
283 *
284 *
285 * Possible UPNP Error codes :
286 * 606 Action not Authorized
287 * 730 PortMappingNotFound - no port mapping is found in the specified range.
288 * 733 InconsistantParameters - NewStartPort and NewEndPort values are not
289 *                              consistent.
290 */
291MINIUPNP_LIBSPEC int
292UPNP_GetListOfPortMappings(const char * controlURL,
293                           const char * servicetype,
294                           const char * startPort,
295                           const char * endPort,
296                           const char * protocol,
297                           const char * numberOfPorts,
298                           struct PortMappingParserData * data);
299
300/* IGD:2, functions for service WANIPv6FirewallControl:1 */
301MINIUPNP_LIBSPEC int
302UPNP_GetFirewallStatus(const char * controlURL,
303				const char * servicetype,
304				int * firewallEnabled,
305				int * inboundPinholeAllowed);
306
307MINIUPNP_LIBSPEC int
308UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype,
309                    const char * remoteHost,
310                    const char * remotePort,
311                    const char * intClient,
312                    const char * intPort,
313                    const char * proto,
314                    int * opTimeout);
315
316MINIUPNP_LIBSPEC int
317UPNP_AddPinhole(const char * controlURL, const char * servicetype,
318                    const char * remoteHost,
319                    const char * remotePort,
320                    const char * intClient,
321                    const char * intPort,
322                    const char * proto,
323                    const char * leaseTime,
324                    char * uniqueID);
325
326MINIUPNP_LIBSPEC int
327UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
328                    const char * uniqueID,
329                    const char * leaseTime);
330
331MINIUPNP_LIBSPEC int
332UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID);
333
334MINIUPNP_LIBSPEC int
335UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
336                                 const char * uniqueID, int * isWorking);
337
338MINIUPNP_LIBSPEC int
339UPNP_GetPinholePackets(const char * controlURL, const char * servicetype,
340                                 const char * uniqueID, int * packets);
341
342#ifdef __cplusplus
343}
344#endif
345
346#endif
347
348