#include <stdbool.h>
#include <arpa/inet.h>
+
#include <netinet/ether.h>
* This enum lists all the error codes the library can return to user.
**/
enum {
- ERR_OK=0, /**< no error */
- ERR_NET=-1, /**< network error */
- ERR_NOTLOG=-2, /**< not logged */
- ERR_BADPASS=-3, /**< bad password */
- ERR_BADID=-4, /**< bad switch id */
- ERR_INVARG=-5, /**< invalid argument */
- ERR_TIMEOUT=-6, /**< timeout */
- ERR_NOTIMPL=-7 /**< not implemented */
+ ERR_OK = 0, /**< no error */
+ ERR_NET = -1, /**< network error */
+ ERR_NOTLOG = -2, /**< not logged */
+ ERR_DENIED = -3, /**< access denied */
+ ERR_BADPASS = -4, /**< bad password */
+ ERR_BADID = -5, /**< bad switch id */
+ ERR_INVARG = -6, /**< invalid argument */
+ ERR_TIMEOUT = -7, /**< timeout */
+ ERR_MEM = -8, /**< out of memory */
+ ERR_NOTIMPL = -8 /**< not implemented */
};
* This enum lists all the speeds a port can have.
**/
enum {
- SPEED_DOWN=0, /**< link down */
- SPEED_10=1, /**< 10 Mb/s */
- SPEED_100=4, /**< 100 Mb/s */
- SPEED_1000=5 /**< 1000 Mb/s */
+ SPEED_UNK = -1, /**< unknown status */
+ SPEED_DOWN = 0, /**< link down */
+ SPEED_10 = 1, /**< 10 Mb/s */
+ SPEED_100 = 4, /**< 100 Mb/s */
+ SPEED_1000 = 5 /**< 1000 Mb/s */
};
* This enum lists all the VLAN types available
**/
enum {
- VLAN_DISABLED=0, /**< VLAN disabled */
- VLAN_PORT_BASIC=1, /**< port basic */
- VLAN_PORT_ADV=2, /**< port advanced */
- VLAN_DOT_BASIC=3, /**< 802.1q basic */
- VLAN_DOT_ADV=4 /**< 802.1q advanced */
+ VLAN_DISABLED = 0, /**< VLAN disabled */
+ VLAN_PORT_BASIC = 1, /**< port basic */
+ VLAN_PORT_ADV = 2, /**< port advanced */
+ VLAN_DOT_BASIC = 3, /**< 802.1q basic */
+ VLAN_DOT_ADV = 4 /**< 802.1q advanced */
};
* This enum lists all the VLAN specifications a port can have.
**/
enum {
- VLAN_UNSPEC=0xFF, /**< unspecified */
- VLAN_NO=0, /**< not present */
- VLAN_UNTAGGED=1, /**< present, untagged */
- VLAN_TAGGED=2 /**< present, tagged */
+ VLAN_UNSPEC = 0xFF, /**< unspecified */
+ VLAN_NO = 0, /**< not present */
+ VLAN_UNTAGGED = 1, /**< present, untagged */
+ VLAN_TAGGED = 2 /**< present, tagged */
};
* This enum lists all the availables QoS modes.
**/
enum {
- QOS_PORT=1, /**< port based */
- QOS_DOT=2 /**< 802.1p based */
+ QOS_PORT = 1, /**< port based */
+ QOS_DOT = 2 /**< 802.1p based */
};
* This enum lists all the priorities a port can have.
**/
enum {
- PRIO_UNSPEC=-1, /**< unspecified */
- PRIO_HIGH=1, /**< high */
- PRIO_MED=2, /**< medium */
- PRIO_NORM=3, /**< normal */
- PRIO_LOW=4 /**< low */
+ PRIO_UNSPEC = -1, /**< unspecified */
+ PRIO_HIGH = 1, /**< high */
+ PRIO_MED = 2, /**< medium */
+ PRIO_NORM = 3, /**< normal */
+ PRIO_LOW = 4 /**< low */
};
* This enum lists all the available bitrates.
**/
enum {
- BITRATE_UNSPEC=-1, /**< unspecified */
- BITRATE_NOLIMIT=0, /**< unlimited */
- BITRATE_512K=1, /**< 512 Kb/s */
- BITRATE_1M=2, /**< 1 Mb/s */
- BITRATE_2M=3, /**< 2 Mb/s */
- BITRATE_4M=4, /**< 4 Mb/s */
- BITRATE_8M=5, /**< 8 Mb/s */
- BITRATE_16M=6, /**< 16 Mb/s */
- BITRATE_32M=7, /**< 32 Mb/s */
- BITRATE_64M=8, /**< 64 Mb/s */
- BITRATE_128M=9, /**< 128 Mb/s */
- BITRATE_256M=10, /**< 256 Mb/s */
- BITRATE_512M=11 /**< 512 Mb/s */
+ BITRATE_UNSPEC = -1, /**< unspecified */
+ BITRATE_NOLIMIT = 0, /**< unlimited */
+ BITRATE_512K = 1, /**< 512 Kb/s */
+ BITRATE_1M = 2, /**< 1 Mb/s */
+ BITRATE_2M = 3, /**< 2 Mb/s */
+ BITRATE_4M = 4, /**< 4 Mb/s */
+ BITRATE_8M = 5, /**< 8 Mb/s */
+ BITRATE_16M = 6, /**< 16 Mb/s */
+ BITRATE_32M = 7, /**< 32 Mb/s */
+ BITRATE_64M = 8, /**< 64 Mb/s */
+ BITRATE_128M = 9, /**< 128 Mb/s */
+ BITRATE_256M = 10, /**< 256 Mb/s */
+ BITRATE_512M = 11 /**< 512 Mb/s */
};
* Represents the network configuration of a switch.
*/
struct net_conf {
- struct in_addr ip; /**< IP */
- struct in_addr netmask; /**< netmask */
- struct in_addr gw; /**< gateway IP */
- bool dhcp; /**< DHCP enabled */
+ struct in_addr ip; /**< IP */
+ struct in_addr netmask; /**< netmask */
+ struct in_addr gw; /**< gateway IP */
+ bool dhcp; /**< DHCP enabled */
};
* Represents the main characteristics of a switch.
*/
struct swi_attr {
- char product[PRODUCT_SIZE]; /**< product name (eg.\ GS108EV1) */
- char name[NAME_SIZE]; /**< custom name */
- char firmware[FIRMWARE_SIZE]; /**< firmware version string */
- unsigned char ports; /**< number of ports */
- struct ether_addr mac; /**< MAC address */
- struct net_conf nc; /**< network configuration */
+ char product[PRODUCT_SIZE]; /**< product name (eg.\ GS108EV1) */
+ char name[NAME_SIZE]; /**< custom name */
+ char firmware[FIRMWARE_SIZE]; /**< firmware version string */
+ unsigned char ports; /**< number of ports */
+ struct ether_addr mac; /**< MAC address */
+ struct net_conf nc; /**< network configuration */
};
* Represents statistics of a particular port.
*/
struct port_stats {
- unsigned long long recv; /**< packets received */
- unsigned long long sent; /**< packets sent */
- unsigned long long crc; /**< CRC errors */
+ unsigned long long recv; /**< packets received */
+ unsigned long long sent; /**< packets sent */
+ unsigned long long crc; /**< CRC errors */
};
* Represents the IGMP snooping configuration of a switch.
*/
struct igmp_conf {
- bool enable; /**< IGMP snooping enabled */
- unsigned short vlan; /**< VLAN on which IGMP snooping is done */
- bool validate; /**< validate IGMPv3 headers */
- bool block; /**< block unknown multicast addresses */
+ bool enable; /**< IGMP snooping enabled */
+ unsigned short vlan; /**< VLAN on which IGMP snooping is done */
+ bool validate; /**< validate IGMPv3 headers */
+ bool block; /**< block unknown multicast addresses */
};
* Cabletest result.
*/
struct cabletest {
- char port; /**< port */
- int v1; /**< raw value 1 */
- int v2; /**< raw value 2 */
+ char port; /**< port */
+ int v1; /**< raw value 1 */
+ int v2; /**< raw value 2 */
};
/**
* Force the use of the interface.
* This function allows to solve two problems:
- * - When you have multiple network interfaces, sending to the broadcast may not
- * send the packet on the interface you want. \n
+ * - When you have multiple network interfaces, sending to the global broadcast
+ * address may not send the packet on the interface you want. \n
* This function forces the packet to go on the interface you specified at
* the library initialization.
* - When the switch is not in your network range, because DHCP is disabled or
* you started the DHCP server after the switch. \n
* This function allows you to ignore the routing table and consider every
* address is directly reachable on the interface. \n
- * An alternative is to use ngadmin_setKeepBroadcasting.
+ * An alternative is to use ngadmin_setKeepBroadcasting, or simply add a route.
*
* @warning Requires root priviledges.
* @see ngadmin_setKeepBroadcasting()
int ngadmin_setKeepBroadcasting (struct ngadmin *nga, bool value) EXPORT;
+/**
+ * Use global broadcast address.
+ * By default, NgAdmin uses the interface broadcast address.
+ * This option forces the lib to use the global broadcast address
+ * (255.255.255.255) instead.
+ * @warning If you have multiple interfaces, enabling this may cause problems.
+ * @see ngadmin_forceInterface()
+ * @param nga A pointer to the ngadmin structure.
+ * @param value Enable or disable the use of the global broadcast address.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
+int ngadmin_useGlobalBroadcast (struct ngadmin *nga, bool value) EXPORT;
+
+
/**
* Specify the password to use to login.
* Sets the password to use to login on switches.
const struct swi_attr* ngadmin_getCurrentSwitch (struct ngadmin *nga) EXPORT;
+
+/**
+ * Upgrade the switch firmware.
+ * This function allows you to upgrade the switch firmware.
+ * @warning Currently not implemented.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param filename A path to the file of the new firmware to send.
+ * @return ERR_NOTIMPL
+ **/
+int ngadmin_upgradeFirmware (struct ngadmin *nga, const char *filename) EXPORT;
+
+
/**
* Login on a switch.
* This function permits to login on a switch.
* This changes the name of a switch.
* @note You must be logged on a switch.
* @param nga A pointer to the ngadmin structure.
- * @param name The name string to use.
+ * @param name The name string to use. A NULL value clears the name.
* @return ERR_OK when everything is well or an error code otherwise.
**/
int ngadmin_setName (struct ngadmin *nga, const char *name) EXPORT;
/**
* Get the QoS mode.
- * Retrieve the QoS mode.
+ * Retrieves the QoS mode.
* @note You must be logged on a switch.
* @param nga A pointer to the ngadmin structure.
* @param s A pointer to an integer. Must not be NULL.
/**
* Get the QoS values.
- * Retrieve the QoS priority values for all the ports.
+ * Retrieves the QoS priority values for all the ports.
* @note You must be logged on a switch.
* @note The switch QoS mode should be port based to use this function.
* @param nga A pointer to the ngadmin structure.
* Get the port mirroring values.
* Retrieves the port mirrorring values.
* @note The switch QoS mode should be port based to use this function.
+ * @note You must be logged on a switch.
* @param nga A pointer to the ngadmin structure.
* @param ports A pointer to an array of chars. Must not be NULL. \n
The first element of the array is the output port (or 0 if port
int ngadmin_setMirror (struct ngadmin *nga, const char *ports) EXPORT;
-//
+/**
+ * Get the IGMP configuration.
+ * Retrieves the IGMP & multicast configuration.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param ic A pointer to an igmp_conf structure. Must not be NULL.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_getIGMPConf (struct ngadmin *nga, struct igmp_conf *ic) EXPORT;
-//
+/**
+ * Set the IGMP configuration.
+ * Changes the IGMP configuration.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param ic A pointer to an igmp_conf structure. Must not be NULL.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_setIGMPConf (struct ngadmin *nga, const struct igmp_conf *ic) EXPORT;
-//
+/**
+ * Perform a cable test.
+ * Performs a cable test on one ore more ports.
+ * @note Results are still raw values.
+ * @note This function takes a very long time.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param ct A pointer to an array of cabletest structures. Must not be NULL.
+ * @param nb The number of elements in the array.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb) EXPORT;
-//
+/**
+ * Set the network configuration.
+ * Changes the network configuration.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param nc A pointer to a net_conf structure. Must not be NULL. \n
+ Only non-zero fields of the structure are taken into account.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_setNetConf (struct ngadmin *nga, const struct net_conf *nc) EXPORT;
-//
+/**
+ * Get the VLAN type.
+ * Retrieves the VLAN type.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param t A pointer to an integer which will receive the VLAN type. Must not be NULL.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_getVLANType (struct ngadmin *nga, int *t) EXPORT;
-//
+/**
+ * Set the VLAN type.
+ * Changes the VLAN type.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param t An integer which contains the new VLAN type.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_setVLANType (struct ngadmin *nga, int t) EXPORT;
-//
+/**
+ * Get all the 802.1q VLAN configuration.
+ * Retrieves all the VLAN configuration in 802.1q mode.
+ * @note The switch should be in 802.1q mode.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param vlans A pointer to an array of unsigned shorts which will receive
+ * VLAN ids. Must not be NULL. \n
+ * The array size must be sizeof(unsigned short)*(*nb).
+ * @param ports A pointer to an array of unsigned chars which will receive the
+ 802.1q configuration for each VLAN. Must not be NULL. \n
+ The array size must be sizeof(unsigned char)*ports_count*(*nb).
+ * @param nb A pointer to an integer which contains the maximum number of
+ elements allowed in the array. Must not be NULL. \n
+ It will receive the actual number of VLAN written in the arrays.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsigned char *ports, int *nb) EXPORT;
-//
+/**
+ * Get the configuration of a VLAN in 802.1q mode.
+ * Retrieves the configuration of a particular VLAN in 802.1q mode.
+ * @note The switch should be in 802.1q mode.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param vlan The VLAN you want to get the configuration.
+ * @param ports A pointer to an array of integers which will receive the
+ configuration. Must not be NULL.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned char *ports) EXPORT;
-//
+/**
+ * Set the configuration if a VLAN in 802.1q mode.
+ * Changes the configuration of a particular VLAN in 802.1q mode.
+ * @note The switch should be in 802.1q mode.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param vlan The VLAN you want to change the configuration.
+ * @param ports A pointer to an array of integers which contain the
+ configuration. Must not be NULL.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsigned char *ports) EXPORT;
-//
+/**
+ * Destroy a VLAN in 802.1q mode.
+ * Destroys a particular VLAN in 802.1q mode.
+ * @note The switch should be in 802.1q mode.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param vlan The VLAN you want to destroy.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_VLANDestroy (struct ngadmin *nga, unsigned short vlan) EXPORT;
-//
+/**
+ * Get the PVID values.
+ * Retrieves the PVID values of all the ports.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param ports A pointer to an array of unsigned shorts which will receive the
+ * PVID values. Must not be NULL. \n
+ * The array size must be sizeof(unsigned short)*ports_count.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports) EXPORT;
-//
+/**
+ * Set the PVID of one port.
+ * Changes the PVID of one port.
+ * @note You must be logged on a switch.
+ * @param nga A pointer to the ngadmin structure.
+ * @param port The port you want to change PVID.
+ * @param vlan The new PVID value.
+ * @return ERR_OK when everything is well or an error code otherwise.
+ **/
int ngadmin_setPVID (struct ngadmin *nga, unsigned char port, unsigned short vlan) EXPORT;