iface.h
Go to the documentation of this file.
1 /* vim: set ts=2 expandtab: */
2 /**
3  * @file iface.h
4  * @brief interface handling for the Commotion daemon
5  *
6  * @author Josh King (jheretic), jking@chambana.net
7  *
8  * @internal
9  * Created 03/07/2013
10  * Revision $Id: doxygen.commotion.templates,v 0.1 2013/01/01 09:00:00 jheretic Exp $
11  * Compiler gcc/g++
12  * Company The Open Technology Institute
13  * Copyright Copyright (c) 2013, Josh King
14  *
15  * This file is part of Commotion, Copyright (c) 2013, Josh King
16  *
17  * Commotion is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as
19  * published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * Commotion is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with Commotion. If not, see <http://www.gnu.org/licenses/>.
29  *
30  * =====================================================================================
31  */
32 
33 #ifndef _IFACE_H
34 #define _IFACE_H
35 #include <stdbool.h>
36 #include <net/if.h>
37 #include "id.h"
38 #include "obj.h"
39 
40 #define FREQ_LEN 5 //number of characters in 802.11 frequency designator
41 #define MAC_LEN 6
42 #define WPA_REPLY_SIZE 2048
43 #define IFACES_MAX 32
44 #define SIOCGIWNAME 0x8B01
45 
46 /**
47  * @enum co_iface_status_t indicates whether the interface is UP(1) or DOWN(0)
48  */
49 typedef enum {
50  DOWN = 0,
51  UP = 1
53 
54 typedef struct co_iface_t co_iface_t;
55 
56 /**
57  * @struct co_iface_t
58  * @brief contains the file descriptor, interface status (up or down), profile name, interface frequency struct, wpa control struct, wpa id, and a bool to indicare whether the interface is wireless or not
59  */
60 struct co_iface_t {
61  co_obj_t _header;
62  uint8_t _exttype;
63  uint8_t _len;
64  int fd;
65  co_iface_status_t status;
66  char *profile;
67  struct ifreq ifr;
68  struct wpa_ctrl *ctrl;
69  int wpa_id;
70  bool wireless;
71 } __attribute__((packed));
72 
73 /**
74  * @brief checks for available interfaces
75  */
76 int co_ifaces_create(void);
77 
78 /**
79  * @brief removes all interfaces
80  */
81 void co_ifaces_shutdown(void);
82 
83 /**
84  * @brief removes an interface from the list of available interfaces
85  * @param iface_name name of interface to be removed
86  */
87 int co_iface_remove(char *iface_name);
88 
89 /**
90  * @brief adds a new interface to the list of available interfaces, and checks whether it is IPv4 and IPv6 capable, and whether it is wireless
91  * @param iface_name name of the interface
92  * @param family address family of the interface. Must be AF_INET (IPv4) or AF_INET6 (IPv6), which uses host and port number for addressing
93  */
94 co_obj_t *co_iface_add(const char *iface_name, const int family);
95 
96 /**
97  * @brief connects the commotion interface to wpa supplicant
98  * @param iface interface object
99  */
100 int co_iface_wpa_connect(co_obj_t *iface);
101 
102 /**
103  * @brief turns off wpa supplicant
104  * @param iface interface object
105  */
107 
108 /**
109  * @brief
110  * @param iface interface object
111  * @param output output of hardware MAC address lookup
112  * @param output_size size of MAC address. Must be six bytes
113  */
114 int co_iface_get_mac(co_obj_t *iface, unsigned char *output, int output_size);
115 
116 /**
117  * @brief sets ip address and netmask for commotion interface
118  * @param iface interface object
119  * @param ip_addr ip address for the socket
120  * @param netmask netmask for the socket
121  */
122 int co_iface_set_ip(co_obj_t *iface, const char *ip_addr, const char *netmask);
123 
124 /**
125  * @brief Resets ip address of chosen interface
126  * @param iface interface object
127  */
128 int co_iface_unset_ip(co_obj_t *iface);
129 
130 /**
131  * @brief sets SSID from profile or uses default
132  * @param iface interface object
133  * @param ssid desired SSID
134  */
135 int co_iface_set_ssid(co_obj_t *iface, const char *ssid);
136 
137 /**
138  * @brief sets BSSID from profile or uses default
139  * @param iface interface object
140  * @param bssid desired BSSID
141  */
142 int co_iface_set_bssid(co_obj_t *iface, const char *bssid);
143 
144 /**
145  * @brief sets wireless frequency (eg. channel) from profile or uses default
146  * @param iface interface object
147  * @param frequency desired frequency
148  */
149 int co_iface_set_frequency(co_obj_t *iface, const int frequency);
150 
151 /**
152  * @brief specifies the wpa encryption protocol
153  * @param iface interface object
154  * @param proto desired protocol
155  */
156 int co_iface_set_encryption(co_obj_t *iface, const char *proto);
157 
158 /**
159  * @brief specifies the wpa encryption key
160  * @param iface interface object
161  * @param key desired key
162  */
163 int co_iface_set_key(co_obj_t *iface, const char *key);
164 
165 /**
166  * @brief specifies the Wi-Fi mode
167  * @param iface interface object
168  * @param mode desired mode
169  */
170 int co_iface_set_mode(co_obj_t *iface, const char *mode);
171 
172 /**
173  * @brief sets AP_SCAN value
174  * @param iface interface object
175  * @param value desired value for AP_SCAN
176  */
177 int co_iface_set_apscan(co_obj_t *iface, const int value);
178 
179 /**
180  * @brief enables specified wireless network
181  * @param iface interface object
182  */
184 
185 /**
186  * @brief disables specified wireless network
187  * @param iface interface object
188  */
190 
191 /**
192  * @brief sets DNS name server and sets search domain
193  * @param dnsserver IP addresss of DNS server
194  * @param searchdomain desired search domain
195  * @param resolvpath filepath to resolv.conf
196  */
197 int co_set_dns(const char *dnsserver, const char *searchdomain, const char *resolvpath);
198 
199 //int co_set_dns(const char *dnsservers[], const size_t numservers, const char *searchdomain, const char *resolvpath);
200 
201 /**
202  * @brief generates an ip table for a commotion interface
203  * @param base base address
204  * @param genmask genmask
205  * @param id the node id
206  * @param type whether the device is a gateway (1) or not (0)
207  */
208 int co_generate_ip(const char *base, const char *genmask, const nodeid_t id, char *output, int type);
209 
210 //int co_iface_status(const char *iface_name);
211 
212 /**
213  * @brief sets node configuration profile
214  * @param iface_name name of interface
215  */
216 char *co_iface_profile(char *iface_name);
217 
218 /**
219  * @brief retrieves node configuration profile
220  * @param iface_name name of interface
221  */
222 co_obj_t *co_iface_get(char *iface_name);
223 
224 #endif
Commotion object model.
Definition: id.h:40
int co_iface_unset_ip(co_obj_t *iface)
Resets ip address of chosen interface.
Definition: iface.c:259
int co_iface_wpa_disconnect(co_obj_t *iface)
turns off wpa supplicant
Definition: iface.c:273
int co_set_dns(const char *dnsserver, const char *searchdomain, const char *resolvpath)
sets DNS name server and sets search domain
Definition: iface.c:426
int co_iface_set_mode(co_obj_t *iface, const char *mode)
specifies the Wi-Fi mode
Definition: iface.c:366
int co_iface_set_encryption(co_obj_t *iface, const char *proto)
specifies the wpa encryption protocol
Definition: iface.c:352
int co_iface_set_ip(co_obj_t *iface, const char *ip_addr, const char *netmask)
sets ip address and netmask for commotion interface
Definition: iface.c:232
void co_ifaces_shutdown(void)
removes all interfaces
Definition: iface.c:162
int co_iface_set_ssid(co_obj_t *iface, const char *ssid)
sets SSID from profile or uses default
Definition: iface.c:309
co_obj_t * co_iface_get(char *iface_name)
retrieves node configuration profile
Definition: iface.c:502
simple interface for managing node id
co_iface_status_t
Definition: iface.h:49
contains the file descriptor, interface status (up or down), profile name, interface frequency struct...
Definition: iface.h:60
int co_iface_get_mac(co_obj_t *iface, unsigned char *output, int output_size)
Definition: iface.c:210
Definition: obj.h:131
int co_iface_wpa_connect(co_obj_t *iface)
connects the commotion interface to wpa supplicant
Definition: iface.c:285
int co_iface_wireless_disable(co_obj_t *iface)
disables specified wireless network
Definition: iface.c:401
int co_iface_set_apscan(co_obj_t *iface, const int value)
sets AP_SCAN value
Definition: iface.c:373
int co_iface_remove(char *iface_name)
removes an interface from the list of available interfaces
Definition: iface.c:166
int co_ifaces_create(void)
checks for available interfaces
Definition: iface.c:153
int co_iface_wireless_enable(co_obj_t *iface)
enables specified wireless network
Definition: iface.c:387
Definition: wpa_ctrl.c:76
int co_iface_set_key(co_obj_t *iface, const char *key)
specifies the wpa encryption key
Definition: iface.c:359
co_obj_t * co_iface_add(const char *iface_name, const int family)
adds a new interface to the list of available interfaces, and checks whether it is IPv4 and IPv6 capa...
Definition: iface.c:180
char * co_iface_profile(char *iface_name)
sets node configuration profile
Definition: iface.c:494
int co_iface_set_bssid(co_obj_t *iface, const char *bssid)
sets BSSID from profile or uses default
Definition: iface.c:316
int co_generate_ip(const char *base, const char *genmask, const nodeid_t id, char *output, int type)
generates an ip table for a commotion interface
Definition: iface.c:437
int co_iface_set_frequency(co_obj_t *iface, const int frequency)
sets wireless frequency (eg. channel) from profile or uses default
Definition: iface.c:343