File: nm-conf.h

package info (click to toggle)
netcfg 1.131
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 3,524 kB
  • sloc: ansic: 5,376; sh: 183; makefile: 78
file content (154 lines) | stat: -rw-r--r-- 5,280 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

#ifndef _NM_CONF_H
#define _NM_CONF_H

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <debian-installer.h>

#ifdef WIRELESS
#include <iwlib.h>
#endif

/* Global variables. */
#include "netcfg.h"

/* Constants for maximum size for Network Manager config fields. */
#define NM_MAX_LEN_BUF          1024 /* Max len for most buffers */
#define NM_MAX_LEN_ID           128
#define NM_MAX_LEN_SSID         128
#define NM_MAX_LEN_MAC_ADDR     20   /* AA:BB:CC:DD:EE:FF format */
#define NM_MAX_LEN_IPV4         20   /* x.x.x.x format */
#define NM_MAX_LEN_WPA_PSK      65   /* 64 standard + NULL char */
#define NM_MAX_LEN_WEP_KEY      30   /* Rough estimation (should be 26) */
#define NM_MAX_LEN_PATH         128  /* Assume a path won't be longer */
#define NM_MAX_LEN_UUID         37
#define NM_NO_BITS_IPV4         32


/* Some Network Manager default values for connection types. */
#define NM_DEFAULT_WIRED                "802-3-ethernet"
#define NM_DEFAULT_WIRED_NAME           "Wired connection 1"
#define NM_DEFAULT_WIRELESS             "802-11-wireless"
#define NM_DEFAULT_WIRELESS_SECURITY    "802-11-wireless-security"
#define NM_DEFAULT_PATH_FOR_MAC         "/sys/class/net/%s/address"
#define NM_CONFIG_FILE_PATH             "/etc/NetworkManager/system-connections"
#define NM_CONNECTION_FILE              "/tmp/connection_type"

#define NM_SETTINGS_CONNECTION          "[connection]"
#define NM_SETTINGS_WIRELESS            "["NM_DEFAULT_WIRELESS"]"
#define NM_SETTINGS_WIRED               "["NM_DEFAULT_WIRED"]"
#define NM_SETTINGS_WIRELESS_SECURITY   "["NM_DEFAULT_WIRELESS_SECURITY"]"
#define NM_SETTINGS_IPV4                "[ipv4]"
#define NM_SETTINGS_IPV6                "[ipv6]"


/* Minimalist structures for storing basic elements in order to write a Network
 * Manager format config file.
 *
 * See full specifications at:
 *
 * http://projects.gnome.org/NetworkManager/developers/settings-spec-08.html
 *
 */
typedef struct nm_connection
{
    char id[NM_MAX_LEN_ID];
    char uuid[NM_MAX_LEN_UUID];
    enum {WIRED, WIFI} type;
    int manual; /* 1 = true, 0 = false */
} nm_connection;

typedef struct nm_wired
{
    char                            mac_addr[NM_MAX_LEN_MAC_ADDR];
}   nm_wired;

typedef struct nm_wireless
{
    char                            ssid[NM_MAX_LEN_SSID];
    char                            mac_addr[NM_MAX_LEN_MAC_ADDR];
    enum {AD_HOC, INFRASTRUCTURE}   mode;
    enum {FALSE = 0, TRUE = 1}      is_secured; /* 1 = secure, 0 = unsecure */
}   nm_wireless;

typedef struct nm_wireless_security
{
    enum {WEP_KEY, WPA_PSK}         key_mgmt;

    union
    {
        char                psk[NM_MAX_LEN_WPA_PSK];
        struct
        {
            enum {HEX_ASCII = 1, PASSPHRASE = 2}  wep_key_type;
            enum {OPEN, SHARED}                   auth_alg;
            unsigned char                         wep_key0[NM_MAX_LEN_WEP_KEY];
        };
    };
}   nm_wireless_security;

typedef struct nm_ipvX
{
    int                             used;   /* 1 = true, 0 = false */
    enum {AUTO, MANUAL, IGNORE}     method;
    char *                          ip_address;
    char *                          gateway;
    char *                          nameservers[NETCFG_NAMESERVERS_MAX];
    unsigned int                    masklen;
}   nm_ipvX;


typedef struct nm_config_info
{
    nm_connection           connection;
    nm_wired                wired;
    nm_wireless             wireless;
    nm_wireless_security    wireless_security;
    nm_ipvX                 ipv4;
    nm_ipvX                 ipv6;
}   nm_config_info;

/* Here come functions: */

#ifdef WIRELESS
void nm_write_wireless_specific_options(FILE *config_file,
        struct nm_config_info *nmconf);
void nm_write_wireless_security(FILE *config_file, nm_wireless_security
        wireless_security);
#endif
void nm_write_connection(FILE *config_file, nm_connection connection);
void nm_write_wired_specific_options(FILE *config_file,
        struct nm_config_info *nmconf);
void nm_write_ipv4(FILE *config_file, nm_ipvX ipv4);
void nm_write_ipv6(FILE *config_file, nm_ipvX ipv6);

void nm_write_configuration(struct nm_config_info nmconf);

void nm_write_connection_type(struct nm_config_info nmconf);


#ifdef WIRELESS
void nm_get_wireless_connection(struct netcfg_interface *niface, nm_connection *connection);
void nm_get_wireless_specific_options(struct netcfg_interface *niface, nm_wireless *wireless);
void nm_get_wireless_security(struct netcfg_interface *niface, nm_wireless_security *wireless_security);
#endif
void nm_get_wired_connection(nm_connection *connection);
void nm_get_mac_address(char *interface, char *mac_addr);
void nm_get_wired_specific_options(struct netcfg_interface *niface, nm_wired *wired);
void nm_get_ipv4(struct netcfg_interface *niface, nm_ipvX *ipv4);
void nm_get_ipv6(struct netcfg_interface *niface, nm_ipvX *ipv6);

#ifdef WIRELESS
void nm_get_wireless_config(struct netcfg_interface *niface, struct nm_config_info *nmconf);
#endif
void nm_get_wired_config(struct netcfg_interface *niface, struct nm_config_info *nmconf);

void nm_get_configuration(struct netcfg_interface *niface, struct nm_config_info *nmconf);

#endif