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