debugfs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. #include <linux/module.h>
  2. #include <linux/dcache.h>
  3. #include <linux/debugfs.h>
  4. #include <linux/delay.h>
  5. #include <linux/mm.h>
  6. #include <linux/string.h>
  7. #include <net/iw_handler.h>
  8. #include "dev.h"
  9. #include "decl.h"
  10. #include "host.h"
  11. #include "debugfs.h"
  12. static struct dentry *lbs_dir;
  13. static char *szStates[] = {
  14. "Connected",
  15. "Disconnected"
  16. };
  17. #ifdef PROC_DEBUG
  18. static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev);
  19. #endif
  20. static int open_file_generic(struct inode *inode, struct file *file)
  21. {
  22. file->private_data = inode->i_private;
  23. return 0;
  24. }
  25. static ssize_t write_file_dummy(struct file *file, const char __user *buf,
  26. size_t count, loff_t *ppos)
  27. {
  28. return -EINVAL;
  29. }
  30. static const size_t len = PAGE_SIZE;
  31. static ssize_t lbs_dev_info(struct file *file, char __user *userbuf,
  32. size_t count, loff_t *ppos)
  33. {
  34. struct lbs_private *priv = file->private_data;
  35. size_t pos = 0;
  36. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  37. char *buf = (char *)addr;
  38. ssize_t res;
  39. pos += snprintf(buf+pos, len-pos, "state = %s\n",
  40. szStates[priv->adapter->connect_status]);
  41. pos += snprintf(buf+pos, len-pos, "region_code = %02x\n",
  42. (u32) priv->adapter->regioncode);
  43. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  44. free_page(addr);
  45. return res;
  46. }
  47. static ssize_t lbs_getscantable(struct file *file, char __user *userbuf,
  48. size_t count, loff_t *ppos)
  49. {
  50. struct lbs_private *priv = file->private_data;
  51. size_t pos = 0;
  52. int numscansdone = 0, res;
  53. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  54. char *buf = (char *)addr;
  55. DECLARE_MAC_BUF(mac);
  56. struct bss_descriptor * iter_bss;
  57. pos += snprintf(buf+pos, len-pos,
  58. "# | ch | rssi | bssid | cap | Qual | SSID \n");
  59. mutex_lock(&priv->adapter->lock);
  60. list_for_each_entry (iter_bss, &priv->adapter->network_list, list) {
  61. u16 ibss = (iter_bss->capability & WLAN_CAPABILITY_IBSS);
  62. u16 privacy = (iter_bss->capability & WLAN_CAPABILITY_PRIVACY);
  63. u16 spectrum_mgmt = (iter_bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT);
  64. pos += snprintf(buf+pos, len-pos,
  65. "%02u| %03d | %04ld | %s |",
  66. numscansdone, iter_bss->channel, iter_bss->rssi,
  67. print_mac(mac, iter_bss->bssid));
  68. pos += snprintf(buf+pos, len-pos, " %04x-", iter_bss->capability);
  69. pos += snprintf(buf+pos, len-pos, "%c%c%c |",
  70. ibss ? 'A' : 'I', privacy ? 'P' : ' ',
  71. spectrum_mgmt ? 'S' : ' ');
  72. pos += snprintf(buf+pos, len-pos, " %04d |", SCAN_RSSI(iter_bss->rssi));
  73. pos += snprintf(buf+pos, len-pos, " %s\n",
  74. escape_essid(iter_bss->ssid, iter_bss->ssid_len));
  75. numscansdone++;
  76. }
  77. mutex_unlock(&priv->adapter->lock);
  78. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  79. free_page(addr);
  80. return res;
  81. }
  82. static ssize_t lbs_sleepparams_write(struct file *file,
  83. const char __user *user_buf, size_t count,
  84. loff_t *ppos)
  85. {
  86. struct lbs_private *priv = file->private_data;
  87. ssize_t buf_size, res;
  88. int p1, p2, p3, p4, p5, p6;
  89. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  90. char *buf = (char *)addr;
  91. buf_size = min(count, len - 1);
  92. if (copy_from_user(buf, user_buf, buf_size)) {
  93. res = -EFAULT;
  94. goto out_unlock;
  95. }
  96. res = sscanf(buf, "%d %d %d %d %d %d", &p1, &p2, &p3, &p4, &p5, &p6);
  97. if (res != 6) {
  98. res = -EFAULT;
  99. goto out_unlock;
  100. }
  101. priv->adapter->sp.sp_error = p1;
  102. priv->adapter->sp.sp_offset = p2;
  103. priv->adapter->sp.sp_stabletime = p3;
  104. priv->adapter->sp.sp_calcontrol = p4;
  105. priv->adapter->sp.sp_extsleepclk = p5;
  106. priv->adapter->sp.sp_reserved = p6;
  107. res = lbs_prepare_and_send_command(priv,
  108. CMD_802_11_SLEEP_PARAMS,
  109. CMD_ACT_SET,
  110. CMD_OPTION_WAITFORRSP, 0, NULL);
  111. if (!res)
  112. res = count;
  113. else
  114. res = -EINVAL;
  115. out_unlock:
  116. free_page(addr);
  117. return res;
  118. }
  119. static ssize_t lbs_sleepparams_read(struct file *file, char __user *userbuf,
  120. size_t count, loff_t *ppos)
  121. {
  122. struct lbs_private *priv = file->private_data;
  123. struct lbs_adapter *adapter = priv->adapter;
  124. ssize_t res;
  125. size_t pos = 0;
  126. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  127. char *buf = (char *)addr;
  128. res = lbs_prepare_and_send_command(priv,
  129. CMD_802_11_SLEEP_PARAMS,
  130. CMD_ACT_GET,
  131. CMD_OPTION_WAITFORRSP, 0, NULL);
  132. if (res) {
  133. res = -EFAULT;
  134. goto out_unlock;
  135. }
  136. pos += snprintf(buf, len, "%d %d %d %d %d %d\n", adapter->sp.sp_error,
  137. adapter->sp.sp_offset, adapter->sp.sp_stabletime,
  138. adapter->sp.sp_calcontrol, adapter->sp.sp_extsleepclk,
  139. adapter->sp.sp_reserved);
  140. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  141. out_unlock:
  142. free_page(addr);
  143. return res;
  144. }
  145. static ssize_t lbs_extscan(struct file *file, const char __user *userbuf,
  146. size_t count, loff_t *ppos)
  147. {
  148. struct lbs_private *priv = file->private_data;
  149. ssize_t res, buf_size;
  150. union iwreq_data wrqu;
  151. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  152. char *buf = (char *)addr;
  153. buf_size = min(count, len - 1);
  154. if (copy_from_user(buf, userbuf, buf_size)) {
  155. res = -EFAULT;
  156. goto out_unlock;
  157. }
  158. lbs_send_specific_ssid_scan(priv, buf, strlen(buf)-1, 0);
  159. memset(&wrqu, 0, sizeof(union iwreq_data));
  160. wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
  161. out_unlock:
  162. free_page(addr);
  163. return count;
  164. }
  165. static void lbs_parse_bssid(char *buf, size_t count,
  166. struct lbs_ioctl_user_scan_cfg *scan_cfg)
  167. {
  168. char *hold;
  169. unsigned int mac[ETH_ALEN];
  170. hold = strstr(buf, "bssid=");
  171. if (!hold)
  172. return;
  173. hold += 6;
  174. sscanf(hold, "%02x:%02x:%02x:%02x:%02x:%02x",
  175. mac, mac+1, mac+2, mac+3, mac+4, mac+5);
  176. memcpy(scan_cfg->bssid, mac, ETH_ALEN);
  177. }
  178. static void lbs_parse_ssid(char *buf, size_t count,
  179. struct lbs_ioctl_user_scan_cfg *scan_cfg)
  180. {
  181. char *hold, *end;
  182. ssize_t size;
  183. hold = strstr(buf, "ssid=");
  184. if (!hold)
  185. return;
  186. hold += 5;
  187. end = strchr(hold, ' ');
  188. if (!end)
  189. end = buf + count - 1;
  190. size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
  191. strncpy(scan_cfg->ssid, hold, size);
  192. return;
  193. }
  194. static int lbs_parse_clear(char *buf, size_t count, const char *tag)
  195. {
  196. char *hold;
  197. int val;
  198. hold = strstr(buf, tag);
  199. if (!hold)
  200. return 0;
  201. hold += strlen(tag);
  202. sscanf(hold, "%d", &val);
  203. if (val != 0)
  204. val = 1;
  205. return val;
  206. }
  207. static int lbs_parse_dur(char *buf, size_t count,
  208. struct lbs_ioctl_user_scan_cfg *scan_cfg)
  209. {
  210. char *hold;
  211. int val;
  212. hold = strstr(buf, "dur=");
  213. if (!hold)
  214. return 0;
  215. hold += 4;
  216. sscanf(hold, "%d", &val);
  217. return val;
  218. }
  219. static void lbs_parse_type(char *buf, size_t count,
  220. struct lbs_ioctl_user_scan_cfg *scan_cfg)
  221. {
  222. char *hold;
  223. int val;
  224. hold = strstr(buf, "type=");
  225. if (!hold)
  226. return;
  227. hold += 5;
  228. sscanf(hold, "%d", &val);
  229. /* type=1,2 or 3 */
  230. if (val < 1 || val > 3)
  231. return;
  232. scan_cfg->bsstype = val;
  233. return;
  234. }
  235. static ssize_t lbs_setuserscan(struct file *file,
  236. const char __user *userbuf,
  237. size_t count, loff_t *ppos)
  238. {
  239. struct lbs_private *priv = file->private_data;
  240. ssize_t res, buf_size;
  241. struct lbs_ioctl_user_scan_cfg *scan_cfg;
  242. union iwreq_data wrqu;
  243. int dur;
  244. char *buf = (char *)get_zeroed_page(GFP_KERNEL);
  245. if (!buf)
  246. return -ENOMEM;
  247. buf_size = min(count, len - 1);
  248. if (copy_from_user(buf, userbuf, buf_size)) {
  249. res = -EFAULT;
  250. goto out_buf;
  251. }
  252. scan_cfg = kzalloc(sizeof(struct lbs_ioctl_user_scan_cfg), GFP_KERNEL);
  253. if (!scan_cfg) {
  254. res = -ENOMEM;
  255. goto out_buf;
  256. }
  257. res = count;
  258. scan_cfg->bsstype = LBS_SCAN_BSS_TYPE_ANY;
  259. dur = lbs_parse_dur(buf, count, scan_cfg);
  260. lbs_parse_bssid(buf, count, scan_cfg);
  261. scan_cfg->clear_bssid = lbs_parse_clear(buf, count, "clear_bssid=");
  262. lbs_parse_ssid(buf, count, scan_cfg);
  263. scan_cfg->clear_ssid = lbs_parse_clear(buf, count, "clear_ssid=");
  264. lbs_parse_type(buf, count, scan_cfg);
  265. lbs_scan_networks(priv, scan_cfg, 1);
  266. wait_event_interruptible(priv->adapter->cmd_pending,
  267. priv->adapter->surpriseremoved ||
  268. (!priv->adapter->cur_cmd && list_empty(&priv->adapter->cmdpendingq)));
  269. if (priv->adapter->surpriseremoved)
  270. goto out_scan_cfg;
  271. memset(&wrqu, 0x00, sizeof(union iwreq_data));
  272. wireless_send_event(priv->dev, SIOCGIWSCAN, &wrqu, NULL);
  273. out_scan_cfg:
  274. kfree(scan_cfg);
  275. out_buf:
  276. free_page((unsigned long)buf);
  277. return res;
  278. }
  279. /*
  280. * When calling CMD_802_11_SUBSCRIBE_EVENT with CMD_ACT_GET, me might
  281. * get a bunch of vendor-specific TLVs (a.k.a. IEs) back from the
  282. * firmware. Here's an example:
  283. * 04 01 02 00 00 00 05 01 02 00 00 00 06 01 02 00
  284. * 00 00 07 01 02 00 3c 00 00 00 00 00 00 00 03 03
  285. * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  286. *
  287. * The 04 01 is the TLV type (here TLV_TYPE_RSSI_LOW), 02 00 is the length,
  288. * 00 00 are the data bytes of this TLV. For this TLV, their meaning is
  289. * defined in mrvlietypes_thresholds
  290. *
  291. * This function searches in this TLV data chunk for a given TLV type
  292. * and returns a pointer to the first data byte of the TLV, or to NULL
  293. * if the TLV hasn't been found.
  294. */
  295. static void *lbs_tlv_find(u16 tlv_type, const u8 *tlv, u16 size)
  296. {
  297. __le16 le_type = cpu_to_le16(tlv_type);
  298. ssize_t pos = 0;
  299. struct mrvlietypesheader *tlv_h;
  300. while (pos < size) {
  301. u16 length;
  302. tlv_h = (struct mrvlietypesheader *) tlv;
  303. if (tlv_h->type == le_type)
  304. return tlv_h;
  305. if (tlv_h->len == 0)
  306. return NULL;
  307. length = le16_to_cpu(tlv_h->len) +
  308. sizeof(struct mrvlietypesheader);
  309. pos += length;
  310. tlv += length;
  311. }
  312. return NULL;
  313. }
  314. /*
  315. * This just gets the bitmap of currently subscribed events. Used when
  316. * adding an additonal event subscription.
  317. */
  318. static u16 lbs_get_events_bitmap(struct lbs_private *priv)
  319. {
  320. ssize_t res;
  321. struct cmd_ds_802_11_subscribe_event *events = kzalloc(
  322. sizeof(struct cmd_ds_802_11_subscribe_event),
  323. GFP_KERNEL);
  324. res = lbs_prepare_and_send_command(priv,
  325. CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
  326. CMD_OPTION_WAITFORRSP, 0, events);
  327. if (res) {
  328. kfree(events);
  329. return 0;
  330. }
  331. return le16_to_cpu(events->events);
  332. }
  333. static ssize_t lbs_threshold_read(
  334. u16 tlv_type, u16 event_mask,
  335. struct file *file, char __user *userbuf,
  336. size_t count, loff_t *ppos)
  337. {
  338. struct lbs_private *priv = file->private_data;
  339. ssize_t res = 0;
  340. size_t pos = 0;
  341. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  342. char *buf = (char *)addr;
  343. u8 value;
  344. u8 freq;
  345. struct cmd_ds_802_11_subscribe_event *events = kzalloc(
  346. sizeof(struct cmd_ds_802_11_subscribe_event),
  347. GFP_KERNEL);
  348. struct mrvlietypes_thresholds *got;
  349. res = lbs_prepare_and_send_command(priv,
  350. CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_GET,
  351. CMD_OPTION_WAITFORRSP, 0, events);
  352. if (res) {
  353. kfree(events);
  354. return res;
  355. }
  356. got = lbs_tlv_find(tlv_type, events->tlv, sizeof(events->tlv));
  357. if (got) {
  358. value = got->value;
  359. freq = got->freq;
  360. }
  361. kfree(events);
  362. if (got)
  363. pos += snprintf(buf, len, "%d %d %d\n", value, freq,
  364. !!(le16_to_cpu(events->events) & event_mask));
  365. res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  366. free_page(addr);
  367. return res;
  368. }
  369. static ssize_t lbs_threshold_write(
  370. u16 tlv_type, u16 event_mask,
  371. struct file *file,
  372. const char __user *userbuf,
  373. size_t count, loff_t *ppos)
  374. {
  375. struct lbs_private *priv = file->private_data;
  376. ssize_t res, buf_size;
  377. int value, freq, curr_mask, new_mask;
  378. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  379. char *buf = (char *)addr;
  380. struct cmd_ds_802_11_subscribe_event *events;
  381. buf_size = min(count, len - 1);
  382. if (copy_from_user(buf, userbuf, buf_size)) {
  383. res = -EFAULT;
  384. goto out_unlock;
  385. }
  386. res = sscanf(buf, "%d %d %d", &value, &freq, &new_mask);
  387. if (res != 3) {
  388. res = -EFAULT;
  389. goto out_unlock;
  390. }
  391. curr_mask = lbs_get_events_bitmap(priv);
  392. if (new_mask)
  393. new_mask = curr_mask | event_mask;
  394. else
  395. new_mask = curr_mask & ~event_mask;
  396. /* Now everything is set and we can send stuff down to the firmware */
  397. events = kzalloc(
  398. sizeof(struct cmd_ds_802_11_subscribe_event),
  399. GFP_KERNEL);
  400. if (events) {
  401. struct mrvlietypes_thresholds *tlv =
  402. (struct mrvlietypes_thresholds *) events->tlv;
  403. events->action = cpu_to_le16(CMD_ACT_SET);
  404. events->events = cpu_to_le16(new_mask);
  405. tlv->header.type = cpu_to_le16(tlv_type);
  406. tlv->header.len = cpu_to_le16(
  407. sizeof(struct mrvlietypes_thresholds) -
  408. sizeof(struct mrvlietypesheader));
  409. tlv->value = value;
  410. if (tlv_type != TLV_TYPE_BCNMISS)
  411. tlv->freq = freq;
  412. lbs_prepare_and_send_command(priv,
  413. CMD_802_11_SUBSCRIBE_EVENT, CMD_ACT_SET,
  414. CMD_OPTION_WAITFORRSP, 0, events);
  415. kfree(events);
  416. }
  417. res = count;
  418. out_unlock:
  419. free_page(addr);
  420. return res;
  421. }
  422. static ssize_t lbs_lowrssi_read(
  423. struct file *file, char __user *userbuf,
  424. size_t count, loff_t *ppos)
  425. {
  426. return lbs_threshold_read(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
  427. file, userbuf, count, ppos);
  428. }
  429. static ssize_t lbs_lowrssi_write(
  430. struct file *file, const char __user *userbuf,
  431. size_t count, loff_t *ppos)
  432. {
  433. return lbs_threshold_write(TLV_TYPE_RSSI_LOW, CMD_SUBSCRIBE_RSSI_LOW,
  434. file, userbuf, count, ppos);
  435. }
  436. static ssize_t lbs_lowsnr_read(
  437. struct file *file, char __user *userbuf,
  438. size_t count, loff_t *ppos)
  439. {
  440. return lbs_threshold_read(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
  441. file, userbuf, count, ppos);
  442. }
  443. static ssize_t lbs_lowsnr_write(
  444. struct file *file, const char __user *userbuf,
  445. size_t count, loff_t *ppos)
  446. {
  447. return lbs_threshold_write(TLV_TYPE_SNR_LOW, CMD_SUBSCRIBE_SNR_LOW,
  448. file, userbuf, count, ppos);
  449. }
  450. static ssize_t lbs_failcount_read(
  451. struct file *file, char __user *userbuf,
  452. size_t count, loff_t *ppos)
  453. {
  454. return lbs_threshold_read(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
  455. file, userbuf, count, ppos);
  456. }
  457. static ssize_t lbs_failcount_write(
  458. struct file *file, const char __user *userbuf,
  459. size_t count, loff_t *ppos)
  460. {
  461. return lbs_threshold_write(TLV_TYPE_FAILCOUNT, CMD_SUBSCRIBE_FAILCOUNT,
  462. file, userbuf, count, ppos);
  463. }
  464. static ssize_t lbs_highrssi_read(
  465. struct file *file, char __user *userbuf,
  466. size_t count, loff_t *ppos)
  467. {
  468. return lbs_threshold_read(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
  469. file, userbuf, count, ppos);
  470. }
  471. static ssize_t lbs_highrssi_write(
  472. struct file *file, const char __user *userbuf,
  473. size_t count, loff_t *ppos)
  474. {
  475. return lbs_threshold_write(TLV_TYPE_RSSI_HIGH, CMD_SUBSCRIBE_RSSI_HIGH,
  476. file, userbuf, count, ppos);
  477. }
  478. static ssize_t lbs_highsnr_read(
  479. struct file *file, char __user *userbuf,
  480. size_t count, loff_t *ppos)
  481. {
  482. return lbs_threshold_read(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
  483. file, userbuf, count, ppos);
  484. }
  485. static ssize_t lbs_highsnr_write(
  486. struct file *file, const char __user *userbuf,
  487. size_t count, loff_t *ppos)
  488. {
  489. return lbs_threshold_write(TLV_TYPE_SNR_HIGH, CMD_SUBSCRIBE_SNR_HIGH,
  490. file, userbuf, count, ppos);
  491. }
  492. static ssize_t lbs_bcnmiss_read(
  493. struct file *file, char __user *userbuf,
  494. size_t count, loff_t *ppos)
  495. {
  496. return lbs_threshold_read(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
  497. file, userbuf, count, ppos);
  498. }
  499. static ssize_t lbs_bcnmiss_write(
  500. struct file *file, const char __user *userbuf,
  501. size_t count, loff_t *ppos)
  502. {
  503. return lbs_threshold_write(TLV_TYPE_BCNMISS, CMD_SUBSCRIBE_BCNMISS,
  504. file, userbuf, count, ppos);
  505. }
  506. static ssize_t lbs_rdmac_read(struct file *file, char __user *userbuf,
  507. size_t count, loff_t *ppos)
  508. {
  509. struct lbs_private *priv = file->private_data;
  510. struct lbs_adapter *adapter = priv->adapter;
  511. struct lbs_offset_value offval;
  512. ssize_t pos = 0;
  513. int ret;
  514. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  515. char *buf = (char *)addr;
  516. offval.offset = priv->mac_offset;
  517. offval.value = 0;
  518. ret = lbs_prepare_and_send_command(priv,
  519. CMD_MAC_REG_ACCESS, 0,
  520. CMD_OPTION_WAITFORRSP, 0, &offval);
  521. mdelay(10);
  522. pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
  523. priv->mac_offset, adapter->offsetvalue.value);
  524. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  525. free_page(addr);
  526. return ret;
  527. }
  528. static ssize_t lbs_rdmac_write(struct file *file,
  529. const char __user *userbuf,
  530. size_t count, loff_t *ppos)
  531. {
  532. struct lbs_private *priv = file->private_data;
  533. ssize_t res, buf_size;
  534. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  535. char *buf = (char *)addr;
  536. buf_size = min(count, len - 1);
  537. if (copy_from_user(buf, userbuf, buf_size)) {
  538. res = -EFAULT;
  539. goto out_unlock;
  540. }
  541. priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
  542. res = count;
  543. out_unlock:
  544. free_page(addr);
  545. return res;
  546. }
  547. static ssize_t lbs_wrmac_write(struct file *file,
  548. const char __user *userbuf,
  549. size_t count, loff_t *ppos)
  550. {
  551. struct lbs_private *priv = file->private_data;
  552. ssize_t res, buf_size;
  553. u32 offset, value;
  554. struct lbs_offset_value offval;
  555. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  556. char *buf = (char *)addr;
  557. buf_size = min(count, len - 1);
  558. if (copy_from_user(buf, userbuf, buf_size)) {
  559. res = -EFAULT;
  560. goto out_unlock;
  561. }
  562. res = sscanf(buf, "%x %x", &offset, &value);
  563. if (res != 2) {
  564. res = -EFAULT;
  565. goto out_unlock;
  566. }
  567. offval.offset = offset;
  568. offval.value = value;
  569. res = lbs_prepare_and_send_command(priv,
  570. CMD_MAC_REG_ACCESS, 1,
  571. CMD_OPTION_WAITFORRSP, 0, &offval);
  572. mdelay(10);
  573. res = count;
  574. out_unlock:
  575. free_page(addr);
  576. return res;
  577. }
  578. static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
  579. size_t count, loff_t *ppos)
  580. {
  581. struct lbs_private *priv = file->private_data;
  582. struct lbs_adapter *adapter = priv->adapter;
  583. struct lbs_offset_value offval;
  584. ssize_t pos = 0;
  585. int ret;
  586. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  587. char *buf = (char *)addr;
  588. offval.offset = priv->bbp_offset;
  589. offval.value = 0;
  590. ret = lbs_prepare_and_send_command(priv,
  591. CMD_BBP_REG_ACCESS, 0,
  592. CMD_OPTION_WAITFORRSP, 0, &offval);
  593. mdelay(10);
  594. pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
  595. priv->bbp_offset, adapter->offsetvalue.value);
  596. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  597. free_page(addr);
  598. return ret;
  599. }
  600. static ssize_t lbs_rdbbp_write(struct file *file,
  601. const char __user *userbuf,
  602. size_t count, loff_t *ppos)
  603. {
  604. struct lbs_private *priv = file->private_data;
  605. ssize_t res, buf_size;
  606. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  607. char *buf = (char *)addr;
  608. buf_size = min(count, len - 1);
  609. if (copy_from_user(buf, userbuf, buf_size)) {
  610. res = -EFAULT;
  611. goto out_unlock;
  612. }
  613. priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
  614. res = count;
  615. out_unlock:
  616. free_page(addr);
  617. return res;
  618. }
  619. static ssize_t lbs_wrbbp_write(struct file *file,
  620. const char __user *userbuf,
  621. size_t count, loff_t *ppos)
  622. {
  623. struct lbs_private *priv = file->private_data;
  624. ssize_t res, buf_size;
  625. u32 offset, value;
  626. struct lbs_offset_value offval;
  627. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  628. char *buf = (char *)addr;
  629. buf_size = min(count, len - 1);
  630. if (copy_from_user(buf, userbuf, buf_size)) {
  631. res = -EFAULT;
  632. goto out_unlock;
  633. }
  634. res = sscanf(buf, "%x %x", &offset, &value);
  635. if (res != 2) {
  636. res = -EFAULT;
  637. goto out_unlock;
  638. }
  639. offval.offset = offset;
  640. offval.value = value;
  641. res = lbs_prepare_and_send_command(priv,
  642. CMD_BBP_REG_ACCESS, 1,
  643. CMD_OPTION_WAITFORRSP, 0, &offval);
  644. mdelay(10);
  645. res = count;
  646. out_unlock:
  647. free_page(addr);
  648. return res;
  649. }
  650. static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
  651. size_t count, loff_t *ppos)
  652. {
  653. struct lbs_private *priv = file->private_data;
  654. struct lbs_adapter *adapter = priv->adapter;
  655. struct lbs_offset_value offval;
  656. ssize_t pos = 0;
  657. int ret;
  658. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  659. char *buf = (char *)addr;
  660. offval.offset = priv->rf_offset;
  661. offval.value = 0;
  662. ret = lbs_prepare_and_send_command(priv,
  663. CMD_RF_REG_ACCESS, 0,
  664. CMD_OPTION_WAITFORRSP, 0, &offval);
  665. mdelay(10);
  666. pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
  667. priv->rf_offset, adapter->offsetvalue.value);
  668. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  669. free_page(addr);
  670. return ret;
  671. }
  672. static ssize_t lbs_rdrf_write(struct file *file,
  673. const char __user *userbuf,
  674. size_t count, loff_t *ppos)
  675. {
  676. struct lbs_private *priv = file->private_data;
  677. ssize_t res, buf_size;
  678. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  679. char *buf = (char *)addr;
  680. buf_size = min(count, len - 1);
  681. if (copy_from_user(buf, userbuf, buf_size)) {
  682. res = -EFAULT;
  683. goto out_unlock;
  684. }
  685. priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
  686. res = count;
  687. out_unlock:
  688. free_page(addr);
  689. return res;
  690. }
  691. static ssize_t lbs_wrrf_write(struct file *file,
  692. const char __user *userbuf,
  693. size_t count, loff_t *ppos)
  694. {
  695. struct lbs_private *priv = file->private_data;
  696. ssize_t res, buf_size;
  697. u32 offset, value;
  698. struct lbs_offset_value offval;
  699. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  700. char *buf = (char *)addr;
  701. buf_size = min(count, len - 1);
  702. if (copy_from_user(buf, userbuf, buf_size)) {
  703. res = -EFAULT;
  704. goto out_unlock;
  705. }
  706. res = sscanf(buf, "%x %x", &offset, &value);
  707. if (res != 2) {
  708. res = -EFAULT;
  709. goto out_unlock;
  710. }
  711. offval.offset = offset;
  712. offval.value = value;
  713. res = lbs_prepare_and_send_command(priv,
  714. CMD_RF_REG_ACCESS, 1,
  715. CMD_OPTION_WAITFORRSP, 0, &offval);
  716. mdelay(10);
  717. res = count;
  718. out_unlock:
  719. free_page(addr);
  720. return res;
  721. }
  722. #define FOPS(fread, fwrite) { \
  723. .owner = THIS_MODULE, \
  724. .open = open_file_generic, \
  725. .read = (fread), \
  726. .write = (fwrite), \
  727. }
  728. struct lbs_debugfs_files {
  729. char *name;
  730. int perm;
  731. struct file_operations fops;
  732. };
  733. static struct lbs_debugfs_files debugfs_files[] = {
  734. { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
  735. { "getscantable", 0444, FOPS(lbs_getscantable,
  736. write_file_dummy), },
  737. { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
  738. lbs_sleepparams_write), },
  739. { "extscan", 0600, FOPS(NULL, lbs_extscan), },
  740. { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
  741. };
  742. static struct lbs_debugfs_files debugfs_events_files[] = {
  743. {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
  744. lbs_lowrssi_write), },
  745. {"low_snr", 0644, FOPS(lbs_lowsnr_read,
  746. lbs_lowsnr_write), },
  747. {"failure_count", 0644, FOPS(lbs_failcount_read,
  748. lbs_failcount_write), },
  749. {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
  750. lbs_bcnmiss_write), },
  751. {"high_rssi", 0644, FOPS(lbs_highrssi_read,
  752. lbs_highrssi_write), },
  753. {"high_snr", 0644, FOPS(lbs_highsnr_read,
  754. lbs_highsnr_write), },
  755. };
  756. static struct lbs_debugfs_files debugfs_regs_files[] = {
  757. {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
  758. {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
  759. {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
  760. {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
  761. {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
  762. {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
  763. };
  764. void lbs_debugfs_init(void)
  765. {
  766. if (!lbs_dir)
  767. lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
  768. return;
  769. }
  770. void lbs_debugfs_remove(void)
  771. {
  772. if (lbs_dir)
  773. debugfs_remove(lbs_dir);
  774. return;
  775. }
  776. void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
  777. {
  778. int i;
  779. struct lbs_debugfs_files *files;
  780. if (!lbs_dir)
  781. goto exit;
  782. priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
  783. if (!priv->debugfs_dir)
  784. goto exit;
  785. for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
  786. files = &debugfs_files[i];
  787. priv->debugfs_files[i] = debugfs_create_file(files->name,
  788. files->perm,
  789. priv->debugfs_dir,
  790. priv,
  791. &files->fops);
  792. }
  793. priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
  794. if (!priv->events_dir)
  795. goto exit;
  796. for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
  797. files = &debugfs_events_files[i];
  798. priv->debugfs_events_files[i] = debugfs_create_file(files->name,
  799. files->perm,
  800. priv->events_dir,
  801. priv,
  802. &files->fops);
  803. }
  804. priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
  805. if (!priv->regs_dir)
  806. goto exit;
  807. for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
  808. files = &debugfs_regs_files[i];
  809. priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
  810. files->perm,
  811. priv->regs_dir,
  812. priv,
  813. &files->fops);
  814. }
  815. #ifdef PROC_DEBUG
  816. lbs_debug_init(priv, dev);
  817. #endif
  818. exit:
  819. return;
  820. }
  821. void lbs_debugfs_remove_one(struct lbs_private *priv)
  822. {
  823. int i;
  824. for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
  825. debugfs_remove(priv->debugfs_regs_files[i]);
  826. debugfs_remove(priv->regs_dir);
  827. for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
  828. debugfs_remove(priv->debugfs_events_files[i]);
  829. debugfs_remove(priv->events_dir);
  830. #ifdef PROC_DEBUG
  831. debugfs_remove(priv->debugfs_debug);
  832. #endif
  833. for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
  834. debugfs_remove(priv->debugfs_files[i]);
  835. debugfs_remove(priv->debugfs_dir);
  836. }
  837. /* debug entry */
  838. #ifdef PROC_DEBUG
  839. #define item_size(n) (FIELD_SIZEOF(struct lbs_adapter, n))
  840. #define item_addr(n) (offsetof(struct lbs_adapter, n))
  841. struct debug_data {
  842. char name[32];
  843. u32 size;
  844. size_t addr;
  845. };
  846. /* To debug any member of struct lbs_adapter, simply add one line here.
  847. */
  848. static struct debug_data items[] = {
  849. {"intcounter", item_size(intcounter), item_addr(intcounter)},
  850. {"psmode", item_size(psmode), item_addr(psmode)},
  851. {"psstate", item_size(psstate), item_addr(psstate)},
  852. };
  853. static int num_of_items = ARRAY_SIZE(items);
  854. /**
  855. * @brief proc read function
  856. *
  857. * @param page pointer to buffer
  858. * @param s read data starting position
  859. * @param off offset
  860. * @param cnt counter
  861. * @param eof end of file flag
  862. * @param data data to output
  863. * @return number of output data
  864. */
  865. static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
  866. size_t count, loff_t *ppos)
  867. {
  868. int val = 0;
  869. size_t pos = 0;
  870. ssize_t res;
  871. char *p;
  872. int i;
  873. struct debug_data *d;
  874. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  875. char *buf = (char *)addr;
  876. p = buf;
  877. d = (struct debug_data *)file->private_data;
  878. for (i = 0; i < num_of_items; i++) {
  879. if (d[i].size == 1)
  880. val = *((u8 *) d[i].addr);
  881. else if (d[i].size == 2)
  882. val = *((u16 *) d[i].addr);
  883. else if (d[i].size == 4)
  884. val = *((u32 *) d[i].addr);
  885. else if (d[i].size == 8)
  886. val = *((u64 *) d[i].addr);
  887. pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
  888. }
  889. res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
  890. free_page(addr);
  891. return res;
  892. }
  893. /**
  894. * @brief proc write function
  895. *
  896. * @param f file pointer
  897. * @param buf pointer to data buffer
  898. * @param cnt data number to write
  899. * @param data data to write
  900. * @return number of data
  901. */
  902. static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
  903. size_t cnt, loff_t *ppos)
  904. {
  905. int r, i;
  906. char *pdata;
  907. char *p;
  908. char *p0;
  909. char *p1;
  910. char *p2;
  911. struct debug_data *d = (struct debug_data *)f->private_data;
  912. pdata = kmalloc(cnt, GFP_KERNEL);
  913. if (pdata == NULL)
  914. return 0;
  915. if (copy_from_user(pdata, buf, cnt)) {
  916. lbs_deb_debugfs("Copy from user failed\n");
  917. kfree(pdata);
  918. return 0;
  919. }
  920. p0 = pdata;
  921. for (i = 0; i < num_of_items; i++) {
  922. do {
  923. p = strstr(p0, d[i].name);
  924. if (p == NULL)
  925. break;
  926. p1 = strchr(p, '\n');
  927. if (p1 == NULL)
  928. break;
  929. p0 = p1++;
  930. p2 = strchr(p, '=');
  931. if (!p2)
  932. break;
  933. p2++;
  934. r = simple_strtoul(p2, NULL, 0);
  935. if (d[i].size == 1)
  936. *((u8 *) d[i].addr) = (u8) r;
  937. else if (d[i].size == 2)
  938. *((u16 *) d[i].addr) = (u16) r;
  939. else if (d[i].size == 4)
  940. *((u32 *) d[i].addr) = (u32) r;
  941. else if (d[i].size == 8)
  942. *((u64 *) d[i].addr) = (u64) r;
  943. break;
  944. } while (1);
  945. }
  946. kfree(pdata);
  947. return (ssize_t)cnt;
  948. }
  949. static struct file_operations lbs_debug_fops = {
  950. .owner = THIS_MODULE,
  951. .open = open_file_generic,
  952. .write = lbs_debugfs_write,
  953. .read = lbs_debugfs_read,
  954. };
  955. /**
  956. * @brief create debug proc file
  957. *
  958. * @param priv pointer struct lbs_private
  959. * @param dev pointer net_device
  960. * @return N/A
  961. */
  962. static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
  963. {
  964. int i;
  965. if (!priv->debugfs_dir)
  966. return;
  967. for (i = 0; i < num_of_items; i++)
  968. items[i].addr += (size_t) priv->adapter;
  969. priv->debugfs_debug = debugfs_create_file("debug", 0644,
  970. priv->debugfs_dir, &items[0],
  971. &lbs_debug_fops);
  972. }
  973. #endif