oid_mgt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /*
  2. * Copyright (C) 2003,2004 Aurelien Alleaume <slts@free.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/slab.h>
  19. #include "prismcompat.h"
  20. #include "islpci_dev.h"
  21. #include "islpci_mgt.h"
  22. #include "isl_oid.h"
  23. #include "oid_mgt.h"
  24. #include "isl_ioctl.h"
  25. /* to convert between channel and freq */
  26. static const int frequency_list_bg[] = { 2412, 2417, 2422, 2427, 2432,
  27. 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484
  28. };
  29. int
  30. channel_of_freq(int f)
  31. {
  32. int c = 0;
  33. if ((f >= 2412) && (f <= 2484)) {
  34. while ((c < 14) && (f != frequency_list_bg[c]))
  35. c++;
  36. return (c >= 14) ? 0 : ++c;
  37. } else if ((f >= (int) 5000) && (f <= (int) 6000)) {
  38. return ( (f - 5000) / 5 );
  39. } else
  40. return 0;
  41. }
  42. #define OID_STRUCT(name,oid,s,t) [name] = {oid, 0, sizeof(s), t}
  43. #define OID_STRUCT_C(name,oid,s,t) OID_STRUCT(name,oid,s,t | OID_FLAG_CACHED)
  44. #define OID_U32(name,oid) OID_STRUCT(name,oid,u32,OID_TYPE_U32)
  45. #define OID_U32_C(name,oid) OID_STRUCT_C(name,oid,u32,OID_TYPE_U32)
  46. #define OID_STRUCT_MLME(name,oid) OID_STRUCT(name,oid,struct obj_mlme,OID_TYPE_MLME)
  47. #define OID_STRUCT_MLMEEX(name,oid) OID_STRUCT(name,oid,struct obj_mlmeex,OID_TYPE_MLMEEX)
  48. #define OID_UNKNOWN(name,oid) OID_STRUCT(name,oid,0,0)
  49. struct oid_t isl_oid[] = {
  50. OID_STRUCT(GEN_OID_MACADDRESS, 0x00000000, u8[6], OID_TYPE_ADDR),
  51. OID_U32(GEN_OID_LINKSTATE, 0x00000001),
  52. OID_UNKNOWN(GEN_OID_WATCHDOG, 0x00000002),
  53. OID_UNKNOWN(GEN_OID_MIBOP, 0x00000003),
  54. OID_UNKNOWN(GEN_OID_OPTIONS, 0x00000004),
  55. OID_UNKNOWN(GEN_OID_LEDCONFIG, 0x00000005),
  56. /* 802.11 */
  57. OID_U32_C(DOT11_OID_BSSTYPE, 0x10000000),
  58. OID_STRUCT_C(DOT11_OID_BSSID, 0x10000001, u8[6], OID_TYPE_RAW),
  59. OID_STRUCT_C(DOT11_OID_SSID, 0x10000002, struct obj_ssid,
  60. OID_TYPE_SSID),
  61. OID_U32(DOT11_OID_STATE, 0x10000003),
  62. OID_U32(DOT11_OID_AID, 0x10000004),
  63. OID_STRUCT(DOT11_OID_COUNTRYSTRING, 0x10000005, u8[4], OID_TYPE_RAW),
  64. OID_STRUCT_C(DOT11_OID_SSIDOVERRIDE, 0x10000006, struct obj_ssid,
  65. OID_TYPE_SSID),
  66. OID_U32(DOT11_OID_MEDIUMLIMIT, 0x11000000),
  67. OID_U32_C(DOT11_OID_BEACONPERIOD, 0x11000001),
  68. OID_U32(DOT11_OID_DTIMPERIOD, 0x11000002),
  69. OID_U32(DOT11_OID_ATIMWINDOW, 0x11000003),
  70. OID_U32(DOT11_OID_LISTENINTERVAL, 0x11000004),
  71. OID_U32(DOT11_OID_CFPPERIOD, 0x11000005),
  72. OID_U32(DOT11_OID_CFPDURATION, 0x11000006),
  73. OID_U32_C(DOT11_OID_AUTHENABLE, 0x12000000),
  74. OID_U32_C(DOT11_OID_PRIVACYINVOKED, 0x12000001),
  75. OID_U32_C(DOT11_OID_EXUNENCRYPTED, 0x12000002),
  76. OID_U32_C(DOT11_OID_DEFKEYID, 0x12000003),
  77. [DOT11_OID_DEFKEYX] = {0x12000004, 3, sizeof (struct obj_key),
  78. OID_FLAG_CACHED | OID_TYPE_KEY}, /* DOT11_OID_DEFKEY1,...DOT11_OID_DEFKEY4 */
  79. OID_UNKNOWN(DOT11_OID_STAKEY, 0x12000008),
  80. OID_U32(DOT11_OID_REKEYTHRESHOLD, 0x12000009),
  81. OID_UNKNOWN(DOT11_OID_STASC, 0x1200000a),
  82. OID_U32(DOT11_OID_PRIVTXREJECTED, 0x1a000000),
  83. OID_U32(DOT11_OID_PRIVRXPLAIN, 0x1a000001),
  84. OID_U32(DOT11_OID_PRIVRXFAILED, 0x1a000002),
  85. OID_U32(DOT11_OID_PRIVRXNOKEY, 0x1a000003),
  86. OID_U32_C(DOT11_OID_RTSTHRESH, 0x13000000),
  87. OID_U32_C(DOT11_OID_FRAGTHRESH, 0x13000001),
  88. OID_U32_C(DOT11_OID_SHORTRETRIES, 0x13000002),
  89. OID_U32_C(DOT11_OID_LONGRETRIES, 0x13000003),
  90. OID_U32_C(DOT11_OID_MAXTXLIFETIME, 0x13000004),
  91. OID_U32(DOT11_OID_MAXRXLIFETIME, 0x13000005),
  92. OID_U32(DOT11_OID_AUTHRESPTIMEOUT, 0x13000006),
  93. OID_U32(DOT11_OID_ASSOCRESPTIMEOUT, 0x13000007),
  94. OID_UNKNOWN(DOT11_OID_ALOFT_TABLE, 0x1d000000),
  95. OID_UNKNOWN(DOT11_OID_ALOFT_CTRL_TABLE, 0x1d000001),
  96. OID_UNKNOWN(DOT11_OID_ALOFT_RETREAT, 0x1d000002),
  97. OID_UNKNOWN(DOT11_OID_ALOFT_PROGRESS, 0x1d000003),
  98. OID_U32(DOT11_OID_ALOFT_FIXEDRATE, 0x1d000004),
  99. OID_UNKNOWN(DOT11_OID_ALOFT_RSSIGRAPH, 0x1d000005),
  100. OID_UNKNOWN(DOT11_OID_ALOFT_CONFIG, 0x1d000006),
  101. [DOT11_OID_VDCFX] = {0x1b000000, 7, 0, 0},
  102. OID_U32(DOT11_OID_MAXFRAMEBURST, 0x1b000008),
  103. OID_U32(DOT11_OID_PSM, 0x14000000),
  104. OID_U32(DOT11_OID_CAMTIMEOUT, 0x14000001),
  105. OID_U32(DOT11_OID_RECEIVEDTIMS, 0x14000002),
  106. OID_U32(DOT11_OID_ROAMPREFERENCE, 0x14000003),
  107. OID_U32(DOT11_OID_BRIDGELOCAL, 0x15000000),
  108. OID_U32(DOT11_OID_CLIENTS, 0x15000001),
  109. OID_U32(DOT11_OID_CLIENTSASSOCIATED, 0x15000002),
  110. [DOT11_OID_CLIENTX] = {0x15000003, 2006, 0, 0}, /* DOT11_OID_CLIENTX,...DOT11_OID_CLIENT2007 */
  111. OID_STRUCT(DOT11_OID_CLIENTFIND, 0x150007DB, u8[6], OID_TYPE_ADDR),
  112. OID_STRUCT(DOT11_OID_WDSLINKADD, 0x150007DC, u8[6], OID_TYPE_ADDR),
  113. OID_STRUCT(DOT11_OID_WDSLINKREMOVE, 0x150007DD, u8[6], OID_TYPE_ADDR),
  114. OID_STRUCT(DOT11_OID_EAPAUTHSTA, 0x150007DE, u8[6], OID_TYPE_ADDR),
  115. OID_STRUCT(DOT11_OID_EAPUNAUTHSTA, 0x150007DF, u8[6], OID_TYPE_ADDR),
  116. OID_U32_C(DOT11_OID_DOT1XENABLE, 0x150007E0),
  117. OID_UNKNOWN(DOT11_OID_MICFAILURE, 0x150007E1),
  118. OID_UNKNOWN(DOT11_OID_REKEYINDICATE, 0x150007E2),
  119. OID_U32(DOT11_OID_MPDUTXSUCCESSFUL, 0x16000000),
  120. OID_U32(DOT11_OID_MPDUTXONERETRY, 0x16000001),
  121. OID_U32(DOT11_OID_MPDUTXMULTIPLERETRIES, 0x16000002),
  122. OID_U32(DOT11_OID_MPDUTXFAILED, 0x16000003),
  123. OID_U32(DOT11_OID_MPDURXSUCCESSFUL, 0x16000004),
  124. OID_U32(DOT11_OID_MPDURXDUPS, 0x16000005),
  125. OID_U32(DOT11_OID_RTSSUCCESSFUL, 0x16000006),
  126. OID_U32(DOT11_OID_RTSFAILED, 0x16000007),
  127. OID_U32(DOT11_OID_ACKFAILED, 0x16000008),
  128. OID_U32(DOT11_OID_FRAMERECEIVES, 0x16000009),
  129. OID_U32(DOT11_OID_FRAMEERRORS, 0x1600000A),
  130. OID_U32(DOT11_OID_FRAMEABORTS, 0x1600000B),
  131. OID_U32(DOT11_OID_FRAMEABORTSPHY, 0x1600000C),
  132. OID_U32(DOT11_OID_SLOTTIME, 0x17000000),
  133. OID_U32(DOT11_OID_CWMIN, 0x17000001),
  134. OID_U32(DOT11_OID_CWMAX, 0x17000002),
  135. OID_U32(DOT11_OID_ACKWINDOW, 0x17000003),
  136. OID_U32(DOT11_OID_ANTENNARX, 0x17000004),
  137. OID_U32(DOT11_OID_ANTENNATX, 0x17000005),
  138. OID_U32(DOT11_OID_ANTENNADIVERSITY, 0x17000006),
  139. OID_U32_C(DOT11_OID_CHANNEL, 0x17000007),
  140. OID_U32_C(DOT11_OID_EDTHRESHOLD, 0x17000008),
  141. OID_U32(DOT11_OID_PREAMBLESETTINGS, 0x17000009),
  142. OID_STRUCT(DOT11_OID_RATES, 0x1700000A, u8[IWMAX_BITRATES + 1],
  143. OID_TYPE_RAW),
  144. OID_U32(DOT11_OID_CCAMODESUPPORTED, 0x1700000B),
  145. OID_U32(DOT11_OID_CCAMODE, 0x1700000C),
  146. OID_UNKNOWN(DOT11_OID_RSSIVECTOR, 0x1700000D),
  147. OID_UNKNOWN(DOT11_OID_OUTPUTPOWERTABLE, 0x1700000E),
  148. OID_U32(DOT11_OID_OUTPUTPOWER, 0x1700000F),
  149. OID_STRUCT(DOT11_OID_SUPPORTEDRATES, 0x17000010,
  150. u8[IWMAX_BITRATES + 1], OID_TYPE_RAW),
  151. OID_U32_C(DOT11_OID_FREQUENCY, 0x17000011),
  152. [DOT11_OID_SUPPORTEDFREQUENCIES] =
  153. {0x17000012, 0, sizeof (struct obj_frequencies)
  154. + sizeof (u16) * IWMAX_FREQ, OID_TYPE_FREQUENCIES},
  155. OID_U32(DOT11_OID_NOISEFLOOR, 0x17000013),
  156. OID_STRUCT(DOT11_OID_FREQUENCYACTIVITY, 0x17000014, u8[IWMAX_FREQ + 1],
  157. OID_TYPE_RAW),
  158. OID_UNKNOWN(DOT11_OID_IQCALIBRATIONTABLE, 0x17000015),
  159. OID_U32(DOT11_OID_NONERPPROTECTION, 0x17000016),
  160. OID_U32(DOT11_OID_SLOTSETTINGS, 0x17000017),
  161. OID_U32(DOT11_OID_NONERPTIMEOUT, 0x17000018),
  162. OID_U32(DOT11_OID_PROFILES, 0x17000019),
  163. OID_STRUCT(DOT11_OID_EXTENDEDRATES, 0x17000020,
  164. u8[IWMAX_BITRATES + 1], OID_TYPE_RAW),
  165. OID_STRUCT_MLME(DOT11_OID_DEAUTHENTICATE, 0x18000000),
  166. OID_STRUCT_MLME(DOT11_OID_AUTHENTICATE, 0x18000001),
  167. OID_STRUCT_MLME(DOT11_OID_DISASSOCIATE, 0x18000002),
  168. OID_STRUCT_MLME(DOT11_OID_ASSOCIATE, 0x18000003),
  169. OID_UNKNOWN(DOT11_OID_SCAN, 0x18000004),
  170. OID_STRUCT_MLMEEX(DOT11_OID_BEACON, 0x18000005),
  171. OID_STRUCT_MLMEEX(DOT11_OID_PROBE, 0x18000006),
  172. OID_STRUCT_MLMEEX(DOT11_OID_DEAUTHENTICATEEX, 0x18000007),
  173. OID_STRUCT_MLMEEX(DOT11_OID_AUTHENTICATEEX, 0x18000008),
  174. OID_STRUCT_MLMEEX(DOT11_OID_DISASSOCIATEEX, 0x18000009),
  175. OID_STRUCT_MLMEEX(DOT11_OID_ASSOCIATEEX, 0x1800000A),
  176. OID_STRUCT_MLMEEX(DOT11_OID_REASSOCIATE, 0x1800000B),
  177. OID_STRUCT_MLMEEX(DOT11_OID_REASSOCIATEEX, 0x1800000C),
  178. OID_U32(DOT11_OID_NONERPSTATUS, 0x1E000000),
  179. OID_U32(DOT11_OID_STATIMEOUT, 0x19000000),
  180. OID_U32_C(DOT11_OID_MLMEAUTOLEVEL, 0x19000001),
  181. OID_U32(DOT11_OID_BSSTIMEOUT, 0x19000002),
  182. [DOT11_OID_ATTACHMENT] = {0x19000003, 0,
  183. sizeof(struct obj_attachment), OID_TYPE_ATTACH},
  184. OID_STRUCT_C(DOT11_OID_PSMBUFFER, 0x19000004, struct obj_buffer,
  185. OID_TYPE_BUFFER),
  186. OID_U32(DOT11_OID_BSSS, 0x1C000000),
  187. [DOT11_OID_BSSX] = {0x1C000001, 63, sizeof (struct obj_bss),
  188. OID_TYPE_BSS}, /*DOT11_OID_BSS1,...,DOT11_OID_BSS64 */
  189. OID_STRUCT(DOT11_OID_BSSFIND, 0x1C000042, struct obj_bss, OID_TYPE_BSS),
  190. [DOT11_OID_BSSLIST] = {0x1C000043, 0, sizeof (struct
  191. obj_bsslist) +
  192. sizeof (struct obj_bss[IWMAX_BSS]),
  193. OID_TYPE_BSSLIST},
  194. OID_UNKNOWN(OID_INL_TUNNEL, 0xFF020000),
  195. OID_UNKNOWN(OID_INL_MEMADDR, 0xFF020001),
  196. OID_UNKNOWN(OID_INL_MEMORY, 0xFF020002),
  197. OID_U32_C(OID_INL_MODE, 0xFF020003),
  198. OID_UNKNOWN(OID_INL_COMPONENT_NR, 0xFF020004),
  199. OID_STRUCT(OID_INL_VERSION, 0xFF020005, u8[8], OID_TYPE_RAW),
  200. OID_UNKNOWN(OID_INL_INTERFACE_ID, 0xFF020006),
  201. OID_UNKNOWN(OID_INL_COMPONENT_ID, 0xFF020007),
  202. OID_U32_C(OID_INL_CONFIG, 0xFF020008),
  203. OID_U32_C(OID_INL_DOT11D_CONFORMANCE, 0xFF02000C),
  204. OID_U32(OID_INL_PHYCAPABILITIES, 0xFF02000D),
  205. OID_U32_C(OID_INL_OUTPUTPOWER, 0xFF02000F),
  206. };
  207. int
  208. mgt_init(islpci_private *priv)
  209. {
  210. int i;
  211. priv->mib = kcalloc(OID_NUM_LAST, sizeof (void *), GFP_KERNEL);
  212. if (!priv->mib)
  213. return -ENOMEM;
  214. /* Alloc the cache */
  215. for (i = 0; i < OID_NUM_LAST; i++) {
  216. if (isl_oid[i].flags & OID_FLAG_CACHED) {
  217. priv->mib[i] = kzalloc(isl_oid[i].size *
  218. (isl_oid[i].range + 1),
  219. GFP_KERNEL);
  220. if (!priv->mib[i])
  221. return -ENOMEM;
  222. } else
  223. priv->mib[i] = NULL;
  224. }
  225. init_rwsem(&priv->mib_sem);
  226. prism54_mib_init(priv);
  227. return 0;
  228. }
  229. void
  230. mgt_clean(islpci_private *priv)
  231. {
  232. int i;
  233. if (!priv->mib)
  234. return;
  235. for (i = 0; i < OID_NUM_LAST; i++) {
  236. kfree(priv->mib[i]);
  237. priv->mib[i] = NULL;
  238. }
  239. kfree(priv->mib);
  240. priv->mib = NULL;
  241. }
  242. void
  243. mgt_le_to_cpu(int type, void *data)
  244. {
  245. switch (type) {
  246. case OID_TYPE_U32:
  247. *(u32 *) data = le32_to_cpu(*(u32 *) data);
  248. break;
  249. case OID_TYPE_BUFFER:{
  250. struct obj_buffer *buff = data;
  251. buff->size = le32_to_cpu(buff->size);
  252. buff->addr = le32_to_cpu(buff->addr);
  253. break;
  254. }
  255. case OID_TYPE_BSS:{
  256. struct obj_bss *bss = data;
  257. bss->age = le16_to_cpu(bss->age);
  258. bss->channel = le16_to_cpu(bss->channel);
  259. bss->capinfo = le16_to_cpu(bss->capinfo);
  260. bss->rates = le16_to_cpu(bss->rates);
  261. bss->basic_rates = le16_to_cpu(bss->basic_rates);
  262. break;
  263. }
  264. case OID_TYPE_BSSLIST:{
  265. struct obj_bsslist *list = data;
  266. int i;
  267. list->nr = le32_to_cpu(list->nr);
  268. for (i = 0; i < list->nr; i++)
  269. mgt_le_to_cpu(OID_TYPE_BSS, &list->bsslist[i]);
  270. break;
  271. }
  272. case OID_TYPE_FREQUENCIES:{
  273. struct obj_frequencies *freq = data;
  274. int i;
  275. freq->nr = le16_to_cpu(freq->nr);
  276. for (i = 0; i < freq->nr; i++)
  277. freq->mhz[i] = le16_to_cpu(freq->mhz[i]);
  278. break;
  279. }
  280. case OID_TYPE_MLME:{
  281. struct obj_mlme *mlme = data;
  282. mlme->id = le16_to_cpu(mlme->id);
  283. mlme->state = le16_to_cpu(mlme->state);
  284. mlme->code = le16_to_cpu(mlme->code);
  285. break;
  286. }
  287. case OID_TYPE_MLMEEX:{
  288. struct obj_mlmeex *mlme = data;
  289. mlme->id = le16_to_cpu(mlme->id);
  290. mlme->state = le16_to_cpu(mlme->state);
  291. mlme->code = le16_to_cpu(mlme->code);
  292. mlme->size = le16_to_cpu(mlme->size);
  293. break;
  294. }
  295. case OID_TYPE_ATTACH:{
  296. struct obj_attachment *attach = data;
  297. attach->id = le16_to_cpu(attach->id);
  298. attach->size = le16_to_cpu(attach->size);
  299. break;
  300. }
  301. case OID_TYPE_SSID:
  302. case OID_TYPE_KEY:
  303. case OID_TYPE_ADDR:
  304. case OID_TYPE_RAW:
  305. break;
  306. default:
  307. BUG();
  308. }
  309. }
  310. static void
  311. mgt_cpu_to_le(int type, void *data)
  312. {
  313. switch (type) {
  314. case OID_TYPE_U32:
  315. *(u32 *) data = cpu_to_le32(*(u32 *) data);
  316. break;
  317. case OID_TYPE_BUFFER:{
  318. struct obj_buffer *buff = data;
  319. buff->size = cpu_to_le32(buff->size);
  320. buff->addr = cpu_to_le32(buff->addr);
  321. break;
  322. }
  323. case OID_TYPE_BSS:{
  324. struct obj_bss *bss = data;
  325. bss->age = cpu_to_le16(bss->age);
  326. bss->channel = cpu_to_le16(bss->channel);
  327. bss->capinfo = cpu_to_le16(bss->capinfo);
  328. bss->rates = cpu_to_le16(bss->rates);
  329. bss->basic_rates = cpu_to_le16(bss->basic_rates);
  330. break;
  331. }
  332. case OID_TYPE_BSSLIST:{
  333. struct obj_bsslist *list = data;
  334. int i;
  335. list->nr = cpu_to_le32(list->nr);
  336. for (i = 0; i < list->nr; i++)
  337. mgt_cpu_to_le(OID_TYPE_BSS, &list->bsslist[i]);
  338. break;
  339. }
  340. case OID_TYPE_FREQUENCIES:{
  341. struct obj_frequencies *freq = data;
  342. int i;
  343. freq->nr = cpu_to_le16(freq->nr);
  344. for (i = 0; i < freq->nr; i++)
  345. freq->mhz[i] = cpu_to_le16(freq->mhz[i]);
  346. break;
  347. }
  348. case OID_TYPE_MLME:{
  349. struct obj_mlme *mlme = data;
  350. mlme->id = cpu_to_le16(mlme->id);
  351. mlme->state = cpu_to_le16(mlme->state);
  352. mlme->code = cpu_to_le16(mlme->code);
  353. break;
  354. }
  355. case OID_TYPE_MLMEEX:{
  356. struct obj_mlmeex *mlme = data;
  357. mlme->id = cpu_to_le16(mlme->id);
  358. mlme->state = cpu_to_le16(mlme->state);
  359. mlme->code = cpu_to_le16(mlme->code);
  360. mlme->size = cpu_to_le16(mlme->size);
  361. break;
  362. }
  363. case OID_TYPE_ATTACH:{
  364. struct obj_attachment *attach = data;
  365. attach->id = cpu_to_le16(attach->id);
  366. attach->size = cpu_to_le16(attach->size);
  367. break;
  368. }
  369. case OID_TYPE_SSID:
  370. case OID_TYPE_KEY:
  371. case OID_TYPE_ADDR:
  372. case OID_TYPE_RAW:
  373. break;
  374. default:
  375. BUG();
  376. }
  377. }
  378. /* Note : data is modified during this function */
  379. int
  380. mgt_set_request(islpci_private *priv, enum oid_num_t n, int extra, void *data)
  381. {
  382. int ret = 0;
  383. struct islpci_mgmtframe *response = NULL;
  384. int response_op = PIMFOR_OP_ERROR;
  385. int dlen;
  386. void *cache, *_data = data;
  387. u32 oid;
  388. BUG_ON(OID_NUM_LAST <= n);
  389. BUG_ON(extra > isl_oid[n].range);
  390. if (!priv->mib)
  391. /* memory has been freed */
  392. return -1;
  393. dlen = isl_oid[n].size;
  394. cache = priv->mib[n];
  395. cache += (cache ? extra * dlen : 0);
  396. oid = isl_oid[n].oid + extra;
  397. if (_data == NULL)
  398. /* we are requested to re-set a cached value */
  399. _data = cache;
  400. else
  401. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, _data);
  402. /* If we are going to write to the cache, we don't want anyone to read
  403. * it -> acquire write lock.
  404. * Else we could acquire a read lock to be sure we don't bother the
  405. * commit process (which takes a write lock). But I'm not sure if it's
  406. * needed.
  407. */
  408. if (cache)
  409. down_write(&priv->mib_sem);
  410. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  411. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, oid,
  412. _data, dlen, &response);
  413. if (!ret) {
  414. response_op = response->header->operation;
  415. islpci_mgt_release(response);
  416. }
  417. if (ret || response_op == PIMFOR_OP_ERROR)
  418. ret = -EIO;
  419. } else if (!cache)
  420. ret = -EIO;
  421. if (cache) {
  422. if (!ret && data)
  423. memcpy(cache, _data, dlen);
  424. up_write(&priv->mib_sem);
  425. }
  426. /* re-set given data to what it was */
  427. if (data)
  428. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, data);
  429. return ret;
  430. }
  431. /* None of these are cached */
  432. int
  433. mgt_set_varlen(islpci_private *priv, enum oid_num_t n, void *data, int extra_len)
  434. {
  435. int ret = 0;
  436. struct islpci_mgmtframe *response;
  437. int response_op = PIMFOR_OP_ERROR;
  438. int dlen;
  439. u32 oid;
  440. BUG_ON(OID_NUM_LAST <= n);
  441. dlen = isl_oid[n].size;
  442. oid = isl_oid[n].oid;
  443. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, data);
  444. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  445. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, oid,
  446. data, dlen + extra_len, &response);
  447. if (!ret) {
  448. response_op = response->header->operation;
  449. islpci_mgt_release(response);
  450. }
  451. if (ret || response_op == PIMFOR_OP_ERROR)
  452. ret = -EIO;
  453. } else
  454. ret = -EIO;
  455. /* re-set given data to what it was */
  456. if (data)
  457. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, data);
  458. return ret;
  459. }
  460. int
  461. mgt_get_request(islpci_private *priv, enum oid_num_t n, int extra, void *data,
  462. union oid_res_t *res)
  463. {
  464. int ret = -EIO;
  465. int reslen = 0;
  466. struct islpci_mgmtframe *response = NULL;
  467. int dlen;
  468. void *cache, *_res = NULL;
  469. u32 oid;
  470. BUG_ON(OID_NUM_LAST <= n);
  471. BUG_ON(extra > isl_oid[n].range);
  472. res->ptr = NULL;
  473. if (!priv->mib)
  474. /* memory has been freed */
  475. return -1;
  476. dlen = isl_oid[n].size;
  477. cache = priv->mib[n];
  478. cache += cache ? extra * dlen : 0;
  479. oid = isl_oid[n].oid + extra;
  480. reslen = dlen;
  481. if (cache)
  482. down_read(&priv->mib_sem);
  483. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  484. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
  485. oid, data, dlen, &response);
  486. if (ret || !response ||
  487. response->header->operation == PIMFOR_OP_ERROR) {
  488. if (response)
  489. islpci_mgt_release(response);
  490. ret = -EIO;
  491. }
  492. if (!ret) {
  493. _res = response->data;
  494. reslen = response->header->length;
  495. }
  496. } else if (cache) {
  497. _res = cache;
  498. ret = 0;
  499. }
  500. if ((isl_oid[n].flags & OID_FLAG_TYPE) == OID_TYPE_U32)
  501. res->u = ret ? 0 : le32_to_cpu(*(u32 *) _res);
  502. else {
  503. res->ptr = kmalloc(reslen, GFP_KERNEL);
  504. BUG_ON(res->ptr == NULL);
  505. if (ret)
  506. memset(res->ptr, 0, reslen);
  507. else {
  508. memcpy(res->ptr, _res, reslen);
  509. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE,
  510. res->ptr);
  511. }
  512. }
  513. if (cache)
  514. up_read(&priv->mib_sem);
  515. if (response && !ret)
  516. islpci_mgt_release(response);
  517. if (reslen > isl_oid[n].size)
  518. printk(KERN_DEBUG
  519. "mgt_get_request(0x%x): received data length was bigger "
  520. "than expected (%d > %d). Memory is probably corrupted...",
  521. oid, reslen, isl_oid[n].size);
  522. return ret;
  523. }
  524. /* lock outside */
  525. int
  526. mgt_commit_list(islpci_private *priv, enum oid_num_t *l, int n)
  527. {
  528. int i, ret = 0;
  529. struct islpci_mgmtframe *response;
  530. for (i = 0; i < n; i++) {
  531. struct oid_t *t = &(isl_oid[l[i]]);
  532. void *data = priv->mib[l[i]];
  533. int j = 0;
  534. u32 oid = t->oid;
  535. BUG_ON(data == NULL);
  536. while (j <= t->range) {
  537. int r = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
  538. oid, data, t->size,
  539. &response);
  540. if (response) {
  541. r |= (response->header->operation == PIMFOR_OP_ERROR);
  542. islpci_mgt_release(response);
  543. }
  544. if (r)
  545. printk(KERN_ERR "%s: mgt_commit_list: failure. "
  546. "oid=%08x err=%d\n",
  547. priv->ndev->name, oid, r);
  548. ret |= r;
  549. j++;
  550. oid++;
  551. data += t->size;
  552. }
  553. }
  554. return ret;
  555. }
  556. /* Lock outside */
  557. void
  558. mgt_set(islpci_private *priv, enum oid_num_t n, void *data)
  559. {
  560. BUG_ON(OID_NUM_LAST <= n);
  561. BUG_ON(priv->mib[n] == NULL);
  562. memcpy(priv->mib[n], data, isl_oid[n].size);
  563. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, priv->mib[n]);
  564. }
  565. void
  566. mgt_get(islpci_private *priv, enum oid_num_t n, void *res)
  567. {
  568. BUG_ON(OID_NUM_LAST <= n);
  569. BUG_ON(priv->mib[n] == NULL);
  570. BUG_ON(res == NULL);
  571. memcpy(res, priv->mib[n], isl_oid[n].size);
  572. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, res);
  573. }
  574. /* Commits the cache. Lock outside. */
  575. static enum oid_num_t commit_part1[] = {
  576. OID_INL_CONFIG,
  577. OID_INL_MODE,
  578. DOT11_OID_BSSTYPE,
  579. DOT11_OID_CHANNEL,
  580. DOT11_OID_MLMEAUTOLEVEL
  581. };
  582. static enum oid_num_t commit_part2[] = {
  583. DOT11_OID_SSID,
  584. DOT11_OID_PSMBUFFER,
  585. DOT11_OID_AUTHENABLE,
  586. DOT11_OID_PRIVACYINVOKED,
  587. DOT11_OID_EXUNENCRYPTED,
  588. DOT11_OID_DEFKEYX, /* MULTIPLE */
  589. DOT11_OID_DEFKEYID,
  590. DOT11_OID_DOT1XENABLE,
  591. OID_INL_DOT11D_CONFORMANCE,
  592. /* Do not initialize this - fw < 1.0.4.3 rejects it
  593. OID_INL_OUTPUTPOWER,
  594. */
  595. };
  596. /* update the MAC addr. */
  597. static int
  598. mgt_update_addr(islpci_private *priv)
  599. {
  600. struct islpci_mgmtframe *res;
  601. int ret;
  602. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
  603. isl_oid[GEN_OID_MACADDRESS].oid, NULL,
  604. isl_oid[GEN_OID_MACADDRESS].size, &res);
  605. if ((ret == 0) && res && (res->header->operation != PIMFOR_OP_ERROR))
  606. memcpy(priv->ndev->dev_addr, res->data, ETH_ALEN);
  607. else
  608. ret = -EIO;
  609. if (res)
  610. islpci_mgt_release(res);
  611. if (ret)
  612. printk(KERN_ERR "%s: mgt_update_addr: failure\n", priv->ndev->name);
  613. return ret;
  614. }
  615. int
  616. mgt_commit(islpci_private *priv)
  617. {
  618. int rvalue;
  619. enum oid_num_t u;
  620. if (islpci_get_state(priv) < PRV_STATE_INIT)
  621. return 0;
  622. rvalue = mgt_commit_list(priv, commit_part1, ARRAY_SIZE(commit_part1));
  623. if (priv->iw_mode != IW_MODE_MONITOR)
  624. rvalue |= mgt_commit_list(priv, commit_part2, ARRAY_SIZE(commit_part2));
  625. u = OID_INL_MODE;
  626. rvalue |= mgt_commit_list(priv, &u, 1);
  627. rvalue |= mgt_update_addr(priv);
  628. if (rvalue) {
  629. /* some request have failed. The device might be in an
  630. incoherent state. We should reset it ! */
  631. printk(KERN_DEBUG "%s: mgt_commit: failure\n", priv->ndev->name);
  632. }
  633. return rvalue;
  634. }
  635. /* The following OIDs need to be "unlatched":
  636. *
  637. * MEDIUMLIMIT,BEACONPERIOD,DTIMPERIOD,ATIMWINDOW,LISTENINTERVAL
  638. * FREQUENCY,EXTENDEDRATES.
  639. *
  640. * The way to do this is to set ESSID. Note though that they may get
  641. * unlatch before though by setting another OID. */
  642. #if 0
  643. void
  644. mgt_unlatch_all(islpci_private *priv)
  645. {
  646. u32 u;
  647. int rvalue = 0;
  648. if (islpci_get_state(priv) < PRV_STATE_INIT)
  649. return;
  650. u = DOT11_OID_SSID;
  651. rvalue = mgt_commit_list(priv, &u, 1);
  652. /* Necessary if in MANUAL RUN mode? */
  653. #if 0
  654. u = OID_INL_MODE;
  655. rvalue |= mgt_commit_list(priv, &u, 1);
  656. u = DOT11_OID_MLMEAUTOLEVEL;
  657. rvalue |= mgt_commit_list(priv, &u, 1);
  658. u = OID_INL_MODE;
  659. rvalue |= mgt_commit_list(priv, &u, 1);
  660. #endif
  661. if (rvalue)
  662. printk(KERN_DEBUG "%s: Unlatching OIDs failed\n", priv->ndev->name);
  663. }
  664. #endif
  665. /* This will tell you if you are allowed to answer a mlme(ex) request .*/
  666. int
  667. mgt_mlme_answer(islpci_private *priv)
  668. {
  669. u32 mlmeautolevel;
  670. /* Acquire a read lock because if we are in a mode change, it's
  671. * possible to answer true, while the card is leaving master to managed
  672. * mode. Answering to a mlme in this situation could hang the card.
  673. */
  674. down_read(&priv->mib_sem);
  675. mlmeautolevel =
  676. le32_to_cpu(*(u32 *) priv->mib[DOT11_OID_MLMEAUTOLEVEL]);
  677. up_read(&priv->mib_sem);
  678. return ((priv->iw_mode == IW_MODE_MASTER) &&
  679. (mlmeautolevel >= DOT11_MLME_INTERMEDIATE));
  680. }
  681. enum oid_num_t
  682. mgt_oidtonum(u32 oid)
  683. {
  684. int i;
  685. for (i = 0; i < OID_NUM_LAST; i++)
  686. if (isl_oid[i].oid == oid)
  687. return i;
  688. printk(KERN_DEBUG "looking for an unknown oid 0x%x", oid);
  689. return OID_NUM_LAST;
  690. }
  691. int
  692. mgt_response_to_str(enum oid_num_t n, union oid_res_t *r, char *str)
  693. {
  694. switch (isl_oid[n].flags & OID_FLAG_TYPE) {
  695. case OID_TYPE_U32:
  696. return snprintf(str, PRIV_STR_SIZE, "%u\n", r->u);
  697. case OID_TYPE_BUFFER:{
  698. struct obj_buffer *buff = r->ptr;
  699. return snprintf(str, PRIV_STR_SIZE,
  700. "size=%u\naddr=0x%X\n", buff->size,
  701. buff->addr);
  702. }
  703. break;
  704. case OID_TYPE_BSS:{
  705. struct obj_bss *bss = r->ptr;
  706. return snprintf(str, PRIV_STR_SIZE,
  707. "age=%u\nchannel=%u\n"
  708. "capinfo=0x%X\nrates=0x%X\n"
  709. "basic_rates=0x%X\n", bss->age,
  710. bss->channel, bss->capinfo,
  711. bss->rates, bss->basic_rates);
  712. }
  713. break;
  714. case OID_TYPE_BSSLIST:{
  715. struct obj_bsslist *list = r->ptr;
  716. int i, k;
  717. k = snprintf(str, PRIV_STR_SIZE, "nr=%u\n", list->nr);
  718. for (i = 0; i < list->nr; i++)
  719. k += snprintf(str + k, PRIV_STR_SIZE - k,
  720. "bss[%u] :\nage=%u\nchannel=%u\n"
  721. "capinfo=0x%X\nrates=0x%X\n"
  722. "basic_rates=0x%X\n",
  723. i, list->bsslist[i].age,
  724. list->bsslist[i].channel,
  725. list->bsslist[i].capinfo,
  726. list->bsslist[i].rates,
  727. list->bsslist[i].basic_rates);
  728. return k;
  729. }
  730. break;
  731. case OID_TYPE_FREQUENCIES:{
  732. struct obj_frequencies *freq = r->ptr;
  733. int i, t;
  734. printk("nr : %u\n", freq->nr);
  735. t = snprintf(str, PRIV_STR_SIZE, "nr=%u\n", freq->nr);
  736. for (i = 0; i < freq->nr; i++)
  737. t += snprintf(str + t, PRIV_STR_SIZE - t,
  738. "mhz[%u]=%u\n", i, freq->mhz[i]);
  739. return t;
  740. }
  741. break;
  742. case OID_TYPE_MLME:{
  743. struct obj_mlme *mlme = r->ptr;
  744. return snprintf(str, PRIV_STR_SIZE,
  745. "id=0x%X\nstate=0x%X\ncode=0x%X\n",
  746. mlme->id, mlme->state, mlme->code);
  747. }
  748. break;
  749. case OID_TYPE_MLMEEX:{
  750. struct obj_mlmeex *mlme = r->ptr;
  751. return snprintf(str, PRIV_STR_SIZE,
  752. "id=0x%X\nstate=0x%X\n"
  753. "code=0x%X\nsize=0x%X\n", mlme->id,
  754. mlme->state, mlme->code, mlme->size);
  755. }
  756. break;
  757. case OID_TYPE_ATTACH:{
  758. struct obj_attachment *attach = r->ptr;
  759. return snprintf(str, PRIV_STR_SIZE,
  760. "id=%d\nsize=%d\n",
  761. attach->id,
  762. attach->size);
  763. }
  764. break;
  765. case OID_TYPE_SSID:{
  766. struct obj_ssid *ssid = r->ptr;
  767. return snprintf(str, PRIV_STR_SIZE,
  768. "length=%u\noctets=%.*s\n",
  769. ssid->length, ssid->length,
  770. ssid->octets);
  771. }
  772. break;
  773. case OID_TYPE_KEY:{
  774. struct obj_key *key = r->ptr;
  775. int t, i;
  776. t = snprintf(str, PRIV_STR_SIZE,
  777. "type=0x%X\nlength=0x%X\nkey=0x",
  778. key->type, key->length);
  779. for (i = 0; i < key->length; i++)
  780. t += snprintf(str + t, PRIV_STR_SIZE - t,
  781. "%02X:", key->key[i]);
  782. t += snprintf(str + t, PRIV_STR_SIZE - t, "\n");
  783. return t;
  784. }
  785. break;
  786. case OID_TYPE_RAW:
  787. case OID_TYPE_ADDR:{
  788. unsigned char *buff = r->ptr;
  789. int t, i;
  790. t = snprintf(str, PRIV_STR_SIZE, "hex data=");
  791. for (i = 0; i < isl_oid[n].size; i++)
  792. t += snprintf(str + t, PRIV_STR_SIZE - t,
  793. "%02X:", buff[i]);
  794. t += snprintf(str + t, PRIV_STR_SIZE - t, "\n");
  795. return t;
  796. }
  797. break;
  798. default:
  799. BUG();
  800. }
  801. return 0;
  802. }