debugfs.c 27 KB

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