cm-kernel /drivers/net/wireless/tiwlan1251/CUDK/CLI/ipc.c

Language C Lines 160
MD5 Hash 365d853419328aac66a852329b72407a Estimated Cost $1,433 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*******************************************************************************
**+--------------------------------------------------------------------------+**
**|                                                                          |**
**| Copyright 1998-2008 Texas Instruments, Inc. - http://www.ti.com/         |**
**|                                                                          |**
**| Licensed under the Apache License, Version 2.0 (the "License");          |**
**| you may not use this file except in compliance with the License.         |**
**| You may obtain a copy of the License at                                  |**
**|                                                                          |**
**|     http://www.apache.org/licenses/LICENSE-2.0                           |**
**|                                                                          |**
**| Unless required by applicable law or agreed to in writing, software      |**
**| distributed under the License is distributed on an "AS IS" BASIS,        |**
**| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |**
**| See the License for the specific language governing permissions and      |**
**| limitations under the License.                                           |**
**|                                                                          |**
**+--------------------------------------------------------------------------+**
*******************************************************************************/


/****************************************************************************************************/
/*                                                                                                  */
/*      MODULE:     ipc.c                                                                           */
/*      PURPOSE:    Inter Process Communication utils                                               */
/*      Note:	    This module is for LINUX compilation only!										*/
/*                                                                                                  */
/****************************************************************************************************/

#include <sys/mman.h>
#include <sys/ipc.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>

#include "console.h"
#include "ticon.h"
#include "ipc.h"

	/*********************/
	/* Global variables */
	/*******************/

int ethernet_wipp_process_pid = 0;
int ethernet_g_tester_process_pid = 0;
int ethernet_logger_process_pid = 0;


int ethernet_wipp_control_pipe[2];
int ethernet_g_tester_pipe[2];
int ethernet_logger_pipe[2];

int ipc_pipe[2];

void *p_shared_memory;


/************************************************************************
 *                        ipc_initialize				                *
 ************************************************************************
DESCRIPTION: Initialize the IPC 

CONTEXT:  main process only!
************************************************************************/
int ipc_initialize()
{
	/*****************************/
	/* Create IPC shared memory */
	/***************************/

	if ((p_shared_memory = mmap(0, SHARED_MEMORY_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0)) == (void *)-1) 
	{
		/* I should use the regular 'printf' function, because the 
		   'console_printf_terminal' is not working w/o shared memory */
		printf("IPC Error, can't create shared memory mapping (%s)!\n", strerror(errno));

		return -1;
	}

	SHARED_MEMORY_TERMINAL_OUTPUT_PATH() = OUTPUT_PATH_SIMPLE_UART;

	/************************/
	/* Create the IPC pipe */
	/**********************/

	if (pipe(ipc_pipe) < 0)
	{
		console_printf_terminal("IPC Error, can't create pipe\n");

		return -1;
	}

	/* Close the write direction of the pipe  - because i only read information from this pipe. */ 
	/*close(ipc_pipe[1]);*/

	return 0;
}

/************************************************************************
 *                        ipc_deinitialize				                *
 ************************************************************************
DESCRIPTION: Deinitialize the IPC 

CONTEXT:  main process only!
************************************************************************/
void ipc_deinitialize()
{
	/* Close the read direction of the pipe */ 
	close(ipc_pipe[0]);
}

/************************************************************************
 *                        ipc_send_command_to_main_process              *
 ************************************************************************
DESCRIPTION: Handles the 'SIGUSR1' signal 

CONTEXT:  All child process - NOT FROM parent process!!!!
************************************************************************/
void ipc_send_command_to_main_process(int module_index, unsigned char *command, int size)
{
	int pid = getpid();

	/*********************************************************************/
	/* Flow control 													*/
	/* The pid of the caller process is inserted, so the main process  */
	/* will signal it back and release the waiting condition		  */
	/*****************************************************************/

	command[0] = command[1] = 0xFF;

	switch (module_index)
	{
	case ETHERNET_UTILS_G_TESTER_MODULE_ID:
		command[0] = (pid & 0x00FF);
		command[1] = ((pid & 0xFF00) >> 8);
		command[2] = '-';
		break;

	case ETHERNET_UTILS_WIPP_MODULE_ID:
	case ETHERNET_UTILS_LOGGER_MODULE_ID:
		command[0] = (pid & 0x00FF);
		command[1] = ((pid & 0xFF00) >> 8);
		command[2] = '+';
		break;

	case GENERAL_PROCESS_MODULE_ID:
		command[2] = '!';
		break;
	}

	/* Send the buffer to the main process */
	write(ipc_pipe[1], command, size);

	/* Wait for 300usec (probably the signal will release us earlier) */
	usleep(300);
}
Back to Top