summaryrefslogtreecommitdiff
path: root/src/NetworkManagerAPList.c
blob: 32e596493364e512b14da87c31afdcf0506a62ff (plain)
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
/* 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 <glib.h>
#include <dbus/dbus-glib.h>
#include <netinet/ether.h>
#include "NetworkManagerAP.h"
#include "NetworkManagerAPList.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerDbus.h"
#include "nm-utils.h"


struct NMAccessPointList
{
	guint		 refcount;
	NMNetworkType	 type;
	GSList		*ap_list;
	GMutex		*mutex;
};


/*
 * nm_ap_list_new
 *
 * Creates a new empty access point list
 *
 */
NMAccessPointList *nm_ap_list_new (NMNetworkType type)
{
	NMAccessPointList *list = g_new0 (NMAccessPointList, 1);

	g_return_val_if_fail (list != NULL, NULL);

	nm_ap_list_ref (list);
	list->type = type;
	list->mutex = g_mutex_new ();
	if (!list->mutex)
	{
		g_free (list);
		nm_warning ("nm_ap_list_new() could not create list mutex");
		return (NULL);
	}
	nm_register_mutex_desc (list->mutex, "AP List Mutex");

	return (list);
}


/*
 * nm_ap_list_ref
 *
 * Increases the refcount of the ap list
 *
 */
void nm_ap_list_ref (NMAccessPointList *list)
{
	g_return_if_fail (list != NULL);

	list->refcount++;
}


/*
 * nm_ap_list_element_free
 *
 * Frees each member of an access point list before the list is
 * disposed of. 
 *
 */
static void nm_ap_list_element_free (void *element, void *user_data)
{
	nm_ap_unref (element);
}


/*
 * nm_ap_list_unref
 *
 * Decreases the refcount of the ap list, and if it reaches
 * 0 frees the structure.
 *
 */
void nm_ap_list_unref (NMAccessPointList *list)
{
	if (!list)
		return;

	list->refcount--;
	if (list->refcount <= 0)
	{
		gboolean	acquired = nm_try_acquire_mutex (list->mutex, __FUNCTION__);

		g_slist_foreach (list->ap_list, nm_ap_list_element_free, NULL);
		g_slist_free (list->ap_list);

		if (acquired)
			nm_unlock_mutex (list->mutex, __FUNCTION__);

		g_mutex_free (list->mutex);
		g_free(list);
	}
}


/*
 * nm_ap_list_size
 *
 * Return size of the access point list
 *
 */
guint nm_ap_list_size (NMAccessPointList *list)
{
	guint size;

	g_return_val_if_fail (list != NULL, 0);

	if (!nm_ap_list_lock (list))
	{
		nm_warning ("nm_ap_list_size() could not acquire AP list mutex." );
		return 0;
	}

	size = g_slist_length (list->ap_list);
	nm_ap_list_unlock (list);

	return size;
}


/*
 * nm_ap_list_is_empty
 *
 * Returns whether or not the access point list has any access points
 * in it.
 *
 */
gboolean nm_ap_list_is_empty (NMAccessPointList *list)
{
	return ((list->ap_list == NULL));
}


/*
 * nm_ap_list_append_ap
 *
 * Helper to append an AP to an ap list of a certain type.
 *
 */
void nm_ap_list_append_ap (NMAccessPointList *list, NMAccessPoint *ap)
{
	g_return_if_fail (list != NULL);
	g_return_if_fail (ap != NULL);

	if (!nm_ap_list_lock (list))
	{
		nm_warning ("nm_ap_list_append_ap() could not acquire AP list mutex." );
		return;
	}

	nm_ap_ref (ap);
	list->ap_list = g_slist_append (list->ap_list, ap);

	nm_ap_list_unlock (list);
}


/*
 * nm_ap_list_remove_ap
 *
 * Helper to remove an AP to an ap list of a certain type.
 *
 */
void nm_ap_list_remove_ap (NMAccessPointList *list, NMAccessPoint *ap)
{
	GSList		*elt = NULL;

	g_return_if_fail (list != NULL);
	g_return_if_fail (ap != NULL);

	if (!nm_ap_list_lock (list))
	{
		nm_warning ("nm_ap_list_remove_ap() could not acquire AP list mutex." );
		return;
	}

	for (elt = list->ap_list; elt; elt = g_slist_next (elt))
	{
		NMAccessPoint	*list_ap = (NMAccessPoint *)(elt->data);

		if (list_ap == ap)
		{
			list->ap_list = g_slist_remove_link (list->ap_list, elt);
			nm_ap_unref (list_ap);
			g_slist_free (elt);
			break;
		}
	}
	nm_ap_list_unlock (list);
}


