2
0

iwinfo_lib.c 11 KB

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