• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/iwinfo/iwinfo_lib.c

  1 /*
  2  * iwinfo - Wireless Information Library - Lua Bindings
  3  *
  4  *   Copyright (C) 2009-2013 Jo-Philipp Wich <xm@subsignal.org>
  5  *
  6  * The iwinfo library is free software: you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License version 2
  8  * as published by the Free Software Foundation.
  9  *
 10  * The iwinfo library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 13  * See the GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License along
 16  * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
 17  */
 18 
 19 #include "iwinfo.h"
 20 
 21 
 22 /*
 23  * name constants
 24  */
 25 const char * const IWINFO_80211_NAMES[IWINFO_80211_COUNT] = {
 26         "a",
 27         "b",
 28         "g",
 29         "n",
 30         "ac",
 31         "ad",
 32         "ax",
 33         "be",
 34 };
 35 
 36 const char * const IWINFO_BAND_NAMES[IWINFO_BAND_COUNT] = {
 37         "2.4 GHz",
 38         "5 GHz",
 39         "6 GHz",
 40         "60 GHz",
 41 };
 42 
 43 const char * const IWINFO_CIPHER_NAMES[IWINFO_CIPHER_COUNT] = {
 44         "NONE",
 45         "WEP-40",
 46         "TKIP",
 47         "WRAP",
 48         "CCMP",
 49         "WEP-104",
 50         "AES-OCB",
 51         "CKIP",
 52         "GCMP",
 53         "CCMP-256",
 54         "GCMP-256",
 55 };
 56 
 57 const char * const IWINFO_KMGMT_NAMES[IWINFO_KMGMT_COUNT] = {
 58         "NONE",
 59         "802.1X",
 60         "PSK",
 61         "SAE",
 62         "OWE",
 63 };
 64 
 65 const char * const IWINFO_AUTH_NAMES[IWINFO_AUTH_COUNT] = {
 66         "OPEN",
 67         "SHARED",
 68 };
 69 
 70 const char * const IWINFO_OPMODE_NAMES[IWINFO_OPMODE_COUNT] = {
 71         "Unknown",
 72         "Master",
 73         "Ad-Hoc",
 74         "Client",
 75         "Monitor",
 76         "Master (VLAN)",
 77         "WDS",
 78         "Mesh Point",
 79         "P2P Client",
 80         "P2P Go",
 81 };
 82 
 83 const char * const IWINFO_HTMODE_NAMES[IWINFO_HTMODE_COUNT] = {
 84         "HT20",
 85         "HT40",
 86         "VHT20",
 87         "VHT40",
 88         "VHT80",
 89         "VHT80+80",
 90         "VHT160",
 91         "NOHT",
 92         "HE20",
 93         "HE40",
 94         "HE80",
 95         "HE80+80",
 96         "HE160",
 97         "EHT20",
 98         "EHT40",
 99         "EHT80",
100         "EHT80+80",
101         "EHT160",
102         "EHT320",
103 };
104 
105 const char * const IWINFO_FREQ_FLAG_NAMES[IWINFO_FREQ_FLAG_COUNT] = {
106         "NO_10MHZ",
107         "NO_20MHZ",
108         "NO_HT40+",
109         "NO_HT40-",
110         "NO_80MHZ",
111         "NO_160MHZ",
112         "NO_HE",
113         "NO_IR",
114         "INDOOR_ONLY",
115 };
116 
117 const char * const ht_secondary_offset[4] = {
118         "no secondary",
119         "above",
120         "[reserved!]",
121         "below",
122 };
123 
124 const uint16_t ht_chan_width[2] = {
125         20,
126         2040,
127 };
128 
129 const uint16_t vht_chan_width[4] = {
130         40, /* 40 MHz or lower (refer to ht to a more precise width) */
131         80, /* 80 MHz */
132         160, /* 160 MHz */
133         8080, /* 80+80 MHz */
134 };
135 
136 /*
137  * ISO3166 country labels
138  */
139 
140 const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[] = {
141         { 0x3030 /* 00 */, "World" },
142         { 0x4144 /* AD */, "Andorra" },
143         { 0x4145 /* AE */, "United Arab Emirates" },
144         { 0x4146 /* AF */, "Afghanistan" },
145         { 0x4147 /* AG */, "Antigua and Barbuda" },
146         { 0x4149 /* AI */, "Anguilla" },
147         { 0x414C /* AL */, "Albania" },
148         { 0x414D /* AM */, "Armenia" },
149         { 0x414E /* AN */, "Netherlands Antilles" },
150         { 0x414F /* AO */, "Angola" },
151         { 0x4151 /* AQ */, "Antarctica" },
152         { 0x4152 /* AR */, "Argentina" },
153         { 0x4153 /* AS */, "American Samoa" },
154         { 0x4154 /* AT */, "Austria" },
155         { 0x4155 /* AU */, "Australia" },
156         { 0x4157 /* AW */, "Aruba" },
157         { 0x4158 /* AX */, "Aland Islands" },
158         { 0x415A /* AZ */, "Azerbaijan" },
159         { 0x4241 /* BA */, "Bosnia and Herzegovina" },
160         { 0x4242 /* BB */, "Barbados" },
161         { 0x4244 /* BD */, "Bangladesh" },
162         { 0x4245 /* BE */, "Belgium" },
163         { 0x4246 /* BF */, "Burkina Faso" },
164         { 0x4247 /* BG */, "Bulgaria" },
165         { 0x4248 /* BH */, "Bahrain" },
166         { 0x4249 /* BI */, "Burundi" },
167         { 0x424A /* BJ */, "Benin" },
168         { 0x424C /* BL */, "Saint Barthelemy" },
169         { 0x424D /* BM */, "Bermuda" },
170         { 0x424E /* BN */, "Brunei Darussalam" },
171         { 0x424F /* BO */, "Bolivia" },
172         { 0x4252 /* BR */, "Brazil" },
173         { 0x4253 /* BS */, "Bahamas" },
174         { 0x4254 /* BT */, "Bhutan" },
175         { 0x4256 /* BV */, "Bouvet Island" },
176         { 0x4257 /* BW */, "Botswana" },
177         { 0x4259 /* BY */, "Belarus" },
178         { 0x425A /* BZ */, "Belize" },
179         { 0x4341 /* CA */, "Canada" },
180         { 0x4343 /* CC */, "Cocos (Keeling) Islands" },
181         { 0x4344 /* CD */, "Congo" },
182         { 0x4346 /* CF */, "Central African Republic" },
183         { 0x4347 /* CG */, "Congo" },
184         { 0x4348 /* CH */, "Switzerland" },
185         { 0x4349 /* CI */, "Cote d'Ivoire" },
186         { 0x434B /* CK */, "Cook Islands" },
187         { 0x434C /* CL */, "Chile" },
188         { 0x434D /* CM */, "Cameroon" },
189         { 0x434E /* CN */, "China" },
190         { 0x434F /* CO */, "Colombia" },
191         { 0x4352 /* CR */, "Costa Rica" },
192         { 0x4355 /* CU */, "Cuba" },
193         { 0x4356 /* CV */, "Cape Verde" },
194         { 0x4358 /* CX */, "Christmas Island" },
195         { 0x4359 /* CY */, "Cyprus" },
196         { 0x435A /* CZ */, "Czech Republic" },
197         { 0x4445 /* DE */, "Germany" },
198         { 0x444A /* DJ */, "Djibouti" },
199         { 0x444B /* DK */, "Denmark" },
200         { 0x444D /* DM */, "Dominica" },
201         { 0x444F /* DO */, "Dominican Republic" },
202         { 0x445A /* DZ */, "Algeria" },
203         { 0x4543 /* EC */, "Ecuador" },
204         { 0x4545 /* EE */, "Estonia" },
205         { 0x4547 /* EG */, "Egypt" },
206         { 0x4548 /* EH */, "Western Sahara" },
207         { 0x4552 /* ER */, "Eritrea" },
208         { 0x4553 /* ES */, "Spain" },
209         { 0x4554 /* ET */, "Ethiopia" },
210         { 0x4649 /* FI */, "Finland" },
211         { 0x464A /* FJ */, "Fiji" },
212         { 0x464B /* FK */, "Falkland Islands" },
213         { 0x464D /* FM */, "Micronesia" },
214         { 0x464F /* FO */, "Faroe Islands" },
215         { 0x4652 /* FR */, "France" },
216         { 0x4741 /* GA */, "Gabon" },
217         { 0x4742 /* GB */, "United Kingdom" },
218         { 0x4744 /* GD */, "Grenada" },
219         { 0x4745 /* GE */, "Georgia" },
220         { 0x4746 /* GF */, "French Guiana" },
221         { 0x4747 /* GG */, "Guernsey" },
222         { 0x4748 /* GH */, "Ghana" },
223         { 0x4749 /* GI */, "Gibraltar" },
224         { 0x474C /* GL */, "Greenland" },
225         { 0x474D /* GM */, "Gambia" },
226         { 0x474E /* GN */, "Guinea" },
227         { 0x4750 /* GP */, "Guadeloupe" },
228         { 0x4751 /* GQ */, "Equatorial Guinea" },
229         { 0x4752 /* GR */, "Greece" },
230         { 0x4753 /* GS */, "South Georgia" },
231         { 0x4754 /* GT */, "Guatemala" },
232         { 0x4755 /* GU */, "Guam" },
233         { 0x4757 /* GW */, "Guinea-Bissau" },
234         { 0x4759 /* GY */, "Guyana" },
235         { 0x484B /* HK */, "Hong Kong" },
236         { 0x484D /* HM */, "Heard and McDonald Islands" },
237         { 0x484E /* HN */, "Honduras" },
238         { 0x4852 /* HR */, "Croatia" },
239         { 0x4854 /* HT */, "Haiti" },
240         { 0x4855 /* HU */, "Hungary" },
241         { 0x4944 /* ID */, "Indonesia" },
242         { 0x4945 /* IE */, "Ireland" },
243         { 0x494C /* IL */, "Israel" },
244         { 0x494D /* IM */, "Isle of Man" },
245         { 0x494E /* IN */, "India" },
246         { 0x494F /* IO */, "Chagos Islands" },
247         { 0x4951 /* IQ */, "Iraq" },
248         { 0x4952 /* IR */, "Iran" },
249         { 0x4953 /* IS */, "Iceland" },
250         { 0x4954 /* IT */, "Italy" },
251         { 0x4A45 /* JE */, "Jersey" },
252         { 0x4A4D /* JM */, "Jamaica" },
253         { 0x4A4F /* JO */, "Jordan" },
254         { 0x4A50 /* JP */, "Japan" },
255         { 0x4B45 /* KE */, "Kenya" },
256         { 0x4B47 /* KG */, "Kyrgyzstan" },
257         { 0x4B48 /* KH */, "Cambodia" },
258         { 0x4B49 /* KI */, "Kiribati" },
259         { 0x4B4D /* KM */, "Comoros" },
260         { 0x4B4E /* KN */, "Saint Kitts and Nevis" },
261         { 0x4B50 /* KP */, "North Korea" },
262         { 0x4B52 /* KR */, "South Korea" },
263         { 0x4B57 /* KW */, "Kuwait" },
264         { 0x4B59 /* KY */, "Cayman Islands" },
265         { 0x4B5A /* KZ */, "Kazakhstan" },
266         { 0x4C41 /* LA */, "Laos" },
267         { 0x4C42 /* LB */, "Lebanon" },
268         { 0x4C43 /* LC */, "Saint Lucia" },
269         { 0x4C49 /* LI */, "Liechtenstein" },
270         { 0x4C4B /* LK */, "Sri Lanka" },
271         { 0x4C52 /* LR */, "Liberia" },
272         { 0x4C53 /* LS */, "Lesotho" },
273         { 0x4C54 /* LT */, "Lithuania" },
274         { 0x4C55 /* LU */, "Luxembourg" },
275         { 0x4C56 /* LV */, "Latvia" },
276         { 0x4C59 /* LY */, "Libyan Arab Jamahiriya" },
277         { 0x4D41 /* MA */, "Morocco" },
278         { 0x4D43 /* MC */, "Monaco" },
279         { 0x4D44 /* MD */, "Moldova" },
280         { 0x4D45 /* ME */, "Montenegro" },
281         { 0x4D46 /* MF */, "Saint Martin (French part)" },
282         { 0x4D47 /* MG */, "Madagascar" },
283         { 0x4D48 /* MH */, "Marshall Islands" },
284         { 0x4D4B /* MK */, "Macedonia" },
285         { 0x4D4C /* ML */, "Mali" },
286         { 0x4D4D /* MM */, "Myanmar" },
287         { 0x4D4E /* MN */, "Mongolia" },
288         { 0x4D4F /* MO */, "Macao" },
289         { 0x4D50 /* MP */, "Northern Mariana Islands" },
290         { 0x4D51 /* MQ */, "Martinique" },
291         { 0x4D52 /* MR */, "Mauritania" },
292         { 0x4D53 /* MS */, "Montserrat" },
293         { 0x4D54 /* MT */, "Malta" },
294         { 0x4D55 /* MU */, "Mauritius" },
295         { 0x4D56 /* MV */, "Maldives" },
296         { 0x4D57 /* MW */, "Malawi" },
297         { 0x4D58 /* MX */, "Mexico" },
298         { 0x4D59 /* MY */, "Malaysia" },
299         { 0x4D5A /* MZ */, "Mozambique" },
300         { 0x4E41 /* NA */, "Namibia" },
301         { 0x4E43 /* NC */, "New Caledonia" },
302         { 0x4E45 /* NE */, "Niger" },
303         { 0x4E46 /* NF */, "Norfolk Island" },
304         { 0x4E47 /* NG */, "Nigeria" },
305         { 0x4E49 /* NI */, "Nicaragua" },
306         { 0x4E4C /* NL */, "Netherlands" },
307         { 0x4E4F /* NO */, "Norway" },
308         { 0x4E50 /* NP */, "Nepal" },
309         { 0x4E52 /* NR */, "Nauru" },
310         { 0x4E55 /* NU */, "Niue" },
311         { 0x4E5A /* NZ */, "New Zealand" },
312         { 0x4F4D /* OM */, "Oman" },
313         { 0x5041 /* PA */, "Panama" },
314         { 0x5045 /* PE */, "Peru" },
315         { 0x5046 /* PF */, "French Polynesia" },
316         { 0x5047 /* PG */, "Papua New Guinea" },
317         { 0x5048 /* PH */, "Philippines" },
318         { 0x504B /* PK */, "Pakistan" },
319         { 0x504C /* PL */, "Poland" },
320         { 0x504D /* PM */, "Saint Pierre and Miquelon" },
321         { 0x504E /* PN */, "Pitcairn" },
322         { 0x5052 /* PR */, "Puerto Rico" },
323         { 0x5053 /* PS */, "Palestinian Territory" },
324         { 0x5054 /* PT */, "Portugal" },
325         { 0x5057 /* PW */, "Palau" },
326         { 0x5059 /* PY */, "Paraguay" },
327         { 0x5141 /* QA */, "Qatar" },
328         { 0x5245 /* RE */, "Reunion" },
329         { 0x524F /* RO */, "Romania" },
330         { 0x5253 /* RS */, "Serbia" },
331         { 0x5255 /* RU */, "Russian Federation" },
332         { 0x5257 /* RW */, "Rwanda" },
333         { 0x5341 /* SA */, "Saudi Arabia" },
334         { 0x5342 /* SB */, "Solomon Islands" },
335         { 0x5343 /* SC */, "Seychelles" },
336         { 0x5344 /* SD */, "Sudan" },
337         { 0x5345 /* SE */, "Sweden" },
338         { 0x5347 /* SG */, "Singapore" },
339         { 0x5348 /* SH */, "St. Helena and Dependencies" },
340         { 0x5349 /* SI */, "Slovenia" },
341         { 0x534A /* SJ */, "Svalbard and Jan Mayen" },
342         { 0x534B /* SK */, "Slovakia" },
343         { 0x534C /* SL */, "Sierra Leone" },
344         { 0x534D /* SM */, "San Marino" },
345         { 0x534E /* SN */, "Senegal" },
346         { 0x534F /* SO */, "Somalia" },
347         { 0x5352 /* SR */, "Suriname" },
348         { 0x5354 /* ST */, "Sao Tome and Principe" },
349         { 0x5356 /* SV */, "El Salvador" },
350         { 0x5359 /* SY */, "Syrian Arab Republic" },
351         { 0x535A /* SZ */, "Swaziland" },
352         { 0x5443 /* TC */, "Turks and Caicos Islands" },
353         { 0x5444 /* TD */, "Chad" },
354         { 0x5446 /* TF */, "French Southern Territories" },
355         { 0x5447 /* TG */, "Togo" },
356         { 0x5448 /* TH */, "Thailand" },
357         { 0x544A /* TJ */, "Tajikistan" },
358         { 0x544B /* TK */, "Tokelau" },
359         { 0x544C /* TL */, "Timor-Leste" },
360         { 0x544D /* TM */, "Turkmenistan" },
361         { 0x544E /* TN */, "Tunisia" },
362         { 0x544F /* TO */, "Tonga" },
363         { 0x5452 /* TR */, "Turkey" },
364         { 0x5454 /* TT */, "Trinidad and Tobago" },
365         { 0x5456 /* TV */, "Tuvalu" },
366         { 0x5457 /* TW */, "Taiwan" },
367         { 0x545A /* TZ */, "Tanzania" },
368         { 0x5541 /* UA */, "Ukraine" },
369         { 0x5547 /* UG */, "Uganda" },
370         { 0x554D /* UM */, "U.S. Minor Outlying Islands" },
371         { 0x5553 /* US */, "United States" },
372         { 0x5559 /* UY */, "Uruguay" },
373         { 0x555A /* UZ */, "Uzbekistan" },
374         { 0x5641 /* VA */, "Vatican City State" },
375         { 0x5643 /* VC */, "St. Vincent and Grenadines" },
376         { 0x5645 /* VE */, "Venezuela" },
377         { 0x5647 /* VG */, "Virgin Islands, British" },
378         { 0x5649 /* VI */, "Virgin Islands, U.S." },
379         { 0x564E /* VN */, "Viet Nam" },
380         { 0x5655 /* VU */, "Vanuatu" },
381         { 0x5746 /* WF */, "Wallis and Futuna" },
382         { 0x5753 /* WS */, "Samoa" },
383         { 0x5945 /* YE */, "Yemen" },
384         { 0x5954 /* YT */, "Mayotte" },
385         { 0x5A41 /* ZA */, "South Africa" },
386         { 0x5A4D /* ZM */, "Zambia" },
387         { 0x5A57 /* ZW */, "Zimbabwe" },
388         { 0,               "" }
389 };
390 
391 static const struct iwinfo_ops *backends[] = {
392 #ifdef USE_NL80211
393         &nl80211_ops,
394 #endif
395 #ifdef USE_MADWIFI
396         &madwifi_ops,
397 #endif
398 #ifdef USE_WL
399         &wl_ops,
400 #endif
401 #ifdef USE_WEXT
402         &wext_ops,
403 #endif
404 };
405 
406 const char * iwinfo_type(const char *ifname)
407 {
408         const struct iwinfo_ops *ops = iwinfo_backend(ifname);
409         if (!ops)
410                 return NULL;
411 
412         return ops->name;
413 }
414 
415 const struct iwinfo_ops * iwinfo_backend(const char *ifname)
416 {
417         int i;
418 
419         for (i = 0; i < ARRAY_SIZE(backends); i++)
420                 if (backends[i]->probe(ifname))
421                         return backends[i];
422 
423         return NULL;
424 }
425 
426 const struct iwinfo_ops * iwinfo_backend_by_name(const char *name)
427 {
428         int i;
429 
430         for (i = 0; i < ARRAY_SIZE(backends); i++)
431                 if (!strcmp(backends[i]->name, name))
432                         return backends[i];
433 
434         return NULL;
435 }
436 
437 void iwinfo_finish(void)
438 {
439         int i;
440 
441         for (i = 0; i < ARRAY_SIZE(backends); i++)
442                 backends[i]->close();
443 
444         iwinfo_close();
445 }
446 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt