PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/CyanogenMod/cm-kernel
C | 901 lines | 490 code | 174 blank | 237 comment | 69 complexity | 6141709eb936648f8af17bcbc476d2aa 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: wipp_ctrl.c */
  23. /* PURPOSE: WIPP Control utilities */
  24. /* Note: This module is for LINUX compilation only! */
  25. /* */
  26. /****************************************************************************************************/
  27. #include <errno.h>
  28. #include <unistd.h>
  29. #include <signal.h>
  30. #include <stdarg.h>
  31. #include <stdlib.h>
  32. #include <termios.h>
  33. #include <dirent.h>
  34. #include <sys/wait.h>
  35. #include <sys/time.h>
  36. #include <sys/resource.h>
  37. #include "ipc.h"
  38. #include "ticon.h"
  39. #include "cu_cmd.h"
  40. #include "console.h"
  41. #include "eth_utils.h"
  42. #include "wipp_ctrl.h"
  43. #include "dbg_module.h"
  44. #include "TI_AdapterApiC.h"
  45. /************/
  46. /* Defines */
  47. /**********/
  48. #define WIPP_HEADER(_buffer, _op) ({_buffer[0] = '+'; _buffer[1] = _op;})
  49. #define WIPP_CONTROL_HEADER_SIZE (2)
  50. #define TEMP_BUFFER_SIZE (256)
  51. #define MAX_PROCESS_TABLE_INDEX (50)
  52. /*********************/
  53. /* Global variables */
  54. /*******************/
  55. int wipp_control_general_process_pid = 0;
  56. int wipp_control_general_process_out_pipe[2];
  57. int wipp_control_general_process_in_pipe[2];
  58. int process_table_current_index = 0;
  59. int process_table[MAX_PROCESS_TABLE_INDEX][2];
  60. /********************************/
  61. /* static functions prototypes */
  62. /******************************/
  63. void wipp_control_initialize_general_process(void);
  64. int wipp_control_send_message(unsigned char *buffer, unsigned int length);
  65. void wipp_control_cpu_usage(ConParm_t parm[], U16 nParms);
  66. void wipp_control_mem_usage(ConParm_t parm[], U16 nParms);
  67. void wipp_control_report_version(ConParm_t parm[], U16 nParms);
  68. void wipp_control_set_pp_mode(ConParm_t parm[], U16 nParms);
  69. void wipp_control_disable_term_echo(void);
  70. void wipp_control_set_baud_rate(int rate_index);
  71. void wipp_control_active_iperf(char *iperf_cmd_line);
  72. void wipp_control_deactive_iperf(void);
  73. void wipp_control_kill_family_process(int father_pid);
  74. void wipp_control_fill_process_table(void);
  75. void wipp_control_get_version(void);
  76. /**************/
  77. /* Functions */
  78. /************/
  79. /************************************************************************
  80. * wipp_control_init *
  81. ************************************************************************
  82. DESCRIPTION: Initialize the wipp control module.
  83. The iperf control process is prepared during this stage.
  84. CONTEXT : main process only!
  85. ************************************************************************/
  86. void wipp_control_init(void)
  87. {
  88. wipp_control_initialize_general_process();
  89. }
  90. /************************************************************************
  91. * wipp_control_deinit *
  92. ************************************************************************
  93. DESCRIPTION: Deinitialize the wipp control module.
  94. Kill all the process involved
  95. ************************************************************************/
  96. void wipp_control_deinit(void)
  97. {
  98. /* Kill the general process process */
  99. if (wipp_control_general_process_pid > 0)
  100. {
  101. /* Update the process list */
  102. wipp_control_fill_process_table();
  103. /* Kill all the child's of the general process */
  104. wipp_control_kill_family_process(wipp_control_general_process_pid);
  105. wipp_control_general_process_pid = 0;
  106. }
  107. }
  108. /************************************************************************
  109. * wipp_control_initialize_general_process *
  110. ************************************************************************
  111. DESCRIPTION:
  112. ************************************************************************/
  113. void wipp_control_initialize_general_process()
  114. {
  115. /***********************************/
  116. /* Initialize the general process */
  117. /*********************************/
  118. SHARED_MEMORY_RUN_PROCESS_RUNNING() = FALSE;
  119. if (pipe(wipp_control_general_process_out_pipe) < 0)
  120. {
  121. console_printf_terminal("wipp_control, wipp_control_initialize_general_process - Error creating out pipe!\n");
  122. return;
  123. }
  124. if (pipe(wipp_control_general_process_in_pipe) < 0)
  125. {
  126. console_printf_terminal("wipp_control, wipp_control_initialize_general_process - Error creating in pipe!\n");
  127. return;
  128. }
  129. /* Create a child process */
  130. wipp_control_general_process_pid = fork();
  131. if (0 == wipp_control_general_process_pid)
  132. {
  133. /******************/
  134. /* Child process */
  135. /****************/
  136. int result;
  137. char in_buffer[512];
  138. char command_buffer[4] = {0x0, 0x00, 0x00, WIPP_CONTROL_FROM_GENERAL_PROCESS_SEND_TERMINATE};
  139. /* Close the read direction of the pipe - because i only write information from this pipe. */
  140. close(wipp_control_general_process_out_pipe[0]);
  141. /* Close the write direction of the pipe - because i only write information from this pipe. */
  142. close(wipp_control_general_process_in_pipe[1]);
  143. console_printf_terminal("wipp_control, Hello from general process child module (pid = %d).\n", getpid());
  144. /* Redirect the output to the control pipe */
  145. result = dup2(wipp_control_general_process_out_pipe[1], 1);
  146. if (result == 1)
  147. {
  148. /* The duplication is ok! - we can start working */
  149. while (TRUE)
  150. {
  151. result = read(wipp_control_general_process_in_pipe[0], in_buffer, sizeof(in_buffer));
  152. in_buffer[result] = 0;
  153. /* Mark that the process is running */
  154. SHARED_MEMORY_RUN_PROCESS_RUNNING() = TRUE;
  155. /* Run the command line */
  156. result = system(in_buffer);
  157. /* Save the running result */
  158. SHARED_MEMORY_RUN_PROCESS_RESULT() = result;
  159. /* Mark that the process is not running */
  160. SHARED_MEMORY_RUN_PROCESS_RUNNING() = FALSE;
  161. /* Send indication to the main process that the general process is terminated */
  162. ipc_send_command_to_main_process(GENERAL_PROCESS_MODULE_ID,(unsigned char*) command_buffer, 4);
  163. }
  164. }
  165. else
  166. {
  167. /* Terminate the process ... */
  168. exit(0);
  169. }
  170. }
  171. else
  172. {
  173. /* Close the write direction of the pipe - because i only write information from this pipe. */
  174. close(wipp_control_general_process_out_pipe[1]);
  175. /* Close the read direction of the pipe - because i only write information from this pipe. */
  176. close(wipp_control_general_process_in_pipe[0]);
  177. }
  178. }
  179. /************************************************************************
  180. * wipp_control_send_message *
  181. ************************************************************************
  182. DESCRIPTION: Sends a text message to host
  183. NOTE: Maximum length is 'WIPP_CONTROL_MESSAGE_MAX_LENGTH' bytes!
  184. CONTEXT: Main process only!
  185. ************************************************************************/
  186. #define WIPP_CONTROL_MESSAGE_MAX_LENGTH (512)
  187. int wipp_control_send_message(unsigned char *buffer, unsigned int length)
  188. {
  189. /*************************/
  190. /* send message to host */
  191. /***********************/
  192. return console_send_buffer_to_host(ETHERNET_UTILS_WIPP_MODULE_ID, buffer, length);
  193. }
  194. /************************************************************************
  195. * wipp_control_check_command *
  196. ************************************************************************
  197. DESCRIPTION: Handle the wipp control specific commands
  198. CONTEXT : main process only!
  199. ************************************************************************/
  200. unsigned char wipp_control_check_command(char *input_string)
  201. {
  202. ConParm_t param;
  203. int result;
  204. unsigned char return_value = FALSE;
  205. if (input_string[0] == '!')
  206. {
  207. switch (input_string[1])
  208. {
  209. case WIPP_CONTROL_FROM_GENERAL_PROCESS_SEND_TERMINATE:
  210. wipp_control_send_iperf_results_to_host(WIPP_CONTROL_EVT_RUN_PROCESS_TERMINATE, NULL, 0);
  211. break;
  212. case WIPP_CONTROL_FROM_GENERAL_PROCESS_DEACTIVATE_IPERF:
  213. wipp_control_deactive_iperf();
  214. break;
  215. }
  216. return_value = TRUE;
  217. }
  218. if (input_string[0] == '+')
  219. {
  220. switch (input_string[1])
  221. {
  222. case WIPP_CONTROL_CMD_CPU_USAGE:
  223. wipp_control_cpu_usage((ConParm_t *)NULL, (UINT)NULL);
  224. break;
  225. case WIPP_CONTROL_CMD_MEM_USAGE:
  226. wipp_control_mem_usage((ConParm_t *)NULL, (UINT)NULL);
  227. break;
  228. case WIPP_CONTROL_CMD_REPORT_VERSION:
  229. wipp_control_report_version((ConParm_t *)NULL, (UINT)NULL);
  230. break;
  231. case WIPP_CONTROL_CMD_DEBUG_CONTROL:
  232. param.value = input_string[3] - '0';
  233. switch (input_string[2])
  234. {
  235. case '0':
  236. /****************************/
  237. /* Enable the debug module */
  238. /**************************/
  239. console_printf_terminal("WIPP Control, Enable debug kernal module.\n");
  240. result = system("echo b > /dev/debug_msg_dev");
  241. if (result == -1)
  242. {
  243. console_printf_terminal("Error enabling debug module");
  244. }
  245. break;
  246. case '1':
  247. /*****************************/
  248. /* Disable the debug module */
  249. /***************************/
  250. console_printf_terminal("WIPP Control, Disable debug kernel module.\n");
  251. result = system("echo c > /dev/debug_msg_dev");
  252. if (result == -1)
  253. {
  254. console_printf_terminal("Error disabling debug module");
  255. }
  256. break;
  257. #ifdef TI_DBG
  258. case '2':
  259. /***********************/
  260. /* Select debug level */
  261. /*********************/
  262. param.value = (U32)&input_string[3];
  263. /*console_printf_terminal("WIPP Control, Set debug mask (%s).\n", (char *)param.value);*/
  264. cmd_report_severity_table(&param, 1);
  265. break;
  266. case '3':
  267. /*********************/
  268. /* Add module debug */
  269. /*******************/
  270. cmd_report_add(&param, 1);
  271. break;
  272. case '4':
  273. /***********************/
  274. /* Clear module debug */
  275. /*********************/
  276. cmd_report_clear(&param, 1);
  277. break;
  278. case '5':
  279. /*********************/
  280. /* Set module debug */
  281. /*******************/
  282. param.value = (U32)&input_string[3];
  283. /*console_printf_terminal("WIPP Control, Set module mask (%s).\n", param.value);*/
  284. cmd_report_set(&param, 1);
  285. break;
  286. #endif /* TI_DBG */
  287. case '6':
  288. /***************************************/
  289. /* Get debug module buffer statistics */
  290. /*************************************/
  291. debug_module_get_queue_status();
  292. break;
  293. case '7':
  294. /* Translate the value from range of '0-4' to range of '-20 - 20' */
  295. param.value <<= 3;
  296. param.value -= 20;
  297. console_printf_terminal("WIPP Control, Set debug module priority (%d).\n", param.value);
  298. errno = 0;
  299. /* Change the debug process priority */
  300. /* if (setpriority(PRIO_PROCESS, debug_module_process_pid, param.value) != 0)*/
  301. /* {*/
  302. /* console_printf_terminal("WIPP Control, Error changing priority!\n");*/
  303. /* }*/
  304. break;
  305. default:
  306. console_printf_terminal("++ command error (debug switch)!\n");
  307. break;
  308. }
  309. break;
  310. case WIPP_CONTROL_CMD_DEBUG_PATH:
  311. param.value = input_string[2] - '0';
  312. console_printf_terminal("WIPP Control, Activate debug API (%d).\n", param.value);
  313. wipp_control_set_pp_mode(&param, 1);
  314. break;
  315. case WIPP_CONTROL_CMD_ACTIVATE_PROCESS:
  316. wipp_control_active_iperf((char *)&input_string[1]);
  317. break;
  318. case WIPP_CONTROL_CMD_TERMINATE_PROCESS:
  319. wipp_control_deactive_iperf();
  320. break;
  321. case WIPP_CONTROL_CMD_GET_VERSIONS:
  322. wipp_control_get_version();
  323. break;
  324. default:
  325. console_printf_terminal("wipp control ++ command error!\n");
  326. break;
  327. }
  328. return_value = TRUE;
  329. }
  330. return return_value;
  331. }
  332. /************************************************************************
  333. * wipp_control_cpu_usage *
  334. ************************************************************************
  335. DESCRIPTION: Report to the host the current CPU usage
  336. ************************************************************************/
  337. #define MAX_CPU_INFO_LINE_LEN (50)
  338. void wipp_control_cpu_usage(ConParm_t parm[], U16 nParms)
  339. {
  340. FILE *stat_file;
  341. char cpu_stat_line[MAX_CPU_INFO_LINE_LEN];
  342. stat_file = fopen("/proc/stat", "r");
  343. if (stat_file != NULL)
  344. {
  345. if (fgets((cpu_stat_line + WIPP_CONTROL_HEADER_SIZE), MAX_CPU_INFO_LINE_LEN, stat_file) != NULL)
  346. {
  347. WIPP_HEADER(cpu_stat_line, '1');
  348. wipp_control_send_message((unsigned char*)cpu_stat_line, strlen(cpu_stat_line));
  349. }
  350. else
  351. {
  352. cpu_stat_line[WIPP_CONTROL_HEADER_SIZE] = 0;
  353. wipp_control_send_message((unsigned char*)cpu_stat_line, 3);
  354. }
  355. /**********************************************/
  356. /* Output the message to the standard output */
  357. /********************************************/
  358. fclose(stat_file);
  359. }
  360. else
  361. {
  362. cpu_stat_line[WIPP_CONTROL_HEADER_SIZE] = 0;
  363. wipp_control_send_message((unsigned char*)cpu_stat_line, 3);
  364. }
  365. }
  366. /************************************************************************
  367. * wipp_control_report_version *
  368. ************************************************************************
  369. DESCRIPTION: Report to the host the current Memory usage
  370. ************************************************************************/
  371. #define MAX_MEM_INFO_LINE_LEN (250)
  372. void wipp_control_mem_usage(ConParm_t parm[], U16 nParms)
  373. {
  374. FILE *ver_file;
  375. char mem_stat_line[MAX_MEM_INFO_LINE_LEN];
  376. /* Proceed only in 'pp' mode */
  377. ver_file = fopen("/proc/meminfo", "r");
  378. if (ver_file != NULL)
  379. {
  380. while (fgets((mem_stat_line + WIPP_CONTROL_HEADER_SIZE), MAX_MEM_INFO_LINE_LEN, ver_file) != NULL)
  381. {
  382. WIPP_HEADER(mem_stat_line, '2');
  383. mem_stat_line[WIPP_CONTROL_HEADER_SIZE] = 0;
  384. wipp_control_send_message((unsigned char*)mem_stat_line, strlen(mem_stat_line));
  385. }
  386. fclose(ver_file);
  387. }
  388. }
  389. /************************************************************************
  390. * wipp_control_set_pp_mode *
  391. ************************************************************************
  392. DESCRIPTION: Set the driver to work with debug_module
  393. ************************************************************************/
  394. void wipp_control_set_pp_mode(ConParm_t parm[], U16 nParms)
  395. {
  396. #ifdef TI_DBG
  397. TI_SetReportPPMode(g_id_adapter, parm[0].value);
  398. #endif
  399. }
  400. /************************************************************************
  401. * wipp_control_mem_usage *
  402. ************************************************************************
  403. DESCRIPTION: Report to the host the current Memory usage
  404. ************************************************************************/
  405. #define MAX_VER_INFO_LINE_LEN (250)
  406. void wipp_control_report_version(ConParm_t parm[], U16 nParms)
  407. {
  408. FILE *ver_file;
  409. char ver_line[MAX_VER_INFO_LINE_LEN];
  410. ver_file = fopen("/proc/version", "r");
  411. if (ver_file != NULL)
  412. {
  413. if (fgets((ver_line + WIPP_CONTROL_HEADER_SIZE), MAX_VER_INFO_LINE_LEN, ver_file) != NULL)
  414. {
  415. WIPP_HEADER(ver_line, '3');
  416. ver_line[125] = 0;
  417. wipp_control_send_message((unsigned char*)ver_line, strlen(ver_line));
  418. }
  419. fclose(ver_file);
  420. }
  421. else
  422. {
  423. /* Write the protocol prefix - mark error ('0' in len) */
  424. WIPP_HEADER(ver_line, '3');
  425. ver_line[WIPP_CONTROL_HEADER_SIZE] = 0;
  426. wipp_control_send_message((unsigned char*)ver_line, strlen(ver_line));
  427. }
  428. }
  429. /************************************************************************
  430. * wipp_control_disable_term_echo *
  431. ************************************************************************
  432. DESCRIPTION:
  433. ************************************************************************/
  434. void wipp_control_disable_term_echo()
  435. {
  436. struct termios term;
  437. if (isatty(STDIN_FILENO) == 0)
  438. {
  439. console_printf_terminal("wipp control, Error, standart input is not a terminal device\n");
  440. }
  441. else
  442. {
  443. if (tcgetattr(STDIN_FILENO, &term) != -1)
  444. {
  445. /* Disable the echoing */
  446. term.c_lflag &= ~(ECHO);
  447. if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) != -1)
  448. {
  449. console_printf_terminal("wipp control, Echo is disabled!\n");
  450. }
  451. else
  452. {
  453. console_printf_terminal("wipp control, Error writing terminal attributes\n");
  454. }
  455. }
  456. else
  457. {
  458. console_printf_terminal("wipp control, Error reading terminal attributes\n");
  459. }
  460. }
  461. }
  462. /************************************************************************
  463. * wipp_control_set_baud_rate *
  464. ************************************************************************
  465. DESCRIPTION: Set the UART baudrate
  466. ************************************************************************/
  467. void wipp_control_set_baud_rate(int rate_index)
  468. {
  469. struct termios term;
  470. int r1,r2;
  471. if (isatty(STDIN_FILENO) == 0)
  472. {
  473. console_printf_terminal("wipp control, Error, standart input is not a terminal device\n");
  474. }
  475. else
  476. {
  477. if (tcgetattr(STDIN_FILENO, &term) != -1)
  478. {
  479. /* Change the baud rate*/
  480. r1 = cfsetispeed(&term, B230400);
  481. r2 = cfsetospeed(&term, B230400);
  482. console_printf_terminal("wipp control, results: %d, %d\n", r1, r2);
  483. }
  484. else
  485. {
  486. console_printf_terminal("wipp control, Error reading terminal attributes\n");
  487. }
  488. }
  489. }
  490. /************************************************************************
  491. * wipp_control_active_iperf *
  492. ************************************************************************
  493. DESCRIPTION: Start the iperf process
  494. ************************************************************************/
  495. void wipp_control_active_iperf(char *iperf_cmd_line)
  496. {
  497. unsigned int command_length;
  498. if (SHARED_MEMORY_RUN_PROCESS_RUNNING())
  499. {
  500. console_printf_terminal("wipp control, wipp_control_active_iperf: Error: process already running!\n");
  501. wipp_control_send_iperf_results_to_host(WIPP_CONTROL_EVT_RUN_PROCESS_IS_RUNING, NULL, 0);;
  502. }
  503. else
  504. {
  505. iperf_cmd_line++;
  506. command_length = *(iperf_cmd_line + 0) | (*(iperf_cmd_line + 1) << 8) | (*(iperf_cmd_line + 2) << 16) | (*(iperf_cmd_line + 3) << 24);
  507. iperf_cmd_line += 4;
  508. iperf_cmd_line[command_length] = 0;
  509. console_printf_terminal("wipp control, wipp_control_active_iperf (Len = %d, Cmd = %s)\n", command_length, iperf_cmd_line);
  510. /* Send the command to the process */
  511. write(wipp_control_general_process_in_pipe[1], iperf_cmd_line, command_length);
  512. }
  513. }
  514. /************************************************************************
  515. * wipp_control_deactive_iperf *
  516. ************************************************************************
  517. DESCRIPTION: Stop the iperf process (if it's running)
  518. ************************************************************************/
  519. void wipp_control_deactive_iperf()
  520. {
  521. if (!SHARED_MEMORY_RUN_PROCESS_RUNNING())
  522. {
  523. console_printf_terminal("wipp control, wipp_control_active_iperf: Error: process is not running!\n");
  524. wipp_control_send_iperf_results_to_host(WIPP_CONTROL_EVT_RUN_PROCESS_IS_NOT_RUNING, NULL, 0);
  525. }
  526. else
  527. {
  528. console_printf_terminal("wipp control, wipp_control_deactive_iperf\n");
  529. /* Kill the general process process */
  530. if (wipp_control_general_process_pid > 0)
  531. {
  532. /* Update the process list */
  533. wipp_control_fill_process_table();
  534. /* Kill all the child's of the general process */
  535. wipp_control_kill_family_process(wipp_control_general_process_pid);
  536. wipp_control_general_process_pid = 0;
  537. }
  538. close(wipp_control_general_process_out_pipe[0]);
  539. close(wipp_control_general_process_in_pipe[1]);
  540. /* Initialize the general process */
  541. wipp_control_initialize_general_process();
  542. }
  543. }
  544. /************************************************************************
  545. * wipp_control_send_iperf_results_to_host *
  546. ************************************************************************
  547. DESCRIPTION: Send the run process results to the host via ethernet.
  548. The first parameter is the event type (one of the defines),
  549. it is inserted in the ___ byte of the buffer. Therefor the input
  550. buffer ("inbuf") actual data should start at the ___ byte of the buffer.
  551. CONTEXT : main process only!
  552. ************************************************************************/
  553. void wipp_control_send_iperf_results_to_host(unsigned char event, char *inbuf, int result)
  554. {
  555. /* console_printf_terminal("wipp_control, wipp_control_send_iperf_results_to_host (event = %d)\n", event); */
  556. unsigned char temp_buffer[5] = {'+', '4', '0', '0', '0'};
  557. temp_buffer[2] = event;
  558. switch (event)
  559. {
  560. case WIPP_CONTROL_EVT_RUN_PROCESS_STDOUT:
  561. WIPP_HEADER(inbuf, '4');
  562. inbuf[2] = event;
  563. wipp_control_send_message((unsigned char*)inbuf, result + 3);
  564. break;
  565. case WIPP_CONTROL_EVT_RUN_PROCESS_TERMINATE:
  566. temp_buffer[3] = (SHARED_MEMORY_RUN_PROCESS_RESULT() & 0x00FF);
  567. temp_buffer[4] = ((SHARED_MEMORY_RUN_PROCESS_RESULT() & 0xFF00) >> 8);
  568. wipp_control_send_message(temp_buffer, 5);
  569. break;
  570. case WIPP_CONTROL_EVT_RUN_PROCESS_IS_RUNING:
  571. case WIPP_CONTROL_EVT_RUN_PROCESS_IS_NOT_RUNING:
  572. wipp_control_send_message(temp_buffer, 3);
  573. break;
  574. }
  575. }
  576. /************************************************************************
  577. * wipp_control_kill_family_process *
  578. ************************************************************************
  579. DESCRIPTION: Recursive kill of all the process child's.
  580. CONTEXT :
  581. ************************************************************************/
  582. void wipp_control_kill_family_process(int father_pid)
  583. {
  584. int index;
  585. int status;
  586. /* Check to see this process is a parent */
  587. for (index = 0; index < process_table_current_index; index++)
  588. {
  589. if (process_table[index][1] == father_pid)
  590. {
  591. wipp_control_kill_family_process(process_table[index][0]);
  592. }
  593. }
  594. /* Search for the process and kill it */
  595. for (index = 0; index < process_table_current_index; index++)
  596. {
  597. if (process_table[index][0] == father_pid)
  598. {
  599. /* Kill the process */
  600. kill(process_table[index][0] ,SIGKILL);
  601. waitpid(process_table[index][0], &status, WUNTRACED);
  602. /*console_printf_terminal("wipp_control, wipp_control_kill_family_process, Killing index %d, [%d][%d]\n",process_table[index][0], process_table[index][1]);*/
  603. /* Mark the process as killed */
  604. process_table[index][0] = process_table[index][1] = -1;
  605. }
  606. }
  607. }
  608. /************************************************************************
  609. * wipp_control_fill_process_table *
  610. ************************************************************************
  611. DESCRIPTION: Update the table with the current processs information
  612. CONTEXT :
  613. ************************************************************************/
  614. void wipp_control_fill_process_table()
  615. {
  616. DIR *p_directory;
  617. struct dirent *p_dir_entry;
  618. int direcroty_string_lengh;
  619. int index;
  620. int is_valid_process_directory;
  621. /* Clear the table */
  622. process_table_current_index = 0;
  623. /* Open the directory */
  624. if ((p_directory = opendir("/proc/")) == NULL)
  625. {
  626. console_printf_terminal("wipp_control, wipp_control_fill_process_table, Can't open directory!");
  627. return;
  628. }
  629. /* Go over all the files in the directory */
  630. while ((p_dir_entry = readdir(p_directory)) != NULL)
  631. {
  632. /* Get rid of the unwanted file names */
  633. if ((strcmp(p_dir_entry->d_name, ".") == 0) ||
  634. (strcmp(p_dir_entry->d_name, "..") == 0))
  635. {
  636. continue;
  637. }
  638. direcroty_string_lengh = strlen(p_dir_entry->d_name);
  639. is_valid_process_directory = 1;
  640. /* Check if it is valid process directory name */
  641. for (index = 0; index < direcroty_string_lengh; index++)
  642. {
  643. if ((p_dir_entry->d_name[index] > '9') || (p_dir_entry->d_name[index] < '0'))
  644. {
  645. is_valid_process_directory = 0;
  646. break;
  647. }
  648. }
  649. if (is_valid_process_directory)
  650. {
  651. FILE *file_des;
  652. int temp_number;
  653. char temp_buffer[TEMP_BUFFER_SIZE];
  654. if (snprintf(temp_buffer, TEMP_BUFFER_SIZE, "/proc/%s/status", p_dir_entry->d_name) > 0)
  655. {
  656. /* Get the information out of the status file */
  657. if ((file_des = fopen(temp_buffer, "r")) > 0)
  658. {
  659. /* Skip the first four lines */
  660. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  661. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  662. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  663. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  664. /* Get the process id */
  665. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  666. sscanf(temp_buffer, "%s %d", &temp_buffer[TEMP_BUFFER_SIZE / 2], &temp_number);
  667. process_table[process_table_current_index][0] = temp_number;
  668. /* Get the parent process id */
  669. fgets(temp_buffer, TEMP_BUFFER_SIZE, file_des);
  670. sscanf(temp_buffer, "%s %d", &temp_buffer[TEMP_BUFFER_SIZE / 2], &temp_number);
  671. process_table[process_table_current_index][1] = temp_number;
  672. fclose(file_des);
  673. process_table_current_index++;
  674. if (process_table_current_index == MAX_PROCESS_TABLE_INDEX)
  675. {
  676. console_printf_terminal("wipp_control, wipp_control_fill_process_table, Error, reached maximum process table index\n");
  677. break;
  678. }
  679. }
  680. }
  681. }
  682. }
  683. closedir(p_directory);
  684. }
  685. /************************************************************************
  686. * wipp_control_get_version *
  687. ************************************************************************
  688. DESCRIPTION:
  689. CONTEXT :
  690. ************************************************************************/
  691. void wipp_control_get_version(void)
  692. {
  693. /***************************
  694. Return buffer structure :
  695. Byte 0 : Header ('+')
  696. Byte 1 : OpCode ('a')
  697. Byte 2 : Command Status
  698. Byte 3-6 : Driver Version
  699. Byte 7-10 : FW Version
  700. ***************************/
  701. tiUINT32 ret;
  702. tiUINT8 return_buffer[11];
  703. TIWLN_VERSION_EX VersionData;
  704. console_printf_terminal("WIPP control, wipp_control__get_version.\n");
  705. ret = (tiUINT8)TI_GetDriverVersion(g_id_adapter, &VersionData);
  706. memset(return_buffer, 0, sizeof(return_buffer) / sizeof(return_buffer[0]));
  707. WIPP_HEADER(return_buffer, 'a');
  708. return_buffer[2] = (UINT8)ret;
  709. if (ret == OK)
  710. {
  711. memcpy(return_buffer + 3, &(VersionData.DrvVersion), 4);
  712. memcpy(return_buffer + 7, &(VersionData.FWVersion), 4);
  713. }
  714. wipp_control_send_message(return_buffer, sizeof(return_buffer));
  715. }