3 (c) 2010 Gregor Riepl <onitake@gmail.com>
5 Tethering utility for Maemo
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _MTETHERD_NET_H
22 #define _MTETHERD_NET_H
25 #include <glib-object.h>
29 #define TYPE_MTETHERD_DEVICE (mtetherd_device_get_type())
30 #define MTETHERD_DEVICE(object) (G_TYPE_CHECK_INSTANCE_CAST((object), TYPE_MTETHERD_DEVICE, MTetherDDevice))
31 #define MTETHERD_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TYPE_MTETHERD_DEVICE, MTetherDDeviceClass))
32 #define IS_MTETHERD_DEVICE(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), TYPE_MTETHERD_DEVICE))
33 #define IS_MTETHERD_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_MTETHERD_DEVICE))
34 #define MTETHERD_DEVICE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), TYPE_MTETHERD_DEVICE, MTetherDDeviceClass))
36 typedef struct _MTetherDDeviceClass MTetherDDeviceClass;
37 typedef struct _MTetherDDevice MTetherDDevice;
38 typedef struct _MTetherDDevicePrivate MTetherDDevicePrivate;
40 struct _MTetherDDeviceClass {
44 struct _MTetherDDevice {
46 MTetherDDevicePrivate *priv;
49 GType mtetherd_device_get_type();
51 // Allocates a new device object
52 // This object doesn't have addresses assigned yet
53 // Add it to a device list or use mtetherd_device_set_index to construct them
54 MTetherDDevice *mtetherd_device_new(const gchar *interface, const gchar *udi);
55 // Constructs IP address and DHCP ranges from the given index
56 // 192.168.255.0/24 is the supernet for all devices,
57 // each gets a /30 from that range, depending on the index
58 // Example: index = 32 -> subnet = 192.168.255.200/30
59 // The host address is always 1, and the DHCP range goes from 1 to 2
60 void mtetherd_device_set_index(MTetherDDevice *self, guint index);
61 // Returns the interface name
62 const gchar *mtetherd_device_get_interface(MTetherDDevice *self);
63 // Returns the host address
65 gchar *mtetherd_device_get_addr(MTetherDDevice *self);
66 // Returns the netmask
68 gchar *mtetherd_device_get_netmask(MTetherDDevice *self);
69 // Returns the DHCP range start address
71 gchar *mtetherd_device_get_dhcp_start(MTetherDDevice *self);
72 // Returns the DHCP range end address
74 gchar *mtetherd_device_get_dhcp_end(MTetherDDevice *self);
76 // Device list functions
77 // The list is constrained to 64 entries
78 gpointer mtetherd_device_list_new();
79 // Unrefs all devices contained within and frees the list
80 void mtetherd_device_list_free(gpointer list);
81 // Scans the list for an udi and returns the first device found
82 MTetherDDevice *mtetherd_device_list_find(gpointer list, const gchar *udi);
83 // Adds a device to the next free position
84 // This transfers ownership of the object to the list
85 // Returns FALSE if the list is already full
86 gboolean mtetherd_device_list_add(gpointer list, MTetherDDevice *device);
87 // Removes and deallocates the first device with the given UDI from the list
88 // Returns FALSE if the UDI is not found
89 gboolean mtetherd_device_list_remove(gpointer list, const gchar *udi);
91 // Returns true if the device is acceptable for tethering
92 // Currently checks if the interface name starts with usb or bnep
93 gboolean mtetherd_device_ok(const gchar *interface);
97 #endif //_MTETHERD_NET_H