1/****************************************************************************
2**+-----------------------------------------------------------------------+**
3**|                                                                       |**
4**| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
5**| All rights reserved.                                                  |**
6**|                                                                       |**
7**| Redistribution and use in source and binary forms, with or without    |**
8**| modification, are permitted provided that the following conditions    |**
9**| are met:                                                              |**
10**|                                                                       |**
11**|  * Redistributions of source code must retain the above copyright     |**
12**|    notice, this list of conditions and the following disclaimer.      |**
13**|  * Redistributions in binary form must reproduce the above copyright  |**
14**|    notice, this list of conditions and the following disclaimer in    |**
15**|    the documentation and/or other materials provided with the         |**
16**|    distribution.                                                      |**
17**|  * Neither the name Texas Instruments nor the names of its            |**
18**|    contributors may be used to endorse or promote products derived    |**
19**|    from this software without specific prior written permission.      |**
20**|                                                                       |**
21**| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
22**| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
23**| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
24**| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
25**| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
26**| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
27**| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
28**| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
29**| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
30**| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
31**| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
32**|                                                                       |**
33**+-----------------------------------------------------------------------+**
34****************************************************************************/
35
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/stddef.h>
39#include <linux/netdevice.h>
40#include <linux/rtnetlink.h>
41#include <linux/netlink.h>
42
43#include "osTIType.h"
44#include "esta_drv.h"
45#include "osApi.h"
46#include "ioctl_init.h"
47#include "cli_cu_common.h"
48#include "TI_IPC_Api.h"
49
50UINT32 IPCKernelInit    (TI_HANDLE hAdapter,TI_HANDLE  hIPCEv)
51{
52    return 0;
53}
54
55UINT32 IPCKernelDeInit  (TI_HANDLE hAdapter)
56{
57    return 0;
58}
59
60
61/*******************************************************/
62INT32 IPC_EventSend(TI_HANDLE hAdapter, tiUINT8* pEvData, UINT32 EvDataSize)
63{
64	struct sk_buff *skb;
65	int res;
66	tiwlan_net_dev_t *drv = (tiwlan_net_dev_t *) hAdapter;
67	UINT32 realSize = 0;
68	UINT32 msgSize;
69	struct nlmsghdr *nlh;
70	tiUINT8 *msg;
71
72#ifdef CONFIG_ANDROID_POWER
73	drv->receive_packet = 1; /* Remember to stay awake */
74#endif
75	/* This event is targetted to the OS process Id 0 is not a valid pId for LINUX*/
76	if (((IPC_EVENT_PARAMS *)pEvData)->uProcessID == 0)
77	{
78		((IPC_EVENT_PARAMS *)pEvData)->pfEventCallback((IPC_EV_DATA *)pEvData);
79		return 0;
80	}
81
82	/* set the payload size */
83	msgSize = (( IPC_EV_DATA *) pEvData) ->uBufferSize + offsetof(IPC_EV_DATA,uBuffer);
84
85	/* add the netlink header size */
86	realSize = NLMSG_SPACE(msgSize);
87
88	/* allocate the complete message */
89	skb = dev_alloc_skb(realSize);
90	if (!skb) {
91		printk(KERN_ERR "Failed to allocate new skb with size=%u.\n",realSize);
92		return -1;
93	}
94
95	/* set the netlink header params */
96	nlh = NLMSG_PUT(skb, 0, 0, NLMSG_DONE, realSize - sizeof(*nlh));
97
98	/* get the payload pointer */
99	msg = (char *)NLMSG_DATA(nlh);
100
101	/* copy the data to the payload */
102	memcpy(msg,pEvData,msgSize);
103
104	NETLINK_CB(skb).pid = 0;   /* from kernel */
105	NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
106#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
107	NETLINK_CB(skb).dst_pid = (( IPC_EVENT_PARAMS *) pEvData) ->uProcessID; /* Dm: */
108#endif
109
110	/* send the message*/
111	res = netlink_unicast(drv->wl_sock, skb, (( IPC_EVENT_PARAMS *) pEvData) ->uProcessID, MSG_DONTWAIT);
112
113	/* Sanity checks. As far as we're concerned this error is unrecovarable.*/
114	if (res >= 0)
115	{
116		return 0;
117	}
118
119nlmsg_failure:
120	ti_dprintf(TIWLAN_LOG_INFO,"IPC kernel: did not send the netlink message\n");
121	return -1;
122}
123