• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ipc_k.c
3  *
4  * Copyright(c) 1998 - 2009 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  * src/ipc_k.c
37  *
38  */
39 
40 #include <linux/module.h>
41 #include <linux/kernel.h>
42 #include <linux/stddef.h>
43 #include <linux/netdevice.h>
44 #include <linux/rtnetlink.h>
45 #include <linux/netlink.h>
46 
47 #include "tidef.h"
48 #include "WlanDrvIf.h"
49 #include "osApi.h"
50 #include "ioctl_init.h"
51 #include "cli_cu_common.h"
52 #include "TI_IPC_Api.h"
53 
IPCKernelInit(TI_HANDLE hAdapter,TI_HANDLE hIPCEv)54 TI_UINT32 IPCKernelInit    (TI_HANDLE hAdapter,TI_HANDLE  hIPCEv)
55 {
56     return 0;
57 }
58 
IPCKernelDeInit(TI_HANDLE hAdapter)59 TI_UINT32 IPCKernelDeInit  (TI_HANDLE hAdapter)
60 {
61     return 0;
62 }
63 
64 
65 /*******************************************************/
IPC_EventSend(TI_HANDLE hAdapter,TI_UINT8 * pEvData,TI_UINT32 EvDataSize)66 TI_INT32 IPC_EventSend(TI_HANDLE hAdapter, TI_UINT8* pEvData, TI_UINT32 EvDataSize)
67 {
68 	struct sk_buff *skb;
69 	int res;
70 	TWlanDrvIfObj *drv = (TWlanDrvIfObj *) hAdapter;
71 	TI_UINT32 realSize = 0;
72 	TI_UINT32 msgSize;
73 	struct nlmsghdr *nlh;
74 	TI_UINT8 *msg;
75 
76 	os_wake_lock_timeout_enable(drv);
77 	/* This event is targetted to the OS process Id 0 is not a valid pId for LINUX*/
78 	if (((IPC_EVENT_PARAMS *)pEvData)->uProcessID == 0)
79 	{
80 		((IPC_EVENT_PARAMS *)pEvData)->pfEventCallback(( IPC_EV_DATA *)pEvData);
81 		return 0;
82 	}
83 
84 	/* set the payload size */
85 	msgSize = (( IPC_EV_DATA *) pEvData) ->uBufferSize + offsetof(IPC_EV_DATA,uBuffer);
86 
87 	/* add the netlink header size */
88 	realSize = NLMSG_SPACE(msgSize);
89 
90 	/* allocate the complete message */
91 	skb = dev_alloc_skb(realSize);
92 	if (!skb) {
93 		printk(KERN_ERR "Failed to allocate new skb with size=%u.\n",realSize);
94 		return -1;
95 	}
96 
97 	/* set the netlink header params */
98 	nlh = NLMSG_PUT(skb, 0, 0, NLMSG_DONE, realSize - sizeof(*nlh));
99 
100 	/* get the payload pointer */
101 	msg = (char *)NLMSG_DATA(nlh);
102 
103 	/* copy the data to the payload */
104 	memcpy(msg,pEvData,msgSize);
105 
106 	NETLINK_CB(skb).pid = 0;   /* from kernel */
107 #define RTMGRP_LINK 1
108 	NETLINK_CB(skb).dst_group = RTMGRP_LINK;
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 
119 nlmsg_failure:
120 	ti_dprintf(TIWLAN_LOG_INFO,"IPC kernel: did not send the netlink message\n");
121 	return -1;
122 }
123