PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/CyanogenMod/cm-kernel
C | 159 lines | 61 code | 30 blank | 68 comment | 4 complexity | 365d853419328aac66a852329b72407a 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: ipc.c */
  23. /* PURPOSE: Inter Process Communication utils */
  24. /* Note: This module is for LINUX compilation only! */
  25. /* */
  26. /****************************************************************************************************/
  27. #include <sys/mman.h>
  28. #include <sys/ipc.h>
  29. #include <errno.h>
  30. #include <fcntl.h>
  31. #include <signal.h>
  32. #include <string.h>
  33. #include <unistd.h>
  34. #include "console.h"
  35. #include "ticon.h"
  36. #include "ipc.h"
  37. /*********************/
  38. /* Global variables */
  39. /*******************/
  40. int ethernet_wipp_process_pid = 0;
  41. int ethernet_g_tester_process_pid = 0;
  42. int ethernet_logger_process_pid = 0;
  43. int ethernet_wipp_control_pipe[2];
  44. int ethernet_g_tester_pipe[2];
  45. int ethernet_logger_pipe[2];
  46. int ipc_pipe[2];
  47. void *p_shared_memory;
  48. /************************************************************************
  49. * ipc_initialize *
  50. ************************************************************************
  51. DESCRIPTION: Initialize the IPC
  52. CONTEXT: main process only!
  53. ************************************************************************/
  54. int ipc_initialize()
  55. {
  56. /*****************************/
  57. /* Create IPC shared memory */
  58. /***************************/
  59. if ((p_shared_memory = mmap(0, SHARED_MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == (void *)-1)
  60. {
  61. /* I should use the regular 'printf' function, because the
  62. 'console_printf_terminal' is not working w/o shared memory */
  63. printf("IPC Error, can't create shared memory mapping (%s)!\n", strerror(errno));
  64. return -1;
  65. }
  66. SHARED_MEMORY_TERMINAL_OUTPUT_PATH() = OUTPUT_PATH_SIMPLE_UART;
  67. /************************/
  68. /* Create the IPC pipe */
  69. /**********************/
  70. if (pipe(ipc_pipe) < 0)
  71. {
  72. console_printf_terminal("IPC Error, can't create pipe\n");
  73. return -1;
  74. }
  75. /* Close the write direction of the pipe - because i only read information from this pipe. */
  76. /*close(ipc_pipe[1]);*/
  77. return 0;
  78. }
  79. /************************************************************************
  80. * ipc_deinitialize *
  81. ************************************************************************
  82. DESCRIPTION: Deinitialize the IPC
  83. CONTEXT: main process only!
  84. ************************************************************************/
  85. void ipc_deinitialize()
  86. {
  87. /* Close the read direction of the pipe */
  88. close(ipc_pipe[0]);
  89. }
  90. /************************************************************************
  91. * ipc_send_command_to_main_process *
  92. ************************************************************************
  93. DESCRIPTION: Handles the 'SIGUSR1' signal
  94. CONTEXT: All child process - NOT FROM parent process!!!!
  95. ************************************************************************/
  96. void ipc_send_command_to_main_process(int module_index, unsigned char *command, int size)
  97. {
  98. int pid = getpid();
  99. /*********************************************************************/
  100. /* Flow control */
  101. /* The pid of the caller process is inserted, so the main process */
  102. /* will signal it back and release the waiting condition */
  103. /*****************************************************************/
  104. command[0] = command[1] = 0xFF;
  105. switch (module_index)
  106. {
  107. case ETHERNET_UTILS_G_TESTER_MODULE_ID:
  108. command[0] = (pid & 0x00FF);
  109. command[1] = ((pid & 0xFF00) >> 8);
  110. command[2] = '-';
  111. break;
  112. case ETHERNET_UTILS_WIPP_MODULE_ID:
  113. case ETHERNET_UTILS_LOGGER_MODULE_ID:
  114. command[0] = (pid & 0x00FF);
  115. command[1] = ((pid & 0xFF00) >> 8);
  116. command[2] = '+';
  117. break;
  118. case GENERAL_PROCESS_MODULE_ID:
  119. command[2] = '!';
  120. break;
  121. }
  122. /* Send the buffer to the main process */
  123. write(ipc_pipe[1], command, size);
  124. /* Wait for 300usec (probably the signal will release us earlier) */
  125. usleep(300);
  126. }