/*
 * nm_ap_list_remove_ap_by_essid
 *
 * Helper to remove an AP from an AP list by the AP's ESSID.
 *
 */
void nm_ap_list_remove_ap_by_essid (NMAccessPointList *list, const char *network)
{
	GSList		*elt = NULL;

	g_return_if_fail (list != NULL);
	g_return_if_fail (network != NULL);

	if (!nm_ap_list_lock (list))
	{
		nm_warning ("nm_ap_list_remove_ap_by_essid() could not acquire AP list mutex." );
		return;
	}

	for (elt = list->ap_list; elt; elt = g_slist_next (elt))
	{
		NMAccessPoint	*list_ap = (NMAccessPoint *)(elt->data);

		if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap), network) == 0)
		{
			list->ap_list = g_slist_remove_link (list->ap_list, elt);
			nm_ap_unref (list_ap);
			g_slist_free (elt);
			break;
		}
	}
	nm_ap_list_unlock (list);
}

/* nm_ap_list_remove_duplicate_essids
 *
 */
void    nm_ap_list_remove_duplicate_essids (NMAccessPointList *list)
{
	NMAccessPoint   *removal_ap;
	NMAccessPoint   *list_ap_max;
	GSList          *elt_i = NULL;	
	GSList          *elt_j = NULL;
	GSList          *elt_max = NULL;
	GSList          *removal_list = NULL;
	GSList          *elt;
	gint8            max_strength = 0;
	gint8            strengthj = 0;

	g_return_if_fail (list != NULL);

	if (!nm_ap_list_lock (list))
	{
		nm_warning ("nm_ap_list_append_ap() could not acquire AP list mutex." );
		return;
	}

	for (elt_i = list->ap_list; elt_i; elt_i = g_slist_next (elt_i))
	{
		NMAccessPoint   *list_ap_i = (NMAccessPoint *)(elt_i->data);
		gboolean         found = FALSE;

		for (elt_j = list->ap_list; elt_j < elt_i; elt_j = g_slist_next (elt_j))
		{
			NMAccessPoint   *list_ap_j = (NMAccessPoint *)(elt_j->data);

			if ((found = (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)))
				break;
		}

		if (found)
			continue;

		elt_max = elt_i;
		list_ap_max = (NMAccessPoint *)(elt_i->data);
		max_strength = nm_ap_get_strength (list_ap_i);

		for (elt_j = g_slist_next (elt_i); elt_j; elt_j = g_slist_next (elt_j))
		{
			NMAccessPoint   *list_ap_j = (NMAccessPoint *)(elt_j->data);

			strengthj = nm_ap_get_strength (list_ap_j);
			if (nm_null_safe_strcmp (nm_ap_get_essid (list_ap_i), nm_ap_get_essid (list_ap_j)) == 0)
			{
				if (strengthj > max_strength)
				{
					removal_list = g_slist_append (removal_list, list_ap_max);
					list_ap_max = list_ap_j;
					max_strength = strengthj;
				}
				else
					removal_list = g_slist_append (removal_list, list_ap_j);
			}
		}
	}
	nm_ap_list_unlock (list);

	for (elt = removal_list; elt; elt = g_slist_next (elt))
	{
		if ((removal_ap = (NMAccessPoint *)(elt->data)))
			nm_ap_list_remove_ap (list, removal_ap);
	}
	g_slist_free (removal_list);

}


/*
 * nm_ap_list_get_ap_by_essid
 *
 * Search through an access point list and return the access point
 * that has a given essid.
 *
 */
NMAccessPoint *nm_ap_list_get_ap_by_essid (NMAccessPointList *list, const char *network)
{
	NMAccessPoint	*ap;
	NMAccessPoint	*found_ap = NULL;
	NMAPListIter	*iter;

	if (!network)
		return (NULL);

	if (!list)
		return (NULL);

	if (!(iter = nm_ap_list_iter_new (list)))
		return (NULL);

	while ((ap = nm_ap_list_iter_next (iter)))
	{
		if (nm_ap_get_essid (ap) && (nm_null_safe_strcmp (nm_ap_get_essid (ap), network) == 0))
		{
			found_ap = ap;
			break;
		}
	}
	nm_ap_list_iter_free (iter);

	return (found_ap);
}


