moal_proc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /** @file moal_proc.c
  2. *
  3. * @brief This file contains functions for proc file.
  4. *
  5. * Copyright (C) 2008-2014, Marvell International Ltd.
  6. *
  7. * This software file (the "File") is distributed by Marvell International
  8. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  9. * (the "License"). You may use, redistribute and/or modify this File in
  10. * accordance with the terms and conditions of the License, a copy of which
  11. * is available by writing to the Free Software Foundation, Inc.,
  12. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  13. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  14. *
  15. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  18. * this warranty disclaimer.
  19. *
  20. */
  21. /********************************************************
  22. Change log:
  23. 10/21/2008: initial version
  24. ********************************************************/
  25. #include "moal_main.h"
  26. #ifdef UAP_SUPPORT
  27. #include "moal_uap.h"
  28. #endif
  29. #include "moal_sdio.h"
  30. /********************************************************
  31. Local Variables
  32. ********************************************************/
  33. #ifdef CONFIG_PROC_FS
  34. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  35. #define PROC_DIR NULL
  36. #define MWLAN_PROC_DIR "mwlan/"
  37. /** Proc top level directory entry */
  38. struct proc_dir_entry *proc_mwlan;
  39. #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
  40. #define PROC_DIR (&proc_root)
  41. #else
  42. #define PROC_DIR proc_net
  43. #endif
  44. #ifdef STA_SUPPORT
  45. static char *szModes[] = {
  46. "Unknown",
  47. "Managed",
  48. "Ad-hoc",
  49. "Auto",
  50. };
  51. #endif
  52. extern int drv_mode;
  53. /********************************************************
  54. Global Variables
  55. ********************************************************/
  56. /********************************************************
  57. Local Functions
  58. ********************************************************/
  59. /**
  60. * @brief Proc read function for info
  61. *
  62. * @param sfp pointer to seq_file structure
  63. * @param data
  64. *
  65. * @return Number of output data
  66. */
  67. static int
  68. woal_info_proc_read(struct seq_file *sfp, void *data)
  69. {
  70. struct net_device *netdev = (struct net_device *)sfp->private;
  71. char fmt[MLAN_MAX_VER_STR_LEN];
  72. moal_private *priv = (moal_private *) netdev_priv(netdev);
  73. #ifdef STA_SUPPORT
  74. int i = 0;
  75. moal_handle *handle = NULL;
  76. mlan_bss_info info;
  77. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
  78. struct dev_mc_list *mcptr = netdev->mc_list;
  79. int mc_count = netdev->mc_count;
  80. #else
  81. struct netdev_hw_addr *mcptr = NULL;
  82. int mc_count = netdev_mc_count(netdev);
  83. #endif /* < 2.6.35 */
  84. #else
  85. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
  86. int i = 0;
  87. #endif /* >= 2.6.29 */
  88. #endif
  89. #ifdef UAP_SUPPORT
  90. mlan_ds_uap_stats ustats;
  91. #endif
  92. ENTER();
  93. if (priv == NULL)
  94. goto exit;
  95. #ifdef STA_SUPPORT
  96. handle = priv->phandle;
  97. if (handle == NULL)
  98. goto exit;
  99. #endif
  100. if (!MODULE_GET) {
  101. LEAVE();
  102. return 0;
  103. }
  104. memset(fmt, 0, sizeof(fmt));
  105. #ifdef UAP_SUPPORT
  106. if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_UAP) {
  107. seq_printf(sfp, "driver_name = " "\"uap\"\n");
  108. woal_uap_get_version(priv, fmt, sizeof(fmt) - 1);
  109. if (MLAN_STATUS_SUCCESS !=
  110. woal_uap_get_stats(priv, MOAL_PROC_WAIT, &ustats)) {
  111. MODULE_PUT;
  112. LEAVE();
  113. return -EFAULT;
  114. }
  115. }
  116. #endif /* UAP_SUPPORT */
  117. #ifdef STA_SUPPORT
  118. if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_STA) {
  119. woal_get_version(handle, fmt, sizeof(fmt) - 1);
  120. memset(&info, 0, sizeof(info));
  121. if (MLAN_STATUS_SUCCESS !=
  122. woal_get_bss_info(priv, MOAL_PROC_WAIT, &info)) {
  123. MODULE_PUT;
  124. LEAVE();
  125. return -EFAULT;
  126. }
  127. seq_printf(sfp, "driver_name = " "\"wlan\"\n");
  128. }
  129. #endif
  130. seq_printf(sfp, "driver_version = %s", fmt);
  131. seq_printf(sfp, "\ninterface_name=\"%s\"\n", netdev->name);
  132. #if defined(WIFI_DIRECT_SUPPORT)
  133. if (priv->bss_type == MLAN_BSS_TYPE_WIFIDIRECT) {
  134. if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_STA)
  135. seq_printf(sfp, "bss_mode = \"WIFIDIRECT-Client\"\n");
  136. else
  137. seq_printf(sfp, "bss_mode = \"WIFIDIRECT-GO\"\n");
  138. }
  139. #endif
  140. #ifdef STA_SUPPORT
  141. if (priv->bss_type == MLAN_BSS_TYPE_STA)
  142. seq_printf(sfp, "bss_mode =\"%s\"\n", szModes[info.bss_mode]);
  143. #endif
  144. seq_printf(sfp, "media_state=\"%s\"\n",
  145. ((priv->media_connected ==
  146. MFALSE) ? "Disconnected" : "Connected"));
  147. seq_printf(sfp, "mac_address=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n",
  148. netdev->dev_addr[0], netdev->dev_addr[1],
  149. netdev->dev_addr[2], netdev->dev_addr[3],
  150. netdev->dev_addr[4], netdev->dev_addr[5]);
  151. #ifdef STA_SUPPORT
  152. if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_STA) {
  153. seq_printf(sfp, "multicast_count=\"%d\"\n", mc_count);
  154. seq_printf(sfp, "essid=\"%s\"\n", info.ssid.ssid);
  155. seq_printf(sfp, "bssid=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n",
  156. info.bssid[0], info.bssid[1],
  157. info.bssid[2], info.bssid[3],
  158. info.bssid[4], info.bssid[5]);
  159. seq_printf(sfp, "channel=\"%d\"\n", (int)info.bss_chan);
  160. seq_printf(sfp, "region_code = \"%02x\"\n",
  161. (t_u8) info.region_code);
  162. /*
  163. * Put out the multicast list
  164. */
  165. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
  166. for (i = 0; i < netdev->mc_count; i++) {
  167. seq_printf(sfp,
  168. "multicast_address[%d]=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n",
  169. i,
  170. mcptr->dmi_addr[0], mcptr->dmi_addr[1],
  171. mcptr->dmi_addr[2], mcptr->dmi_addr[3],
  172. mcptr->dmi_addr[4], mcptr->dmi_addr[5]);
  173. mcptr = mcptr->next;
  174. }
  175. #else
  176. netdev_for_each_mc_addr(mcptr, netdev)
  177. seq_printf(sfp,
  178. "multicast_address[%d]=\"%02x:%02x:%02x:%02x:%02x:%02x\"\n",
  179. i++,
  180. mcptr->addr[0], mcptr->addr[1],
  181. mcptr->addr[2], mcptr->addr[3],
  182. mcptr->addr[4], mcptr->addr[5]);
  183. #endif /* < 2.6.35 */
  184. }
  185. #endif
  186. seq_printf(sfp, "num_tx_bytes = %lu\n", priv->stats.tx_bytes);
  187. seq_printf(sfp, "num_rx_bytes = %lu\n", priv->stats.rx_bytes);
  188. seq_printf(sfp, "num_tx_pkts = %lu\n", priv->stats.tx_packets);
  189. seq_printf(sfp, "num_rx_pkts = %lu\n", priv->stats.rx_packets);
  190. seq_printf(sfp, "num_tx_pkts_dropped = %lu\n", priv->stats.tx_dropped);
  191. seq_printf(sfp, "num_rx_pkts_dropped = %lu\n", priv->stats.rx_dropped);
  192. seq_printf(sfp, "num_tx_pkts_err = %lu\n", priv->stats.tx_errors);
  193. seq_printf(sfp, "num_rx_pkts_err = %lu\n", priv->stats.rx_errors);
  194. seq_printf(sfp, "carrier %s\n",
  195. ((netif_carrier_ok(priv->netdev)) ? "on" : "off"));
  196. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
  197. for (i = 0; i < netdev->num_tx_queues; i++) {
  198. seq_printf(sfp, "tx queue %d: %s\n", i,
  199. ((netif_tx_queue_stopped
  200. (netdev_get_tx_queue(netdev, 0))) ? "stopped" :
  201. "started"));
  202. }
  203. #else
  204. seq_printf(sfp, "tx queue %s\n",
  205. ((netif_queue_stopped(priv->netdev)) ? "stopped" :
  206. "started"));
  207. #endif
  208. #ifdef UAP_SUPPORT
  209. if (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_UAP) {
  210. seq_printf(sfp, "tkip_mic_failures = %u\n",
  211. ustats.tkip_mic_failures);
  212. seq_printf(sfp, "ccmp_decrypt_errors = %u\n",
  213. ustats.ccmp_decrypt_errors);
  214. seq_printf(sfp, "wep_undecryptable_count = %u\n",
  215. ustats.wep_undecryptable_count);
  216. seq_printf(sfp, "wep_icv_error_count = %u\n",
  217. ustats.wep_icv_error_count);
  218. seq_printf(sfp, "decrypt_failure_count = %u\n",
  219. ustats.decrypt_failure_count);
  220. seq_printf(sfp, "mcast_tx_count = %u\n", ustats.mcast_tx_count);
  221. seq_printf(sfp, "failed_count = %u\n", ustats.failed_count);
  222. seq_printf(sfp, "retry_count = %u\n", ustats.retry_count);
  223. seq_printf(sfp, "multiple_retry_count = %u\n",
  224. ustats.multi_retry_count);
  225. seq_printf(sfp, "frame_duplicate_count = %u\n",
  226. ustats.frame_dup_count);
  227. seq_printf(sfp, "rts_success_count = %u\n",
  228. ustats.rts_success_count);
  229. seq_printf(sfp, "rts_failure_count = %u\n",
  230. ustats.rts_failure_count);
  231. seq_printf(sfp, "ack_failure_count = %u\n",
  232. ustats.ack_failure_count);
  233. seq_printf(sfp, "rx_fragment_count = %u\n",
  234. ustats.rx_fragment_count);
  235. seq_printf(sfp, "mcast_rx_frame_count = %u\n",
  236. ustats.mcast_rx_frame_count);
  237. seq_printf(sfp, "fcs_error_count = %u\n",
  238. ustats.fcs_error_count);
  239. seq_printf(sfp, "tx_frame_count = %u\n", ustats.tx_frame_count);
  240. seq_printf(sfp, "rsna_tkip_cm_invoked = %u\n",
  241. ustats.rsna_tkip_cm_invoked);
  242. seq_printf(sfp, "rsna_4way_hshk_failures = %u\n",
  243. ustats.rsna_4way_hshk_failures);
  244. }
  245. #endif /* UAP_SUPPORT */
  246. exit:
  247. LEAVE();
  248. MODULE_PUT;
  249. return 0;
  250. }
  251. static int
  252. woal_info_proc_open(struct inode *inode, struct file *file)
  253. {
  254. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
  255. return single_open(file, woal_info_proc_read, PDE_DATA(inode));
  256. #else
  257. return single_open(file, woal_info_proc_read, PDE(inode)->data);
  258. #endif
  259. }
  260. static const struct file_operations info_proc_fops = {
  261. .owner = THIS_MODULE,
  262. .open = woal_info_proc_open,
  263. .read = seq_read,
  264. .llseek = seq_lseek,
  265. .release = single_release,
  266. };
  267. #define CMD52_STR_LEN 50
  268. /*
  269. * @brief Parse cmd52 string
  270. *
  271. * @param buffer A pointer user buffer
  272. * @param len Length user buffer
  273. * @param func Parsed func number
  274. * @param reg Parsed reg value
  275. * @param val Parsed value to set
  276. * @return BT_STATUS_SUCCESS
  277. */
  278. static int
  279. parse_cmd52_string(const char *buffer, size_t len, int *func, int *reg,
  280. int *val)
  281. {
  282. int ret = MLAN_STATUS_SUCCESS;
  283. char *string = NULL;
  284. char *pos = NULL;
  285. gfp_t flag;
  286. ENTER();
  287. flag = (in_atomic() || irqs_disabled())? GFP_ATOMIC : GFP_KERNEL;
  288. string = kzalloc(CMD52_STR_LEN, flag);
  289. if (string == NULL)
  290. return -ENOMEM;
  291. memcpy(string, buffer + strlen("sdcmd52rw="),
  292. MIN((CMD52_STR_LEN - 1), (len - strlen("sdcmd52rw="))));
  293. string = strstrip(string);
  294. *func = -1;
  295. *reg = -1;
  296. *val = -1;
  297. /* Get func */
  298. pos = strsep(&string, " \t");
  299. if (pos)
  300. *func = woal_string_to_number(pos);
  301. /* Get reg */
  302. pos = strsep(&string, " \t");
  303. if (pos)
  304. *reg = woal_string_to_number(pos);
  305. /* Get val (optional) */
  306. pos = strsep(&string, " \t");
  307. if (pos)
  308. *val = woal_string_to_number(pos);
  309. kfree(string);
  310. LEAVE();
  311. return ret;
  312. }
  313. /**
  314. * @brief config proc write function
  315. *
  316. * @param f file pointer
  317. * @param buf pointer to data buffer
  318. * @param count data number to write
  319. * @param off Offset
  320. *
  321. * @return number of data
  322. */
  323. static ssize_t
  324. woal_config_write(struct file *f, const char __user * buf, size_t count,
  325. loff_t * off)
  326. {
  327. char databuf[101];
  328. char *line = NULL;
  329. t_u32 config_data = 0;
  330. struct seq_file *sfp = f->private_data;
  331. moal_handle *handle = (moal_handle *) sfp->private;
  332. int func = 0, reg = 0, val = 0;
  333. int copy_len;
  334. moal_private *priv = NULL;
  335. ENTER();
  336. if (!MODULE_GET) {
  337. LEAVE();
  338. return 0;
  339. }
  340. if (count >= sizeof(databuf)) {
  341. MODULE_PUT;
  342. LEAVE();
  343. return (int)count;
  344. }
  345. memset(databuf, 0, sizeof(databuf));
  346. copy_len = MIN((sizeof(databuf) - 1), count);
  347. if (copy_from_user(databuf, buf, copy_len)) {
  348. MODULE_PUT;
  349. LEAVE();
  350. return 0;
  351. }
  352. line = databuf;
  353. if (!strncmp(databuf, "soft_reset", strlen("soft_reset"))) {
  354. line += strlen("soft_reset") + 1;
  355. config_data = (t_u32) woal_string_to_number(line);
  356. PRINTM(MINFO, "soft_reset: %d\n", (int)config_data);
  357. if (woal_request_soft_reset(handle) == MLAN_STATUS_SUCCESS)
  358. handle->hardware_status = HardwareStatusReset;
  359. else
  360. PRINTM(MERROR, "Could not perform soft reset\n");
  361. }
  362. if (!strncmp(databuf, "drv_mode", strlen("drv_mode"))) {
  363. line += strlen("drv_mode") + 1;
  364. config_data = (t_u32) woal_string_to_number(line);
  365. PRINTM(MINFO, "drv_mode: %d\n", (int)config_data);
  366. if (config_data != (t_u32) drv_mode)
  367. if (woal_switch_drv_mode(handle, config_data) !=
  368. MLAN_STATUS_SUCCESS) {
  369. PRINTM(MERROR, "Could not switch drv mode\n");
  370. }
  371. }
  372. if (!strncmp(databuf, "sdcmd52rw=", strlen("sdcmd52rw=")) &&
  373. count > strlen("sdcmd52rw=")) {
  374. parse_cmd52_string((const char *)databuf, (size_t) count, &func,
  375. &reg, &val);
  376. woal_sdio_read_write_cmd52(handle, func, reg, val);
  377. }
  378. if (!strncmp(databuf, "debug_dump", strlen("debug_dump"))) {
  379. priv = woal_get_priv(handle, MLAN_BSS_ROLE_ANY);
  380. if (priv) {
  381. PRINTM(MERROR, "Recevie debug_dump command\n");
  382. drvdbg &= ~MFW_D;
  383. woal_mlan_debug_info(priv);
  384. woal_moal_debug_info(priv, NULL, MFALSE);
  385. woal_dump_firmware_info(handle);
  386. }
  387. }
  388. MODULE_PUT;
  389. LEAVE();
  390. return (int)count;
  391. }
  392. /**
  393. * @brief config proc read function
  394. *
  395. * @param sfp pointer to seq_file structure
  396. * @param data
  397. *
  398. * @return number of output data
  399. */
  400. static int
  401. woal_config_read(struct seq_file *sfp, void *data)
  402. {
  403. moal_handle *handle = (moal_handle *) sfp->private;
  404. ENTER();
  405. if (!MODULE_GET) {
  406. LEAVE();
  407. return 0;
  408. }
  409. seq_printf(sfp, "hardware_status=%d\n", (int)handle->hardware_status);
  410. seq_printf(sfp, "netlink_num=%d\n", (int)handle->netlink_num);
  411. seq_printf(sfp, "drv_mode=%d\n", (int)drv_mode);
  412. seq_printf(sfp, "sdcmd52rw=%d 0x%0x 0x%02X\n", handle->cmd52_func,
  413. handle->cmd52_reg, handle->cmd52_val);
  414. MODULE_PUT;
  415. LEAVE();
  416. return 0;
  417. }
  418. static int
  419. woal_config_proc_open(struct inode *inode, struct file *file)
  420. {
  421. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
  422. return single_open(file, woal_config_read, PDE_DATA(inode));
  423. #else
  424. return single_open(file, woal_config_read, PDE(inode)->data);
  425. #endif
  426. }
  427. static const struct file_operations config_proc_fops = {
  428. .owner = THIS_MODULE,
  429. .open = woal_config_proc_open,
  430. .read = seq_read,
  431. .llseek = seq_lseek,
  432. .release = single_release,
  433. .write = woal_config_write,
  434. };
  435. /********************************************************
  436. Global Functions
  437. ********************************************************/
  438. /**
  439. * @brief Convert string to number
  440. *
  441. * @param s Pointer to numbered string
  442. *
  443. * @return Converted number from string s
  444. */
  445. int
  446. woal_string_to_number(char *s)
  447. {
  448. int r = 0;
  449. int base = 0;
  450. int pn = 1;
  451. if (!strncmp(s, "-", 1)) {
  452. pn = -1;
  453. s++;
  454. }
  455. if (!strncmp(s, "0x", 2) || !strncmp(s, "0X", 2)) {
  456. base = 16;
  457. s += 2;
  458. } else
  459. base = 10;
  460. for (s = s; *s; s++) {
  461. if ((*s >= '0') && (*s <= '9'))
  462. r = (r * base) + (*s - '0');
  463. else if ((*s >= 'A') && (*s <= 'F'))
  464. r = (r * base) + (*s - 'A' + 10);
  465. else if ((*s >= 'a') && (*s <= 'f'))
  466. r = (r * base) + (*s - 'a' + 10);
  467. else
  468. break;
  469. }
  470. return r * pn;
  471. }
  472. /**
  473. * @brief Create the top level proc directory
  474. *
  475. * @param handle Pointer to woal_handle
  476. *
  477. * @return N/A
  478. */
  479. void
  480. woal_proc_init(moal_handle * handle)
  481. {
  482. struct proc_dir_entry *r;
  483. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
  484. struct proc_dir_entry *pde = PROC_DIR;
  485. #endif
  486. char config_proc_dir[20];
  487. ENTER();
  488. PRINTM(MINFO, "Create Proc Interface\n");
  489. if (!handle->proc_mwlan) {
  490. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
  491. /* Check if directory already exists */
  492. for (pde = pde->subdir; pde; pde = pde->next) {
  493. if (pde->namelen && !strcmp("mwlan", pde->name)) {
  494. /* Directory exists */
  495. PRINTM(MWARN,
  496. "proc interface already exists!\n");
  497. handle->proc_mwlan = pde;
  498. break;
  499. }
  500. }
  501. if (pde == NULL) {
  502. handle->proc_mwlan = proc_mkdir("mwlan", PROC_DIR);
  503. if (!handle->proc_mwlan)
  504. PRINTM(MERROR,
  505. "Cannot create proc interface!\n");
  506. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
  507. else
  508. atomic_set(&handle->proc_mwlan->count, 1);
  509. #endif
  510. }
  511. #else
  512. if (!proc_mwlan) {
  513. handle->proc_mwlan = proc_mkdir("mwlan", PROC_DIR);
  514. if (!handle->proc_mwlan) {
  515. PRINTM(MERROR,
  516. "Cannot create proc interface!\n");
  517. }
  518. } else {
  519. handle->proc_mwlan = proc_mwlan;
  520. }
  521. #endif
  522. if (handle->proc_mwlan) {
  523. if (handle->handle_idx)
  524. sprintf(config_proc_dir, "config%d",
  525. handle->handle_idx);
  526. else
  527. strcpy(config_proc_dir, "config");
  528. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  529. r = proc_create_data(config_proc_dir, 0644,
  530. handle->proc_mwlan,
  531. &config_proc_fops, handle);
  532. if (r == NULL)
  533. #else
  534. r = create_proc_entry(config_proc_dir, 0644,
  535. handle->proc_mwlan);
  536. if (r) {
  537. r->data = handle;
  538. r->proc_fops = &config_proc_fops;
  539. } else
  540. #endif
  541. PRINTM(MMSG, "Fail to create proc config\n");
  542. }
  543. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 26)
  544. proc_mwlan = handle->proc_mwlan;
  545. #endif
  546. }
  547. LEAVE();
  548. }
  549. /**
  550. * @brief Remove the top level proc directory
  551. *
  552. * @param handle pointer moal_handle
  553. *
  554. * @return N/A
  555. */
  556. void
  557. woal_proc_exit(moal_handle * handle)
  558. {
  559. ENTER();
  560. PRINTM(MINFO, "Remove Proc Interface\n");
  561. if (handle->proc_mwlan) {
  562. char config_proc_dir[20];
  563. if (handle->handle_idx)
  564. sprintf(config_proc_dir, "config%d",
  565. handle->handle_idx);
  566. else
  567. strcpy(config_proc_dir, "config");
  568. remove_proc_entry(config_proc_dir, handle->proc_mwlan);
  569. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  570. /* Remove only if we are the only instance using this */
  571. if (atomic_read(&(handle->proc_mwlan->count)) > 1) {
  572. PRINTM(MWARN, "More than one interface using proc!\n");
  573. } else {
  574. #endif
  575. #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
  576. atomic_dec(&(handle->proc_mwlan->count));
  577. #endif
  578. remove_proc_entry("mwlan", PROC_DIR);
  579. handle->proc_mwlan = NULL;
  580. #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 26)
  581. proc_mwlan = NULL;
  582. #endif
  583. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  584. }
  585. #endif
  586. }
  587. LEAVE();
  588. }
  589. /**
  590. * @brief Create proc file for interface
  591. *
  592. * @param priv pointer moal_private
  593. *
  594. * @return N/A
  595. */
  596. void
  597. woal_create_proc_entry(moal_private * priv)
  598. {
  599. struct proc_dir_entry *r;
  600. struct net_device *dev = priv->netdev;
  601. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  602. char proc_dir_name[20];
  603. #endif
  604. ENTER();
  605. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  606. if (!priv->proc_entry) {
  607. memset(proc_dir_name, 0, sizeof(proc_dir_name));
  608. strcpy(proc_dir_name, MWLAN_PROC_DIR);
  609. strcat(proc_dir_name, dev->name);
  610. /* Try to create mwlan/mlanX first */
  611. priv->proc_entry = proc_mkdir(proc_dir_name, PROC_DIR);
  612. if (priv->proc_entry) {
  613. /* Success. Continue normally */
  614. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  615. if (!priv->phandle->proc_mwlan) {
  616. priv->phandle->proc_mwlan =
  617. priv->proc_entry->parent;
  618. }
  619. atomic_inc(&(priv->phandle->proc_mwlan->count));
  620. #endif
  621. } else {
  622. /* Failure. mwlan may not exist. Try to create that
  623. first */
  624. priv->phandle->proc_mwlan =
  625. proc_mkdir("mwlan", PROC_DIR);
  626. if (!priv->phandle->proc_mwlan) {
  627. /* Failure. Something broken */
  628. LEAVE();
  629. return;
  630. } else {
  631. /* Success. Now retry creating mlanX */
  632. priv->proc_entry =
  633. proc_mkdir(proc_dir_name, PROC_DIR);
  634. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  635. atomic_inc(&(priv->phandle->proc_mwlan->count));
  636. #endif
  637. }
  638. }
  639. #else
  640. if (priv->phandle->proc_mwlan && !priv->proc_entry) {
  641. priv->proc_entry =
  642. proc_mkdir(dev->name, priv->phandle->proc_mwlan);
  643. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  644. atomic_inc(&(priv->phandle->proc_mwlan->count));
  645. #endif /* < 3.10.0 */
  646. #endif /* < 2.6.26 */
  647. strcpy(priv->proc_entry_name, dev->name);
  648. if (priv->proc_entry) {
  649. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
  650. r = proc_create_data("info", 0, priv->proc_entry,
  651. &info_proc_fops, dev);
  652. if (r == NULL)
  653. #else
  654. r = create_proc_entry("info", 0, priv->proc_entry);
  655. if (r) {
  656. r->data = dev;
  657. r->proc_fops = &info_proc_fops;
  658. } else
  659. #endif
  660. PRINTM(MMSG, "Fail to create proc info\n");
  661. }
  662. }
  663. LEAVE();
  664. }
  665. /**
  666. * @brief Remove proc file
  667. *
  668. * @param priv Pointer moal_private
  669. *
  670. * @return N/A
  671. */
  672. void
  673. woal_proc_remove(moal_private * priv)
  674. {
  675. ENTER();
  676. if (priv->phandle->proc_mwlan && priv->proc_entry) {
  677. remove_proc_entry("info", priv->proc_entry);
  678. remove_proc_entry(priv->proc_entry_name,
  679. priv->phandle->proc_mwlan);
  680. #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
  681. atomic_dec(&(priv->phandle->proc_mwlan->count));
  682. #endif
  683. priv->proc_entry = NULL;
  684. }
  685. LEAVE();
  686. }
  687. #endif