debugfs.c 27 KB

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