/*
 * nm_ap_list_get_ap_by_address
 *
 * Search through an access point list and return the access point
 * that has a given AP address.
 *
 */
NMAccessPoint *nm_ap_list_get_ap_by_address (NMAccessPointList *list, const struct ether_addr *addr)
{
	NMAccessPoint	*ap;
	NMAccessPoint	*found_ap = NULL;
	NMAPListIter	*iter;

	if (!addr)
		return (NULL);

	if (!list)
		return (NULL);

	if (!(iter = nm_ap_list_iter_new (list)))
		return (NULL);

	while ((ap = nm_ap_list_iter_next (iter)))
	{
		GSList	*user_addrs;
		gboolean	 success = FALSE;

		if (nm_ap_get_address (ap) && (memcmp (addr, nm_ap_get_address (ap), sizeof (struct ether_addr)) == 0))
			success = TRUE;

		if (!success && (user_addrs = nm_ap_get_user_addresses (ap)))
		{
			char		 char_addr[20];
			GSList	*elt;

			memset (&char_addr[0], 0, 20);
			iw_ether_ntop (addr, &char_addr[0]);
			for (elt = user_addrs; elt; elt = g_slist_next (elt))
			{
				if (elt->data && !strcmp (elt->data, &char_addr[0]))
				{
					success = TRUE;
					break;
				}
			}

			g_slist_foreach (user_addrs, (GFunc)g_free, NULL);
			g_slist_free (user_addrs);
		}

		if (success)
		{
			found_ap = ap;
			break;
		}
	}
	nm_ap_list_iter_free (iter);

	return (found_ap);
}


/*
 * nm_ap_list_merge_scanned_ap
 *
 * Given an AP list and an access point, merge the access point into the list.
 * If the AP is already in the list, merge just the /attributes/ together for that
 * AP, if its not already in the list then just add it.  This doesn't merge all
 * attributes, just ones that are likely to be new from the scan.
 *
 * Returns:	FALSE if the AP was not new and was merged
 *			TRUE if the ap was completely new
 *
 */
gboolean nm_ap_list_merge_scanned_ap (NMDevice80211Wireless *dev, NMAccessPointList *list, NMAccessPoint *merge_ap)
{
	NMAccessPoint *	list_ap = NULL;
	gboolean			strength_changed = FALSE;
	gboolean			new = FALSE;
	NMData *			app_data;

	g_return_val_if_fail (dev != NULL, FALSE);
	g_return_val_if_fail (list != NULL, FALSE);
	g_return_val_if_fail (merge_ap != NULL, FALSE);

	app_data = nm_device_get_app_data (NM_DEVICE (dev));
	g_return_val_if_fail (app_data != NULL, FALSE);

	if ((list_ap = nm_ap_list_get_ap_by_address (list, nm_ap_get_address (merge_ap))))
	{
		const char *	devlist_essid = nm_ap_get_essid (list_ap);
		const char *	merge_essid = nm_ap_get_essid (merge_ap);

		/* First, we check for an address match. If the merge AP has the
		 * same address as a list AP, the merge AP and the list AP
		 * must be the same physical AP. The list AP properties must be from
		 * a previous scan so the time_last_seen's are not equal.
		 * Update encryption, authentication method,
		 * strength, and the time_last_seen. */

		const GTimeVal  *merge_ap_seen = nm_ap_get_last_seen (merge_ap);

		/* Did the AP's name change? */
		if (!devlist_essid || !merge_essid || nm_null_safe_strcmp (devlist_essid, merge_essid))
		{
			nm_dbus_signal_wireless_network_change (app_data->dbus_connection,
			        dev, list_ap, NETWORK_STATUS_DISAPPEARED, -1);
			new = TRUE;
		}

		nm_ap_set_capabilities (list_ap, nm_ap_get_capabilities (merge_ap));
		if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap))
		{
			nm_ap_set_strength (list_ap, nm_ap_get_strength (merge_ap));
			strength_changed = TRUE;
		}
		nm_ap_set_last_seen (list_ap, merge_ap_seen);
		nm_ap_set_broadcast (list_ap, nm_ap_get_broadcast (merge_ap));

		/* If the AP is noticed in a scan, it's automatically no longer
		 * artificial, since it clearly exists somewhere.
		 */
		nm_ap_set_artificial (list_ap, FALSE);

		/* Have to change AP's name _after_ dbus signal for old network name
		 * has gone out.
		 */
		nm_ap_set_essid (list_ap, merge_essid);
	}
	else if ((list_ap = nm_ap_list_get_ap_by_essid (list, nm_ap_get_essid (merge_ap))))
	{

		/* Second, we check for an ESSID match. In this case,
		 * a list AP has the same non-NULL ESSID as the merge AP. Update the
		 * encryption and authentication method. Update the strength and address
		 * except when the time_last_seen of the list AP is the same as the
		 * time_last_seen of the merge AP and the strength of the list AP is greater
		 * than or equal to the strength of the merge AP. If the time_last_seen's are
		 * equal, the merge AP and the list AP come from the same scan.
		 * Update the time_last_seen. */

		const GTimeVal *	merge_ap_seen = nm_ap_get_last_seen (merge_ap);
		const GTimeVal *	list_ap_seen = nm_ap_get_last_seen (list_ap);
		const int			merge_ap_strength = nm_ap_get_strength (merge_ap);

		nm_ap_set_capabilities (list_ap, nm_ap_get_capabilities (merge_ap));

		if (!((list_ap_seen->tv_sec == merge_ap_seen->tv_sec)
			&& (nm_ap_get_strength (list_ap) >= merge_ap_strength)))
		{
			nm_ap_set_strength (list_ap, merge_ap_strength);
			nm_ap_set_address (list_ap, nm_ap_get_address (merge_ap));
		}
		nm_ap_set_last_seen (list_ap, merge_ap_seen);
		nm_ap_set_broadcast (list_ap, nm_ap_get_broadcast (merge_ap));

		/* If the AP is noticed in a scan, it's automatically no longer
		 * artificial, since it clearly exists somewhere.
		 */
		nm_ap_set_artificial (list_ap, FALSE);
	}
	else
	{
		/* Add the merge AP to the list. */
		nm_ap_list_append_ap (list, merge_ap);
		list_ap = merge_ap;
		new = TRUE;
	}

	if (list_ap && strength_changed && !new)
	{
		const int new_strength = nm_ap_get_strength (list_ap);
		nm_dbus_signal_wireless_network_change (app_data->dbus_connection,
		        dev, list_ap, NETWORK_STATUS_STRENGTH_CHANGED, new_strength);
	}

	if (list_ap && new)
	{
		nm_dbus_signal_wireless_network_change (app_data->dbus_connection,
		        dev, list_ap, NETWORK_STATUS_APPEARED, -1);
	}

	return TRUE;
}


