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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include "NetworkManagerAP.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
/*
* Encapsulates Access Point information
*/
struct NMAccessPoint
{
guint refcount;
gchar *essid;
gchar *address;
guint8 quality;
double freq;
guint16 rate;
time_t stamp;
/* Things from user prefs */
gchar *wep_key;
guint priority;
};
/*
* nm_ap_new
*
* Create a new, blank user access point info structure
*
*/
NMAccessPoint * nm_ap_new (void)
{
NMAccessPoint *ap;
ap = g_new0 (NMAccessPoint, 1);
if (!ap)
NM_DEBUG_PRINT( "nm_ap_new() could not allocate a new user access point info structure. Not enough memory?" );
ap->priority = NM_AP_PRIORITY_WORST;
ap->refcount = 1;
return (ap);
}
/*
* nm_ap_new_from_ap
*
* Create a new user access point info structure, duplicating an existing one
*
*/
NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap)
{
NMAccessPoint *new_ap;
g_return_val_if_fail (src_ap != NULL, NULL);
new_ap = nm_ap_new();
if (!new_ap)
NM_DEBUG_PRINT( "nm_ap_new_from_uap() could not allocate a new user access point info structure. Not enough memory?" );
new_ap->refcount = 1;
if (src_ap->essid && (strlen (src_ap->essid) > 0))
new_ap->essid = g_strdup (src_ap->essid);
if (src_ap->address && (strlen (src_ap->address) > 0))
new_ap->address = g_strdup (src_ap->address);
new_ap->quality = src_ap->quality;
new_ap->freq = src_ap->freq;
new_ap->rate = src_ap->rate;
if (src_ap->wep_key && (strlen (src_ap->wep_key) > 0))
new_ap->wep_key = g_strdup (src_ap->wep_key);
new_ap->priority = src_ap->priority;
return (new_ap);
}
/*
* AP refcounting functions
*/
void nm_ap_ref (NMAccessPoint *ap)
{
g_return_if_fail (ap != NULL);
ap->refcount++;
}
void nm_ap_unref (NMAccessPoint *ap)
{
g_return_if_fail (ap != NULL);
ap->refcount--;
if (ap->refcount == 0)
{
g_free (ap->essid);
g_free (ap->address);
g_free (ap->wep_key);
ap->essid = NULL;
ap->wep_key = NULL;
g_free (ap);
}
}
/*
* Get/set functions for priority
*
*/
guint nm_ap_get_priority (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->priority);
}
void nm_ap_set_priority (NMAccessPoint *ap, guint priority)
{
g_return_if_fail (ap != NULL);
ap->priority = priority;
}
/*
* Get/set functions for essid
*
*/
gchar * nm_ap_get_essid (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->essid);
}
void nm_ap_set_essid (NMAccessPoint *ap, gchar * essid)
{
g_return_if_fail (ap != NULL);
if (ap->essid)
g_free (ap->essid);
ap->essid = g_strdup (essid);
}
/*
* Get/set functions for WEP key
*
*/
gchar * nm_ap_get_wep_key (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->wep_key);
}
void nm_ap_set_wep_key (NMAccessPoint *ap, gchar * wep_key)
{
g_return_if_fail (ap != NULL);
if (ap->wep_key)
g_free (ap->wep_key);
ap->wep_key = g_strdup (wep_key);
}
/*
* Get/set functions for address
*
*/
gchar * nm_ap_get_address (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->address);
}
void nm_ap_set_address (NMAccessPoint *ap, gchar * address)
{
g_return_if_fail (ap != NULL);
if (ap->address)
g_free (ap->address);
ap->address = g_strdup (address);
}
/*
* Get/set functions for quality
*
*/
guint8 nm_ap_get_quality (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->quality);
}
void nm_ap_set_quality (NMAccessPoint *ap, guint8 quality)
{
g_return_if_fail (ap != NULL);
ap->quality = quality;
}
/*
* Get/set functions for frequency
*
*/
double nm_ap_get_freq (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->freq);
}
void nm_ap_set_freq (NMAccessPoint *ap, double freq)
{
g_return_if_fail (ap != NULL);
ap->freq = freq;
}
/*
* Get/set functions for rate
*
*/
guint16 nm_ap_get_rate (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->rate);
}
void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate)
{
g_return_if_fail (ap != NULL);
ap->rate = rate;
}
/*
* Get/set functions for timestamp
*
*/
time_t nm_ap_get_stamp (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->stamp);
}
void nm_ap_set_stamp (NMAccessPoint *ap, time_t stamp)
{
g_return_if_fail (ap != NULL);
ap->stamp = stamp;
}
|