oid_mgt.c 24 KB

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