/*
 * nm_ap_list_copy_properties
 *
 * Update properties (like encryption keys or timestamps) in one access point list from
 * access points in another list, if the APs in the first list are present
 * in the second.
 *
 */
void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList *source)
{
	NMAPListIter	*iter;
	NMAccessPoint	*dest_ap;

	if (!dest || !source)
		return;

	if ((iter = nm_ap_list_iter_new (dest)))
	{
		while ((dest_ap = nm_ap_list_iter_next (iter)))
		{
			NMAccessPoint	*src_ap = NULL;

			if ((src_ap = nm_ap_list_get_ap_by_essid (source, nm_ap_get_essid (dest_ap))))
			{
				nm_ap_set_invalid (dest_ap, nm_ap_get_invalid (src_ap));
				nm_ap_set_security (dest_ap, nm_ap_get_security (src_ap));
				nm_ap_set_timestamp (dest_ap, nm_ap_get_timestamp (src_ap));
			}
		}
		nm_ap_list_iter_free (iter);
	}
}


/*
 * nm_ap_list_copy_one_essid_by_address
 *
 * If the access point doesn't have an ESSID, search through a list of access points
 * and find one (if any) that has the MAC address of the access point we're looking for.
 * If one is found, copy the essid over to the original access point.
 *
 */
void nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap, NMAccessPointList *search_list)
{
	NMAccessPoint	*found_ap;

	if (!ap || !search_list)
		return;

	if (!nm_ap_get_essid (ap) && (found_ap = nm_ap_list_get_ap_by_address (search_list, nm_ap_get_address (ap))))
	{
		if (nm_ap_get_essid (found_ap))
			nm_ap_set_essid (ap, nm_ap_get_essid (found_ap));
	}
}


/*
 * nm_ap_list_copy_essids_by_address
 *
 * For each blank-essid access point in the destination list, try to find
 * an access point in the source list that has the same MAC address, and if
 * its found, copy the source access point's essid to the dest access point.
 *
 */
