debugfs.c 27 KB

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