oid_mgt.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. kfree(priv->mib[i]);
  239. priv->mib[i] = NULL;
  240. }
  241. kfree(priv->mib);
  242. priv->mib = NULL;
  243. }
  244. void
  245. mgt_le_to_cpu(int type, void *data)
  246. {
  247. switch (type) {
  248. case OID_TYPE_U32:
  249. *(u32 *) data = le32_to_cpu(*(u32 *) data);
  250. break;
  251. case OID_TYPE_BUFFER:{
  252. struct obj_buffer *buff = data;
  253. buff->size = le32_to_cpu(buff->size);
  254. buff->addr = le32_to_cpu(buff->addr);
  255. break;
  256. }
  257. case OID_TYPE_BSS:{
  258. struct obj_bss *bss = data;
  259. bss->age = le16_to_cpu(bss->age);
  260. bss->channel = le16_to_cpu(bss->channel);
  261. bss->capinfo = le16_to_cpu(bss->capinfo);
  262. bss->rates = le16_to_cpu(bss->rates);
  263. bss->basic_rates = le16_to_cpu(bss->basic_rates);
  264. break;
  265. }
  266. case OID_TYPE_BSSLIST:{
  267. struct obj_bsslist *list = data;
  268. int i;
  269. list->nr = le32_to_cpu(list->nr);
  270. for (i = 0; i < list->nr; i++)
  271. mgt_le_to_cpu(OID_TYPE_BSS, &list->bsslist[i]);
  272. break;
  273. }
  274. case OID_TYPE_FREQUENCIES:{
  275. struct obj_frequencies *freq = data;
  276. int i;
  277. freq->nr = le16_to_cpu(freq->nr);
  278. for (i = 0; i < freq->nr; i++)
  279. freq->mhz[i] = le16_to_cpu(freq->mhz[i]);
  280. break;
  281. }
  282. case OID_TYPE_MLME:{
  283. struct obj_mlme *mlme = data;
  284. mlme->id = le16_to_cpu(mlme->id);
  285. mlme->state = le16_to_cpu(mlme->state);
  286. mlme->code = le16_to_cpu(mlme->code);
  287. break;
  288. }
  289. case OID_TYPE_MLMEEX:{
  290. struct obj_mlmeex *mlme = data;
  291. mlme->id = le16_to_cpu(mlme->id);
  292. mlme->state = le16_to_cpu(mlme->state);
  293. mlme->code = le16_to_cpu(mlme->code);
  294. mlme->size = le16_to_cpu(mlme->size);
  295. break;
  296. }
  297. case OID_TYPE_ATTACH:{
  298. struct obj_attachment *attach = data;
  299. attach->id = le16_to_cpu(attach->id);
  300. attach->size = le16_to_cpu(attach->size);
  301. break;
  302. }
  303. case OID_TYPE_SSID:
  304. case OID_TYPE_KEY:
  305. case OID_TYPE_ADDR:
  306. case OID_TYPE_RAW:
  307. break;
  308. default:
  309. BUG();
  310. }
  311. }
  312. static void
  313. mgt_cpu_to_le(int type, void *data)
  314. {
  315. switch (type) {
  316. case OID_TYPE_U32:
  317. *(u32 *) data = cpu_to_le32(*(u32 *) data);
  318. break;
  319. case OID_TYPE_BUFFER:{
  320. struct obj_buffer *buff = data;
  321. buff->size = cpu_to_le32(buff->size);
  322. buff->addr = cpu_to_le32(buff->addr);
  323. break;
  324. }
  325. case OID_TYPE_BSS:{
  326. struct obj_bss *bss = data;
  327. bss->age = cpu_to_le16(bss->age);
  328. bss->channel = cpu_to_le16(bss->channel);
  329. bss->capinfo = cpu_to_le16(bss->capinfo);
  330. bss->rates = cpu_to_le16(bss->rates);
  331. bss->basic_rates = cpu_to_le16(bss->basic_rates);
  332. break;
  333. }
  334. case OID_TYPE_BSSLIST:{
  335. struct obj_bsslist *list = data;
  336. int i;
  337. list->nr = cpu_to_le32(list->nr);
  338. for (i = 0; i < list->nr; i++)
  339. mgt_cpu_to_le(OID_TYPE_BSS, &list->bsslist[i]);
  340. break;
  341. }
  342. case OID_TYPE_FREQUENCIES:{
  343. struct obj_frequencies *freq = data;
  344. int i;
  345. freq->nr = cpu_to_le16(freq->nr);
  346. for (i = 0; i < freq->nr; i++)
  347. freq->mhz[i] = cpu_to_le16(freq->mhz[i]);
  348. break;
  349. }
  350. case OID_TYPE_MLME:{
  351. struct obj_mlme *mlme = data;
  352. mlme->id = cpu_to_le16(mlme->id);
  353. mlme->state = cpu_to_le16(mlme->state);
  354. mlme->code = cpu_to_le16(mlme->code);
  355. break;
  356. }
  357. case OID_TYPE_MLMEEX:{
  358. struct obj_mlmeex *mlme = data;
  359. mlme->id = cpu_to_le16(mlme->id);
  360. mlme->state = cpu_to_le16(mlme->state);
  361. mlme->code = cpu_to_le16(mlme->code);
  362. mlme->size = cpu_to_le16(mlme->size);
  363. break;
  364. }
  365. case OID_TYPE_ATTACH:{
  366. struct obj_attachment *attach = data;
  367. attach->id = cpu_to_le16(attach->id);
  368. attach->size = cpu_to_le16(attach->size);
  369. break;
  370. }
  371. case OID_TYPE_SSID:
  372. case OID_TYPE_KEY:
  373. case OID_TYPE_ADDR:
  374. case OID_TYPE_RAW:
  375. break;
  376. default:
  377. BUG();
  378. }
  379. }
  380. /* Note : data is modified during this function */
  381. int
  382. mgt_set_request(islpci_private *priv, enum oid_num_t n, int extra, void *data)
  383. {
  384. int ret = 0;
  385. struct islpci_mgmtframe *response = NULL;
  386. int response_op = PIMFOR_OP_ERROR;
  387. int dlen;
  388. void *cache, *_data = data;
  389. u32 oid;
  390. BUG_ON(OID_NUM_LAST <= n);
  391. BUG_ON(extra > isl_oid[n].range);
  392. if (!priv->mib)
  393. /* memory has been freed */
  394. return -1;
  395. dlen = isl_oid[n].size;
  396. cache = priv->mib[n];
  397. cache += (cache ? extra * dlen : 0);
  398. oid = isl_oid[n].oid + extra;
  399. if (_data == NULL)
  400. /* we are requested to re-set a cached value */
  401. _data = cache;
  402. else
  403. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, _data);
  404. /* If we are going to write to the cache, we don't want anyone to read
  405. * it -> acquire write lock.
  406. * Else we could acquire a read lock to be sure we don't bother the
  407. * commit process (which takes a write lock). But I'm not sure if it's
  408. * needed.
  409. */
  410. if (cache)
  411. down_write(&priv->mib_sem);
  412. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  413. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, oid,
  414. _data, dlen, &response);
  415. if (!ret) {
  416. response_op = response->header->operation;
  417. islpci_mgt_release(response);
  418. }
  419. if (ret || response_op == PIMFOR_OP_ERROR)
  420. ret = -EIO;
  421. } else if (!cache)
  422. ret = -EIO;
  423. if (cache) {
  424. if (!ret && data)
  425. memcpy(cache, _data, dlen);
  426. up_write(&priv->mib_sem);
  427. }
  428. /* re-set given data to what it was */
  429. if (data)
  430. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, data);
  431. return ret;
  432. }
  433. /* None of these are cached */
  434. int
  435. mgt_set_varlen(islpci_private *priv, enum oid_num_t n, void *data, int extra_len)
  436. {
  437. int ret = 0;
  438. struct islpci_mgmtframe *response;
  439. int response_op = PIMFOR_OP_ERROR;
  440. int dlen;
  441. u32 oid;
  442. BUG_ON(OID_NUM_LAST <= n);
  443. dlen = isl_oid[n].size;
  444. oid = isl_oid[n].oid;
  445. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, data);
  446. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  447. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, oid,
  448. data, dlen + extra_len, &response);
  449. if (!ret) {
  450. response_op = response->header->operation;
  451. islpci_mgt_release(response);
  452. }
  453. if (ret || response_op == PIMFOR_OP_ERROR)
  454. ret = -EIO;
  455. } else
  456. ret = -EIO;
  457. /* re-set given data to what it was */
  458. if (data)
  459. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, data);
  460. return ret;
  461. }
  462. int
  463. mgt_get_request(islpci_private *priv, enum oid_num_t n, int extra, void *data,
  464. union oid_res_t *res)
  465. {
  466. int ret = -EIO;
  467. int reslen = 0;
  468. struct islpci_mgmtframe *response = NULL;
  469. int dlen;
  470. void *cache, *_res = NULL;
  471. u32 oid;
  472. BUG_ON(OID_NUM_LAST <= n);
  473. BUG_ON(extra > isl_oid[n].range);
  474. res->ptr = NULL;
  475. if (!priv->mib)
  476. /* memory has been freed */
  477. return -1;
  478. dlen = isl_oid[n].size;
  479. cache = priv->mib[n];
  480. cache += cache ? extra * dlen : 0;
  481. oid = isl_oid[n].oid + extra;
  482. reslen = dlen;
  483. if (cache)
  484. down_read(&priv->mib_sem);
  485. if (islpci_get_state(priv) >= PRV_STATE_READY) {
  486. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
  487. oid, data, dlen, &response);
  488. if (ret || !response ||
  489. response->header->operation == PIMFOR_OP_ERROR) {
  490. if (response)
  491. islpci_mgt_release(response);
  492. ret = -EIO;
  493. }
  494. if (!ret) {
  495. _res = response->data;
  496. reslen = response->header->length;
  497. }
  498. } else if (cache) {
  499. _res = cache;
  500. ret = 0;
  501. }
  502. if ((isl_oid[n].flags & OID_FLAG_TYPE) == OID_TYPE_U32)
  503. res->u = ret ? 0 : le32_to_cpu(*(u32 *) _res);
  504. else {
  505. res->ptr = kmalloc(reslen, GFP_KERNEL);
  506. BUG_ON(res->ptr == NULL);
  507. if (ret)
  508. memset(res->ptr, 0, reslen);
  509. else {
  510. memcpy(res->ptr, _res, reslen);
  511. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE,
  512. res->ptr);
  513. }
  514. }
  515. if (cache)
  516. up_read(&priv->mib_sem);
  517. if (response && !ret)
  518. islpci_mgt_release(response);
  519. if (reslen > isl_oid[n].size)
  520. printk(KERN_DEBUG
  521. "mgt_get_request(0x%x): received data length was bigger "
  522. "than expected (%d > %d). Memory is probably corrupted...",
  523. oid, reslen, isl_oid[n].size);
  524. return ret;
  525. }
  526. /* lock outside */
  527. int
  528. mgt_commit_list(islpci_private *priv, enum oid_num_t *l, int n)
  529. {
  530. int i, ret = 0;
  531. struct islpci_mgmtframe *response;
  532. for (i = 0; i < n; i++) {
  533. struct oid_t *t = &(isl_oid[l[i]]);
  534. void *data = priv->mib[l[i]];
  535. int j = 0;
  536. u32 oid = t->oid;
  537. BUG_ON(data == NULL);
  538. while (j <= t->range) {
  539. int r = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET,
  540. oid, data, t->size,
  541. &response);
  542. if (response) {
  543. r |= (response->header->operation == PIMFOR_OP_ERROR);
  544. islpci_mgt_release(response);
  545. }
  546. if (r)
  547. printk(KERN_ERR "%s: mgt_commit_list: failure. "
  548. "oid=%08x err=%d\n",
  549. priv->ndev->name, oid, r);
  550. ret |= r;
  551. j++;
  552. oid++;
  553. data += t->size;
  554. }
  555. }
  556. return ret;
  557. }
  558. /* Lock outside */
  559. void
  560. mgt_set(islpci_private *priv, enum oid_num_t n, void *data)
  561. {
  562. BUG_ON(OID_NUM_LAST <= n);
  563. BUG_ON(priv->mib[n] == NULL);
  564. memcpy(priv->mib[n], data, isl_oid[n].size);
  565. mgt_cpu_to_le(isl_oid[n].flags & OID_FLAG_TYPE, priv->mib[n]);
  566. }
  567. void
  568. mgt_get(islpci_private *priv, enum oid_num_t n, void *res)
  569. {
  570. BUG_ON(OID_NUM_LAST <= n);
  571. BUG_ON(priv->mib[n] == NULL);
  572. BUG_ON(res == NULL);
  573. memcpy(res, priv->mib[n], isl_oid[n].size);
  574. mgt_le_to_cpu(isl_oid[n].flags & OID_FLAG_TYPE, res);
  575. }
  576. /* Commits the cache. Lock outside. */
  577. static enum oid_num_t commit_part1[] = {
  578. OID_INL_CONFIG,
  579. OID_INL_MODE,
  580. DOT11_OID_BSSTYPE,
  581. DOT11_OID_CHANNEL,
  582. DOT11_OID_MLMEAUTOLEVEL
  583. };
  584. static enum oid_num_t commit_part2[] = {
  585. DOT11_OID_SSID,
  586. DOT11_OID_PSMBUFFER,
  587. DOT11_OID_AUTHENABLE,
  588. DOT11_OID_PRIVACYINVOKED,
  589. DOT11_OID_EXUNENCRYPTED,
  590. DOT11_OID_DEFKEYX, /* MULTIPLE */
  591. DOT11_OID_DEFKEYID,
  592. DOT11_OID_DOT1XENABLE,
  593. OID_INL_DOT11D_CONFORMANCE,
  594. /* Do not initialize this - fw < 1.0.4.3 rejects it
  595. OID_INL_OUTPUTPOWER,
  596. */
  597. };
  598. /* update the MAC addr. */
  599. static int
  600. mgt_update_addr(islpci_private *priv)
  601. {
  602. struct islpci_mgmtframe *res;
  603. int ret;
  604. ret = islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET,
  605. isl_oid[GEN_OID_MACADDRESS].oid, NULL,
  606. isl_oid[GEN_OID_MACADDRESS].size, &res);
  607. if ((ret == 0) && res && (res->header->operation != PIMFOR_OP_ERROR))
  608. memcpy(priv->ndev->dev_addr, res->data, 6);
  609. else
  610. ret = -EIO;
  611. if (res)
  612. islpci_mgt_release(res);
  613. if (ret)
  614. printk(KERN_ERR "%s: mgt_update_addr: failure\n", priv->ndev->name);
  615. return ret;
  616. }
  617. #define VEC_SIZE(a) (sizeof(a)/sizeof(a[0]))
  618. int
  619. mgt_commit(islpci_private *priv)
  620. {
  621. int rvalue;
  622. u32 u;
  623. if (islpci_get_state(priv) < PRV_STATE_INIT)
  624. return 0;
  625. rvalue = mgt_commit_list(priv, commit_part1, VEC_SIZE(commit_part1));
  626. if (priv->iw_mode != IW_MODE_MONITOR)
  627. rvalue |= mgt_commit_list(priv, commit_part2, VEC_SIZE(commit_part2));
  628. u = OID_INL_MODE;
  629. rvalue |= mgt_commit_list(priv, &u, 1);
  630. rvalue |= mgt_update_addr(priv);
  631. if (rvalue) {
  632. /* some request have failed. The device might be in an
  633. incoherent state. We should reset it ! */
  634. printk(KERN_DEBUG "%s: mgt_commit: failure\n", priv->ndev->name);
  635. }
  636. return rvalue;
  637. }
  638. /* The following OIDs need to be "unlatched":
  639. *
  640. * MEDIUMLIMIT,BEACONPERIOD,DTIMPERIOD,ATIMWINDOW,LISTENINTERVAL
  641. * FREQUENCY,EXTENDEDRATES.
  642. *
  643. * The way to do this is to set ESSID. Note though that they may get
  644. * unlatch before though by setting another OID. */
  645. #if 0
  646. void
  647. mgt_unlatch_all(islpci_private *priv)
  648. {
  649. u32 u;
  650. int rvalue = 0;
  651. if (islpci_get_state(priv) < PRV_STATE_INIT)
  652. return;
  653. u = DOT11_OID_SSID;
  654. rvalue = mgt_commit_list(priv, &u, 1);
  655. /* Necessary if in MANUAL RUN mode? */
  656. #if 0
  657. u = OID_INL_MODE;
  658. rvalue |= mgt_commit_list(priv, &u, 1);
  659. u = DOT11_OID_MLMEAUTOLEVEL;
  660. rvalue |= mgt_commit_list(priv, &u, 1);
  661. u = OID_INL_MODE;
  662. rvalue |= mgt_commit_list(priv, &u, 1);
  663. #endif
  664. if (rvalue)
  665. printk(KERN_DEBUG "%s: Unlatching OIDs failed\n", priv->ndev->name);
  666. }
  667. #endif
  668. /* This will tell you if you are allowed to answer a mlme(ex) request .*/
  669. int
  670. mgt_mlme_answer(islpci_private *priv)
  671. {
  672. u32 mlmeautolevel;
  673. /* Acquire a read lock because if we are in a mode change, it's
  674. * possible to answer true, while the card is leaving master to managed
  675. * mode. Answering to a mlme in this situation could hang the card.
  676. */
  677. down_read(&priv->mib_sem);
  678. mlmeautolevel =
  679. le32_to_cpu(*(u32 *) priv->mib[DOT11_OID_MLMEAUTOLEVEL]);
  680. up_read(&priv->mib_sem);
  681. return ((priv->iw_mode == IW_MODE_MASTER) &&
  682. (mlmeautolevel >= DOT11_MLME_INTERMEDIATE));
  683. }
  684. enum oid_num_t
  685. mgt_oidtonum(u32 oid)
  686. {
  687. int i;
  688. for (i = 0; i < OID_NUM_LAST; i++)
  689. if (isl_oid[i].oid == oid)
  690. return i;
  691. printk(KERN_DEBUG "looking for an unknown oid 0x%x", oid);
  692. return OID_NUM_LAST;
  693. }
  694. int
  695. mgt_response_to_str(enum oid_num_t n, union oid_res_t *r, char *str)
  696. {
  697. switch (isl_oid[n].flags & OID_FLAG_TYPE) {
  698. case OID_TYPE_U32:
  699. return snprintf(str, PRIV_STR_SIZE, "%u\n", r->u);
  700. break;
  701. case OID_TYPE_BUFFER:{
  702. struct obj_buffer *buff = r->ptr;
  703. return snprintf(str, PRIV_STR_SIZE,
  704. "size=%u\naddr=0x%X\n", buff->size,
  705. buff->addr);
  706. }
  707. break;
  708. case OID_TYPE_BSS:{
  709. struct obj_bss *bss = r->ptr;
  710. return snprintf(str, PRIV_STR_SIZE,
  711. "age=%u\nchannel=%u\n"
  712. "capinfo=0x%X\nrates=0x%X\n"
  713. "basic_rates=0x%X\n", bss->age,
  714. bss->channel, bss->capinfo,
  715. bss->rates, bss->basic_rates);
  716. }
  717. break;
  718. case OID_TYPE_BSSLIST:{
  719. struct obj_bsslist *list = r->ptr;
  720. int i, k;
  721. k = snprintf(str, PRIV_STR_SIZE, "nr=%u\n", list->nr);
  722. for (i = 0; i < list->nr; i++)
  723. k += snprintf(str + k, PRIV_STR_SIZE - k,
  724. "bss[%u] : \nage=%u\nchannel=%u\n"
  725. "capinfo=0x%X\nrates=0x%X\n"
  726. "basic_rates=0x%X\n",
  727. i, list->bsslist[i].age,
  728. list->bsslist[i].channel,
  729. list->bsslist[i].capinfo,
  730. list->bsslist[i].rates,
  731. list->bsslist[i].basic_rates);
  732. return k;
  733. }
  734. break;
  735. case OID_TYPE_FREQUENCIES:{
  736. struct obj_frequencies *freq = r->ptr;
  737. int i, t;
  738. printk("nr : %u\n", freq->nr);
  739. t = snprintf(str, PRIV_STR_SIZE, "nr=%u\n", freq->nr);
  740. for (i = 0; i < freq->nr; i++)
  741. t += snprintf(str + t, PRIV_STR_SIZE - t,
  742. "mhz[%u]=%u\n", i, freq->mhz[i]);
  743. return t;
  744. }
  745. break;
  746. case OID_TYPE_MLME:{
  747. struct obj_mlme *mlme = r->ptr;
  748. return snprintf(str, PRIV_STR_SIZE,
  749. "id=0x%X\nstate=0x%X\ncode=0x%X\n",
  750. mlme->id, mlme->state, mlme->code);
  751. }
  752. break;
  753. case OID_TYPE_MLMEEX:{
  754. struct obj_mlmeex *mlme = r->ptr;
  755. return snprintf(str, PRIV_STR_SIZE,
  756. "id=0x%X\nstate=0x%X\n"
  757. "code=0x%X\nsize=0x%X\n", mlme->id,
  758. mlme->state, mlme->code, mlme->size);
  759. }
  760. break;
  761. case OID_TYPE_ATTACH:{
  762. struct obj_attachment *attach = r->ptr;
  763. return snprintf(str, PRIV_STR_SIZE,
  764. "id=%d\nsize=%d\n",
  765. attach->id,
  766. attach->size);
  767. }
  768. break;
  769. case OID_TYPE_SSID:{
  770. struct obj_ssid *ssid = r->ptr;
  771. return snprintf(str, PRIV_STR_SIZE,
  772. "length=%u\noctets=%.*s\n",
  773. ssid->length, ssid->length,
  774. ssid->octets);
  775. }
  776. break;
  777. case OID_TYPE_KEY:{
  778. struct obj_key *key = r->ptr;
  779. int t, i;
  780. t = snprintf(str, PRIV_STR_SIZE,
  781. "type=0x%X\nlength=0x%X\nkey=0x",
  782. key->type, key->length);
  783. for (i = 0; i < key->length; i++)
  784. t += snprintf(str + t, PRIV_STR_SIZE - t,
  785. "%02X:", key->key[i]);
  786. t += snprintf(str + t, PRIV_STR_SIZE - t, "\n");
  787. return t;
  788. }
  789. break;
  790. case OID_TYPE_RAW:
  791. case OID_TYPE_ADDR:{
  792. unsigned char *buff = r->ptr;
  793. int t, i;
  794. t = snprintf(str, PRIV_STR_SIZE, "hex data=");
  795. for (i = 0; i < isl_oid[n].size; i++)
  796. t += snprintf(str + t, PRIV_STR_SIZE - t,
  797. "%02X:", buff[i]);
  798. t += snprintf(str + t, PRIV_STR_SIZE - t, "\n");
  799. return t;
  800. }
  801. break;
  802. default:
  803. BUG();
  804. }
  805. return 0;
  806. }