oid_mgt.c 25 KB

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