void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointList *source)
{
	NMAPListIter	*iter;
	NMAccessPoint	*dest_ap;

	if (!dest || !source)
		return;

	if ((iter = nm_ap_list_iter_new (dest)))
	{
		while ((dest_ap = nm_ap_list_iter_next (iter)))
			nm_ap_list_copy_one_essid_by_address (dest_ap, source);

		nm_ap_list_iter_free (iter);
	}
}


/*
 * nm_ap_list_get_type
 *
 * Return the type of an AP list
 *
 */
NMNetworkType nm_ap_list_get_type (NMAccessPointList *list)
{
	g_return_val_if_fail (list != NULL, NETWORK_TYPE_UNKNOWN);

	return (list->type);
}


/*
 * nm_ap_list_lock
 *
 * Grab exclusive access to an access point list
 *
 */
gboolean nm_ap_list_lock (NMAccessPointList *list)
{
	g_return_val_if_fail (list != NULL, FALSE);

	return (nm_try_acquire_mutex (list->mutex, __FUNCTION__));
}


/*
 * nm_ap_list_unlock
 *
 * Give up access to an access point list
 *
 */
void nm_ap_list_unlock (NMAccessPointList *list)
{
	g_return_if_fail (list != NULL);

	nm_unlock_mutex (list->mutex, __FUNCTION__);
}



struct NMAPListIter
{
	NMAccessPointList	*list;
	GSList			*cur_pos;
	gboolean			 valid;
};


NMAPListIter * nm_ap_list_iter_new (NMAccessPointList *list)
{
	NMAPListIter	*iter;

	g_return_val_if_fail (list != NULL, NULL);

	if (!(iter = g_new0 (NMAPListIter, 1)))
		return (NULL);

	if (!nm_ap_list_lock (list))
	{
		g_free (iter);
		return (NULL);
	}

	iter->list = list;
	iter->cur_pos = list->ap_list;
	iter->valid = FALSE;

	return (iter);
}


NMAccessPoint * nm_ap_list_iter_get_ap (NMAPListIter *iter)
{
	g_return_val_if_fail (iter != NULL, NULL);
	g_return_val_if_fail (iter->valid, NULL);

	if (!iter->cur_pos)
		return (NULL);

	return ((NMAccessPoint *)(iter->cur_pos->data));
}


NMAccessPoint * nm_ap_list_iter_next (NMAPListIter *iter)
{
	g_return_val_if_fail (iter != NULL, NULL);

	if (iter->valid)
		iter->cur_pos = g_slist_next (iter->cur_pos);
	else
	{
		iter->valid = TRUE;
		iter->cur_pos = iter->list->ap_list;
	}
	return (nm_ap_list_iter_get_ap (iter));
}


void nm_ap_list_iter_free (NMAPListIter *iter)
{
	g_return_if_fail (iter != NULL);

	nm_ap_list_unlock (iter->list);
	memset (iter, 0, sizeof (struct NMAPListIter));
	g_free (iter);
}


/*
 * nm_ap_list_print_members
 *
 * Print the information about each access point in an AP list
 *
 */
void nm_ap_list_print_members (NMAccessPointList *list, const char *name)
{
	NMAccessPoint	*ap;
	NMAPListIter	*iter;
	int			 i = 0;

	g_return_if_fail (list != NULL);
	g_return_if_fail (name != NULL);

	if (!(iter = nm_ap_list_iter_new (list)))
		return;

	nm_warning ("AP_LIST_PRINT: printing members of '%s'", name);
	while ((ap = nm_ap_list_iter_next (iter)))
	{
		const GTimeVal *	timestamp = nm_ap_get_timestamp (ap);
		const GTimeVal *	seen = nm_ap_get_last_seen (ap);
		NMAPSecurity * 	security = nm_ap_get_security (ap);
		nm_warning ("\t%d)\tobj=%p, essid='%s', timestamp=%ld, key='%s', enc=%d, addr=%p, strength=%d, %s=%f, rate=%d, inval=%d, mode=%d, seen=%ld",
				i, ap, nm_ap_get_essid (ap), timestamp->tv_sec, nm_ap_security_get_key (security), nm_ap_get_encrypted (ap),
				nm_ap_get_address (ap), nm_ap_get_strength (ap), (nm_ap_get_freq (ap) < 20) ? "channel" : "freq", nm_ap_get_freq (ap), nm_ap_get_rate (ap),
				nm_ap_get_invalid (ap), nm_ap_get_mode (ap), seen->tv_sec);
		i++;
	}
	nm_warning ("AP_LIST_PRINT: done");
	nm_ap_list_iter_free (iter);
}