|
1 #ifndef WLAN_DEV_H |
|
2 #define WLAN_DEV_H |
|
3 |
|
4 /** |
|
5 * Copyright (C) 2007,2008 Nokia Corporation. All rights reserved. |
|
6 * |
|
7 * @author jukka.rissanen@nokia.com |
|
8 * |
|
9 * @file libicd-network-wlan-dev.h |
|
10 */ |
|
11 |
|
12 #include <glib.h> |
|
13 #include <dbus/dbus.h> |
|
14 #include <wlancond.h> |
|
15 #include <icd/network_api_defines.h> |
|
16 |
|
17 |
|
18 /* Difference between network attributes value and wlan capabilities: |
|
19 * |
|
20 * WLAN |
|
21 * Network capability Combined |
|
22 * LSB attribute (from wlancond.h) |
|
23 * ---- --------- ---------- -------- |
|
24 * 0 mode mode |
|
25 * 1 mode mode |
|
26 * 2 mode mode |
|
27 * 3 autoconnect attempt method |
|
28 * 4 encrypt method method |
|
29 * 5 encrypt method method |
|
30 * 6 encrypt method method |
|
31 * 7 encrypt method WPA2 |
|
32 * 8 WPA2 algorithm |
|
33 * 9 WPS algorithm |
|
34 * 10 WPS PIN algorithm |
|
35 * 11 WPS push button algorithm |
|
36 * 12 WPS configured WPS |
|
37 * 13 WPS PIN |
|
38 * 14 WPS push button |
|
39 * 15 WPS configured |
|
40 * 16 rate |
|
41 * 17 rate |
|
42 * 18 rate |
|
43 * 19 rate |
|
44 * 20 rate |
|
45 * 21 rate |
|
46 * 22 rate |
|
47 * 23 iap name rate iap name |
|
48 * 24 silent rate silent |
|
49 * 25 rate |
|
50 * 26 |
|
51 * 27 |
|
52 * 28 security algorithm |
|
53 * 29 always online security algorithm always online |
|
54 * 30 security algorithm |
|
55 * 31 security algorithm |
|
56 * MSB |
|
57 * |
|
58 * |
|
59 * Same view from different angle. |
|
60 * |
|
61 * MSB LSB (of 32 bits) |
|
62 * 10987654321098765432109876543210 |
|
63 * |
|
64 * WWWWaaaaWmmmmmmm Combined format |
|
65 * PPPPllllPeeeeooo |
|
66 * SSSSggggAttttddd |
|
67 * cbp oooo2hhhheee |
|
68 * fti oooo |
|
69 * gnn dddd |
|
70 * |
|
71 * aaaa Wmmmm mmm Capability format |
|
72 * llll Peeee ooo |
|
73 * gggg Atttt ddd |
|
74 * oooo 2hhhh eee |
|
75 * oooo |
|
76 * dddd |
|
77 * |
|
78 * |
|
79 * Note that WPS bits in nwattrs are moved towards MSB because algorithm |
|
80 * was there first and we do not want to break binary compatibility. |
|
81 */ |
|
82 |
|
83 /* capability bits inside network attributes var */ |
|
84 #define NWATTR_WPS_MASK 0x0000F000 |
|
85 #define NWATTR_ALGORITHM_MASK 0x00000F00 |
|
86 #define NWATTR_WPA2_MASK 0x00000080 |
|
87 #define NWATTR_METHOD_MASK 0x00000078 |
|
88 #define NWATTR_MODE_MASK 0x00000007 |
|
89 |
|
90 #define CAP_LOCALMASK 0x0FFFE008 |
|
91 |
|
92 /* how much to shift between capability and network attributes var */ |
|
93 #define CAP_SHIFT_WPS 3 |
|
94 #define CAP_SHIFT_ALGORITHM 20 |
|
95 #define CAP_SHIFT_WPA2 1 |
|
96 #define CAP_SHIFT_METHOD 1 |
|
97 #define CAP_SHIFT_MODE 0 |
|
98 #define CAP_SHIFT_ALWAYS_ONLINE 26 |
|
99 |
|
100 /* ------------------------------------------------------------------------- */ |
|
101 /* From combined to capability */ |
|
102 static inline dbus_uint32_t nwattr2cap(guint nwattrs, dbus_uint32_t *cap) |
|
103 { |
|
104 guint oldval = *cap; |
|
105 |
|
106 *cap &= CAP_LOCALMASK; /* clear old capabilities */ |
|
107 *cap |= |
|
108 ((nwattrs & ICD_NW_ATTR_ALWAYS_ONLINE) >> CAP_SHIFT_ALWAYS_ONLINE) | |
|
109 ((nwattrs & NWATTR_WPS_MASK) >> CAP_SHIFT_WPS) | |
|
110 ((nwattrs & NWATTR_ALGORITHM_MASK) << CAP_SHIFT_ALGORITHM) | |
|
111 ((nwattrs & NWATTR_WPA2_MASK) << CAP_SHIFT_WPA2) | |
|
112 ((nwattrs & NWATTR_METHOD_MASK) << CAP_SHIFT_METHOD) | |
|
113 (nwattrs & NWATTR_MODE_MASK); |
|
114 |
|
115 return oldval; |
|
116 } |
|
117 |
|
118 |
|
119 /* ------------------------------------------------------------------------- */ |
|
120 /* From capability to combined */ |
|
121 static inline guint cap2nwattr(dbus_uint32_t cap, guint *nwattrs) |
|
122 { |
|
123 guint oldval = *nwattrs; |
|
124 |
|
125 *nwattrs &= ~ICD_NW_ATTR_LOCALMASK; /* clear old capabilities */ |
|
126 *nwattrs |= |
|
127 #ifdef WLANCOND_WPS_MASK |
|
128 ((cap & WLANCOND_WPS_MASK) << CAP_SHIFT_WPS) | |
|
129 #endif |
|
130 ((cap & (WLANCOND_ENCRYPT_ALG_MASK | |
|
131 WLANCOND_ENCRYPT_GROUP_ALG_MASK)) >> CAP_SHIFT_ALGORITHM)| |
|
132 ((cap & WLANCOND_ENCRYPT_WPA2_MASK) >> CAP_SHIFT_WPA2) | |
|
133 ((cap & WLANCOND_ENCRYPT_METHOD_MASK) >> CAP_SHIFT_METHOD) | |
|
134 (cap & WLANCOND_MODE_MASK); |
|
135 |
|
136 return oldval; |
|
137 } |
|
138 |
|
139 |
|
140 #endif |