debugfs.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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 ||
  267. (!priv->cur_cmd && list_empty(&priv->cmdpendingq)));
  268. if (priv->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_offset_value offval;
  510. ssize_t pos = 0;
  511. int ret;
  512. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  513. char *buf = (char *)addr;
  514. offval.offset = priv->mac_offset;
  515. offval.value = 0;
  516. ret = lbs_prepare_and_send_command(priv,
  517. CMD_MAC_REG_ACCESS, 0,
  518. CMD_OPTION_WAITFORRSP, 0, &offval);
  519. mdelay(10);
  520. pos += snprintf(buf+pos, len-pos, "MAC[0x%x] = 0x%08x\n",
  521. priv->mac_offset, priv->offsetvalue.value);
  522. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  523. free_page(addr);
  524. return ret;
  525. }
  526. static ssize_t lbs_rdmac_write(struct file *file,
  527. const char __user *userbuf,
  528. size_t count, loff_t *ppos)
  529. {
  530. struct lbs_private *priv = file->private_data;
  531. ssize_t res, buf_size;
  532. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  533. char *buf = (char *)addr;
  534. buf_size = min(count, len - 1);
  535. if (copy_from_user(buf, userbuf, buf_size)) {
  536. res = -EFAULT;
  537. goto out_unlock;
  538. }
  539. priv->mac_offset = simple_strtoul((char *)buf, NULL, 16);
  540. res = count;
  541. out_unlock:
  542. free_page(addr);
  543. return res;
  544. }
  545. static ssize_t lbs_wrmac_write(struct file *file,
  546. const char __user *userbuf,
  547. size_t count, loff_t *ppos)
  548. {
  549. struct lbs_private *priv = file->private_data;
  550. ssize_t res, buf_size;
  551. u32 offset, value;
  552. struct lbs_offset_value offval;
  553. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  554. char *buf = (char *)addr;
  555. buf_size = min(count, len - 1);
  556. if (copy_from_user(buf, userbuf, buf_size)) {
  557. res = -EFAULT;
  558. goto out_unlock;
  559. }
  560. res = sscanf(buf, "%x %x", &offset, &value);
  561. if (res != 2) {
  562. res = -EFAULT;
  563. goto out_unlock;
  564. }
  565. offval.offset = offset;
  566. offval.value = value;
  567. res = lbs_prepare_and_send_command(priv,
  568. CMD_MAC_REG_ACCESS, 1,
  569. CMD_OPTION_WAITFORRSP, 0, &offval);
  570. mdelay(10);
  571. res = count;
  572. out_unlock:
  573. free_page(addr);
  574. return res;
  575. }
  576. static ssize_t lbs_rdbbp_read(struct file *file, char __user *userbuf,
  577. size_t count, loff_t *ppos)
  578. {
  579. struct lbs_private *priv = file->private_data;
  580. struct lbs_offset_value offval;
  581. ssize_t pos = 0;
  582. int ret;
  583. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  584. char *buf = (char *)addr;
  585. offval.offset = priv->bbp_offset;
  586. offval.value = 0;
  587. ret = lbs_prepare_and_send_command(priv,
  588. CMD_BBP_REG_ACCESS, 0,
  589. CMD_OPTION_WAITFORRSP, 0, &offval);
  590. mdelay(10);
  591. pos += snprintf(buf+pos, len-pos, "BBP[0x%x] = 0x%08x\n",
  592. priv->bbp_offset, priv->offsetvalue.value);
  593. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  594. free_page(addr);
  595. return ret;
  596. }
  597. static ssize_t lbs_rdbbp_write(struct file *file,
  598. const char __user *userbuf,
  599. size_t count, loff_t *ppos)
  600. {
  601. struct lbs_private *priv = file->private_data;
  602. ssize_t res, buf_size;
  603. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  604. char *buf = (char *)addr;
  605. buf_size = min(count, len - 1);
  606. if (copy_from_user(buf, userbuf, buf_size)) {
  607. res = -EFAULT;
  608. goto out_unlock;
  609. }
  610. priv->bbp_offset = simple_strtoul((char *)buf, NULL, 16);
  611. res = count;
  612. out_unlock:
  613. free_page(addr);
  614. return res;
  615. }
  616. static ssize_t lbs_wrbbp_write(struct file *file,
  617. const char __user *userbuf,
  618. size_t count, loff_t *ppos)
  619. {
  620. struct lbs_private *priv = file->private_data;
  621. ssize_t res, buf_size;
  622. u32 offset, value;
  623. struct lbs_offset_value offval;
  624. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  625. char *buf = (char *)addr;
  626. buf_size = min(count, len - 1);
  627. if (copy_from_user(buf, userbuf, buf_size)) {
  628. res = -EFAULT;
  629. goto out_unlock;
  630. }
  631. res = sscanf(buf, "%x %x", &offset, &value);
  632. if (res != 2) {
  633. res = -EFAULT;
  634. goto out_unlock;
  635. }
  636. offval.offset = offset;
  637. offval.value = value;
  638. res = lbs_prepare_and_send_command(priv,
  639. CMD_BBP_REG_ACCESS, 1,
  640. CMD_OPTION_WAITFORRSP, 0, &offval);
  641. mdelay(10);
  642. res = count;
  643. out_unlock:
  644. free_page(addr);
  645. return res;
  646. }
  647. static ssize_t lbs_rdrf_read(struct file *file, char __user *userbuf,
  648. size_t count, loff_t *ppos)
  649. {
  650. struct lbs_private *priv = file->private_data;
  651. struct lbs_offset_value offval;
  652. ssize_t pos = 0;
  653. int ret;
  654. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  655. char *buf = (char *)addr;
  656. offval.offset = priv->rf_offset;
  657. offval.value = 0;
  658. ret = lbs_prepare_and_send_command(priv,
  659. CMD_RF_REG_ACCESS, 0,
  660. CMD_OPTION_WAITFORRSP, 0, &offval);
  661. mdelay(10);
  662. pos += snprintf(buf+pos, len-pos, "RF[0x%x] = 0x%08x\n",
  663. priv->rf_offset, priv->offsetvalue.value);
  664. ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
  665. free_page(addr);
  666. return ret;
  667. }
  668. static ssize_t lbs_rdrf_write(struct file *file,
  669. const char __user *userbuf,
  670. size_t count, loff_t *ppos)
  671. {
  672. struct lbs_private *priv = file->private_data;
  673. ssize_t res, buf_size;
  674. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  675. char *buf = (char *)addr;
  676. buf_size = min(count, len - 1);
  677. if (copy_from_user(buf, userbuf, buf_size)) {
  678. res = -EFAULT;
  679. goto out_unlock;
  680. }
  681. priv->rf_offset = simple_strtoul((char *)buf, NULL, 16);
  682. res = count;
  683. out_unlock:
  684. free_page(addr);
  685. return res;
  686. }
  687. static ssize_t lbs_wrrf_write(struct file *file,
  688. const char __user *userbuf,
  689. size_t count, loff_t *ppos)
  690. {
  691. struct lbs_private *priv = file->private_data;
  692. ssize_t res, buf_size;
  693. u32 offset, value;
  694. struct lbs_offset_value offval;
  695. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  696. char *buf = (char *)addr;
  697. buf_size = min(count, len - 1);
  698. if (copy_from_user(buf, userbuf, buf_size)) {
  699. res = -EFAULT;
  700. goto out_unlock;
  701. }
  702. res = sscanf(buf, "%x %x", &offset, &value);
  703. if (res != 2) {
  704. res = -EFAULT;
  705. goto out_unlock;
  706. }
  707. offval.offset = offset;
  708. offval.value = value;
  709. res = lbs_prepare_and_send_command(priv,
  710. CMD_RF_REG_ACCESS, 1,
  711. CMD_OPTION_WAITFORRSP, 0, &offval);
  712. mdelay(10);
  713. res = count;
  714. out_unlock:
  715. free_page(addr);
  716. return res;
  717. }
  718. #define FOPS(fread, fwrite) { \
  719. .owner = THIS_MODULE, \
  720. .open = open_file_generic, \
  721. .read = (fread), \
  722. .write = (fwrite), \
  723. }
  724. struct lbs_debugfs_files {
  725. char *name;
  726. int perm;
  727. struct file_operations fops;
  728. };
  729. static struct lbs_debugfs_files debugfs_files[] = {
  730. { "info", 0444, FOPS(lbs_dev_info, write_file_dummy), },
  731. { "getscantable", 0444, FOPS(lbs_getscantable,
  732. write_file_dummy), },
  733. { "sleepparams", 0644, FOPS(lbs_sleepparams_read,
  734. lbs_sleepparams_write), },
  735. { "extscan", 0600, FOPS(NULL, lbs_extscan), },
  736. { "setuserscan", 0600, FOPS(NULL, lbs_setuserscan), },
  737. };
  738. static struct lbs_debugfs_files debugfs_events_files[] = {
  739. {"low_rssi", 0644, FOPS(lbs_lowrssi_read,
  740. lbs_lowrssi_write), },
  741. {"low_snr", 0644, FOPS(lbs_lowsnr_read,
  742. lbs_lowsnr_write), },
  743. {"failure_count", 0644, FOPS(lbs_failcount_read,
  744. lbs_failcount_write), },
  745. {"beacon_missed", 0644, FOPS(lbs_bcnmiss_read,
  746. lbs_bcnmiss_write), },
  747. {"high_rssi", 0644, FOPS(lbs_highrssi_read,
  748. lbs_highrssi_write), },
  749. {"high_snr", 0644, FOPS(lbs_highsnr_read,
  750. lbs_highsnr_write), },
  751. };
  752. static struct lbs_debugfs_files debugfs_regs_files[] = {
  753. {"rdmac", 0644, FOPS(lbs_rdmac_read, lbs_rdmac_write), },
  754. {"wrmac", 0600, FOPS(NULL, lbs_wrmac_write), },
  755. {"rdbbp", 0644, FOPS(lbs_rdbbp_read, lbs_rdbbp_write), },
  756. {"wrbbp", 0600, FOPS(NULL, lbs_wrbbp_write), },
  757. {"rdrf", 0644, FOPS(lbs_rdrf_read, lbs_rdrf_write), },
  758. {"wrrf", 0600, FOPS(NULL, lbs_wrrf_write), },
  759. };
  760. void lbs_debugfs_init(void)
  761. {
  762. if (!lbs_dir)
  763. lbs_dir = debugfs_create_dir("lbs_wireless", NULL);
  764. return;
  765. }
  766. void lbs_debugfs_remove(void)
  767. {
  768. if (lbs_dir)
  769. debugfs_remove(lbs_dir);
  770. return;
  771. }
  772. void lbs_debugfs_init_one(struct lbs_private *priv, struct net_device *dev)
  773. {
  774. int i;
  775. struct lbs_debugfs_files *files;
  776. if (!lbs_dir)
  777. goto exit;
  778. priv->debugfs_dir = debugfs_create_dir(dev->name, lbs_dir);
  779. if (!priv->debugfs_dir)
  780. goto exit;
  781. for (i=0; i<ARRAY_SIZE(debugfs_files); i++) {
  782. files = &debugfs_files[i];
  783. priv->debugfs_files[i] = debugfs_create_file(files->name,
  784. files->perm,
  785. priv->debugfs_dir,
  786. priv,
  787. &files->fops);
  788. }
  789. priv->events_dir = debugfs_create_dir("subscribed_events", priv->debugfs_dir);
  790. if (!priv->events_dir)
  791. goto exit;
  792. for (i=0; i<ARRAY_SIZE(debugfs_events_files); i++) {
  793. files = &debugfs_events_files[i];
  794. priv->debugfs_events_files[i] = debugfs_create_file(files->name,
  795. files->perm,
  796. priv->events_dir,
  797. priv,
  798. &files->fops);
  799. }
  800. priv->regs_dir = debugfs_create_dir("registers", priv->debugfs_dir);
  801. if (!priv->regs_dir)
  802. goto exit;
  803. for (i=0; i<ARRAY_SIZE(debugfs_regs_files); i++) {
  804. files = &debugfs_regs_files[i];
  805. priv->debugfs_regs_files[i] = debugfs_create_file(files->name,
  806. files->perm,
  807. priv->regs_dir,
  808. priv,
  809. &files->fops);
  810. }
  811. #ifdef PROC_DEBUG
  812. lbs_debug_init(priv, dev);
  813. #endif
  814. exit:
  815. return;
  816. }
  817. void lbs_debugfs_remove_one(struct lbs_private *priv)
  818. {
  819. int i;
  820. for(i=0; i<ARRAY_SIZE(debugfs_regs_files); i++)
  821. debugfs_remove(priv->debugfs_regs_files[i]);
  822. debugfs_remove(priv->regs_dir);
  823. for(i=0; i<ARRAY_SIZE(debugfs_events_files); i++)
  824. debugfs_remove(priv->debugfs_events_files[i]);
  825. debugfs_remove(priv->events_dir);
  826. #ifdef PROC_DEBUG
  827. debugfs_remove(priv->debugfs_debug);
  828. #endif
  829. for(i=0; i<ARRAY_SIZE(debugfs_files); i++)
  830. debugfs_remove(priv->debugfs_files[i]);
  831. debugfs_remove(priv->debugfs_dir);
  832. }
  833. /* debug entry */
  834. #ifdef PROC_DEBUG
  835. #define item_size(n) (FIELD_SIZEOF(struct lbs_private, n))
  836. #define item_addr(n) (offsetof(struct lbs_private, n))
  837. struct debug_data {
  838. char name[32];
  839. u32 size;
  840. size_t addr;
  841. };
  842. /* To debug any member of struct lbs_private, simply add one line here.
  843. */
  844. static struct debug_data items[] = {
  845. {"intcounter", item_size(intcounter), item_addr(intcounter)},
  846. {"psmode", item_size(psmode), item_addr(psmode)},
  847. {"psstate", item_size(psstate), item_addr(psstate)},
  848. };
  849. static int num_of_items = ARRAY_SIZE(items);
  850. /**
  851. * @brief proc read function
  852. *
  853. * @param page pointer to buffer
  854. * @param s read data starting position
  855. * @param off offset
  856. * @param cnt counter
  857. * @param eof end of file flag
  858. * @param data data to output
  859. * @return number of output data
  860. */
  861. static ssize_t lbs_debugfs_read(struct file *file, char __user *userbuf,
  862. size_t count, loff_t *ppos)
  863. {
  864. int val = 0;
  865. size_t pos = 0;
  866. ssize_t res;
  867. char *p;
  868. int i;
  869. struct debug_data *d;
  870. unsigned long addr = get_zeroed_page(GFP_KERNEL);
  871. char *buf = (char *)addr;
  872. p = buf;
  873. d = (struct debug_data *)file->private_data;
  874. for (i = 0; i < num_of_items; i++) {
  875. if (d[i].size == 1)
  876. val = *((u8 *) d[i].addr);
  877. else if (d[i].size == 2)
  878. val = *((u16 *) d[i].addr);
  879. else if (d[i].size == 4)
  880. val = *((u32 *) d[i].addr);
  881. else if (d[i].size == 8)
  882. val = *((u64 *) d[i].addr);
  883. pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
  884. }
  885. res = simple_read_from_buffer(userbuf, count, ppos, p, pos);
  886. free_page(addr);
  887. return res;
  888. }
  889. /**
  890. * @brief proc write function
  891. *
  892. * @param f file pointer
  893. * @param buf pointer to data buffer
  894. * @param cnt data number to write
  895. * @param data data to write
  896. * @return number of data
  897. */
  898. static ssize_t lbs_debugfs_write(struct file *f, const char __user *buf,
  899. size_t cnt, loff_t *ppos)
  900. {
  901. int r, i;
  902. char *pdata;
  903. char *p;
  904. char *p0;
  905. char *p1;
  906. char *p2;
  907. struct debug_data *d = (struct debug_data *)f->private_data;
  908. pdata = kmalloc(cnt, GFP_KERNEL);
  909. if (pdata == NULL)
  910. return 0;
  911. if (copy_from_user(pdata, buf, cnt)) {
  912. lbs_deb_debugfs("Copy from user failed\n");
  913. kfree(pdata);
  914. return 0;
  915. }
  916. p0 = pdata;
  917. for (i = 0; i < num_of_items; i++) {
  918. do {
  919. p = strstr(p0, d[i].name);
  920. if (p == NULL)
  921. break;
  922. p1 = strchr(p, '\n');
  923. if (p1 == NULL)
  924. break;
  925. p0 = p1++;
  926. p2 = strchr(p, '=');
  927. if (!p2)
  928. break;
  929. p2++;
  930. r = simple_strtoul(p2, NULL, 0);
  931. if (d[i].size == 1)
  932. *((u8 *) d[i].addr) = (u8) r;
  933. else if (d[i].size == 2)
  934. *((u16 *) d[i].addr) = (u16) r;
  935. else if (d[i].size == 4)
  936. *((u32 *) d[i].addr) = (u32) r;
  937. else if (d[i].size == 8)
  938. *((u64 *) d[i].addr) = (u64) r;
  939. break;
  940. } while (1);
  941. }
  942. kfree(pdata);
  943. return (ssize_t)cnt;
  944. }
  945. static struct file_operations lbs_debug_fops = {
  946. .owner = THIS_MODULE,
  947. .open = open_file_generic,
  948. .write = lbs_debugfs_write,
  949. .read = lbs_debugfs_read,
  950. };
  951. /**
  952. * @brief create debug proc file
  953. *
  954. * @param priv pointer struct lbs_private
  955. * @param dev pointer net_device
  956. * @return N/A
  957. */
  958. static void lbs_debug_init(struct lbs_private *priv, struct net_device *dev)
  959. {
  960. int i;
  961. if (!priv->debugfs_dir)
  962. return;
  963. for (i = 0; i < num_of_items; i++)
  964. items[i].addr += (size_t) priv;
  965. priv->debugfs_debug = debugfs_create_file("debug", 0644,
  966. priv->debugfs_dir, &items[0],
  967. &lbs_debug_fops);
  968. }
  969. #endif