PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/CUDK/CLI/dbg_module.c

http://github.com/CyanogenMod/cm-kernel
C | 253 lines | 111 code | 49 blank | 93 comment | 14 complexity | a9a41f68a38be2450b288ae68fa40d3b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*******************************************************************************
  2. **+--------------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright 1998-2008 Texas Instruments, Inc. - http://www.ti.com/ |**
  5. **| |**
  6. **| Licensed under the Apache License, Version 2.0 (the "License"); |**
  7. **| you may not use this file except in compliance with the License. |**
  8. **| You may obtain a copy of the License at |**
  9. **| |**
  10. **| http://www.apache.org/licenses/LICENSE-2.0 |**
  11. **| |**
  12. **| Unless required by applicable law or agreed to in writing, software |**
  13. **| distributed under the License is distributed on an "AS IS" BASIS, |**
  14. **| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |**
  15. **| See the License for the specific language governing permissions and |**
  16. **| limitations under the License. |**
  17. **| |**
  18. **+--------------------------------------------------------------------------+**
  19. *******************************************************************************/
  20. /****************************************************************************************************/
  21. /* */
  22. /* MODULE: dbg_module.c */
  23. /* PURPOSE: Handle the debug messages */
  24. /* Note: This module is for LINUX compilation only! */
  25. /* */
  26. /****************************************************************************************************/
  27. #include <stdarg.h>
  28. #include <unistd.h>
  29. #include <stdlib.h>
  30. #include <termios.h>
  31. #include <fcntl.h>
  32. #include <errno.h>
  33. #include <signal.h>
  34. #include <fcntl.h>
  35. #include <stdarg.h>
  36. #include <sys/time.h>
  37. #include <sys/stat.h>
  38. #include <sys/types.h>
  39. #include <sys/ioctl.h>
  40. #include <sys/socket.h>
  41. #include <sys/resource.h>
  42. #include "ipc.h"
  43. #include "ticon.h"
  44. #include "console.h"
  45. #include "dbg_module.h"
  46. #include "eth_utils.h"
  47. #include "debug_module_ioctl.h"
  48. /************/
  49. /* Defines */
  50. /**********/
  51. #define DEBUG_MODULE_BUFFER_SIZE (255)
  52. /*********************/
  53. /* Global variables */
  54. /*******************/
  55. int debug_module_dev_file = -1;
  56. int debug_module_process_pid = 0;
  57. /********************************/
  58. /* static functions prototypes */
  59. /******************************/
  60. unsigned char file_exists(const char *file_name);
  61. /**************/
  62. /* Functions */
  63. /************/
  64. /************************************************************************
  65. * debug_module_init *
  66. ************************************************************************
  67. DESCRIPTION: Initialize the debug module user mode process
  68. CONTEXT : main process only!
  69. ************************************************************************/
  70. void debug_module_init(void)
  71. {
  72. int return_value;
  73. /*********************************/
  74. /* Create the debug device file */
  75. /*******************************/
  76. if (!file_exists("/dev/debug_msg_dev"))
  77. {
  78. /* Create the debug device file */
  79. return_value = system("mknod /dev/debug_msg_dev c 254 0");
  80. }
  81. debug_module_dev_file = open("/dev/debug_msg_dev", O_RDWR);
  82. if (debug_module_dev_file == -1)
  83. {
  84. console_printf_terminal("Debug module, error opening \"/dev/debug_msg_dev\"\n");
  85. return;
  86. }
  87. /* Create another instance of this process */
  88. debug_module_process_pid = fork();
  89. if (debug_module_process_pid == 0)
  90. {
  91. /******************/
  92. /* Child process */
  93. /****************/
  94. unsigned char bytes_read;
  95. unsigned char ioctl_return_size;
  96. t_ioctol1_format ioctl_data;
  97. unsigned char in_debug_buffer[DEBUG_MODULE_BUFFER_SIZE + 1];
  98. /* Set the priority of this process to the lowest */
  99. /* setpriority(PRIO_PROCESS, getpid(), -20);*/
  100. console_printf_terminal("Debug module, Hello from child process (pid = %d).\n", getpid());
  101. /*******************************/
  102. /* Prepare the ioctl's fields */
  103. /*****************************/
  104. ioctl_data.return_size = &ioctl_return_size;
  105. ioctl_data.buffer = (in_debug_buffer + 1);
  106. ioctl_data.buffer_size = DEBUG_MODULE_BUFFER_SIZE;
  107. while (TRUE)
  108. {
  109. /*console_printf_terminal("Debug module, before ioctl\n");*/
  110. /* Read data from device file - blocking command */
  111. return_value = ioctl(debug_module_dev_file, 10, &ioctl_data);
  112. /*console_printf_terminal("Debug module, after ioctl (%d)\n", return_value);*/
  113. if (return_value != -1)
  114. {
  115. bytes_read = ioctl_return_size;
  116. if (bytes_read > 0)
  117. {
  118. /* Mark that this is log message */
  119. in_debug_buffer[0] = 0;
  120. /* Put '0' in the end of the string */
  121. in_debug_buffer[bytes_read + 1] = 0;
  122. console_send_buffer_to_host(ETHERNET_UTILS_LOGGER_MODULE_ID, in_debug_buffer, (bytes_read + 1));
  123. }
  124. }
  125. else
  126. {
  127. console_printf_terminal("Debug module, error reading from device file.\n");
  128. }
  129. }
  130. }
  131. }
  132. /************************************************************************
  133. * debug_module_deinit *
  134. ************************************************************************
  135. DESCRIPTION: Deinitialize the debug module user mode process
  136. CONTEXT : main process only!
  137. ************************************************************************/
  138. void debug_module_deinit(void)
  139. {
  140. if (debug_module_process_pid)
  141. {
  142. kill(debug_module_process_pid, SIGKILL);
  143. }
  144. }
  145. /************************************************************************
  146. * debug_module_get_queue_status *
  147. ************************************************************************
  148. DESCRIPTION: Gets the status of the debug module queue
  149. CONTEXT : main process only!
  150. ************************************************************************/
  151. struct q_report {
  152. unsigned int q_size;
  153. unsigned int q_used;
  154. unsigned int q_overrun;
  155. };
  156. #define QUEUE_STATUS_LEN (12)
  157. void debug_module_get_queue_status(void)
  158. {
  159. int return_value;
  160. char status_result[QUEUE_STATUS_LEN + 1];
  161. struct q_report report;
  162. /* Read data from device file - blocking command */
  163. return_value = ioctl(debug_module_dev_file, 11, &report);
  164. if (return_value != -1)
  165. {
  166. /* console_printf_terminal("Debug module, debug_module_get_queue_status. (size = %d, used = %d, overrun = %d)\n", report.q_size , report.q_used, report.q_overrun); */
  167. memcpy(status_result + 1, &report, sizeof(report));
  168. /* Mark that this is report message */
  169. status_result[0] = 1;
  170. console_send_buffer_to_host(ETHERNET_UTILS_LOGGER_MODULE_ID, (tiUINT8*) status_result, QUEUE_STATUS_LEN + 1);
  171. }
  172. else
  173. {
  174. console_printf_terminal("Debug module, error reading from device file.\n");
  175. }
  176. }
  177. /************************************************************************
  178. * file_exists *
  179. ************************************************************************
  180. DESCRIPTION: Check if a specific file exists
  181. CONTEXT : All process.
  182. Returns: TRUE if the file exists (FALSE otherwise).
  183. ************************************************************************/
  184. unsigned char file_exists(const char *file_name)
  185. {
  186. int test_file;
  187. tiBOOL result = FALSE;;
  188. /* Try to open the file */
  189. test_file = open(file_name, O_RDONLY);
  190. if (test_file != -1)
  191. {
  192. /*************************************************/
  193. /* The file was successfullu opened - it exists */
  194. /***********************************************/
  195. close(test_file);
  196. result = TRUE;
  197. }
  198. return result;
  199. }