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