debugfs.c 27 KB

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