1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* 2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * ipc_k.c 3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved. 6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without 8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions 9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met: 10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Redistributions of source code must retain the above copyright 12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * notice, this list of conditions and the following disclaimer. 13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Redistributions in binary form must reproduce the above copyright 14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * notice, this list of conditions and the following disclaimer in 15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * the documentation and/or other materials provided with the 16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * distribution. 17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * * Neither the name Texas Instruments nor the names of its 18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * contributors may be used to endorse or promote products derived 19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * from this software without specific prior written permission. 20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */ 33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* 36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * src/ipc_k.c 37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * 38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */ 39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/module.h> 41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/kernel.h> 42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/stddef.h> 43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/netdevice.h> 44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/rtnetlink.h> 45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/netlink.h> 46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h" 48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "WlanDrvIf.h" 49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "osApi.h" 50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "ioctl_init.h" 51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "cli_cu_common.h" 52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "TI_IPC_Api.h" 53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_UINT32 IPCKernelInit (TI_HANDLE hAdapter,TI_HANDLE hIPCEv) 55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return 0; 57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_UINT32 IPCKernelDeInit (TI_HANDLE hAdapter) 60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return 0; 62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*******************************************************/ 66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_INT32 IPC_EventSend(TI_HANDLE hAdapter, TI_UINT8* pEvData, TI_UINT32 EvDataSize) 67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{ 6841a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt struct sk_buff *skb; 6941a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt int res; 7041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt TWlanDrvIfObj *drv = (TWlanDrvIfObj *) hAdapter; 7141a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt TI_UINT32 realSize = 0; 7241a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt TI_UINT32 msgSize; 7341a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt struct nlmsghdr *nlh; 7441a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt TI_UINT8 *msg; 7541a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 7641a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt os_wake_lock_timeout_enable(drv); 7741a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* This event is targetted to the OS process Id 0 is not a valid pId for LINUX*/ 7841a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt if (((IPC_EVENT_PARAMS *)pEvData)->uProcessID == 0) 7941a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt { 8041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt ((IPC_EVENT_PARAMS *)pEvData)->pfEventCallback(( IPC_EV_DATA *)pEvData); 8141a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt return 0; 8241a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt } 8341a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 8441a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* set the payload size */ 8541a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt msgSize = (( IPC_EV_DATA *) pEvData) ->uBufferSize + offsetof(IPC_EV_DATA,uBuffer); 8641a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 8741a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* add the netlink header size */ 8841a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt realSize = NLMSG_SPACE(msgSize); 8941a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 9041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* allocate the complete message */ 9141a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt skb = dev_alloc_skb(realSize); 9241a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt if (!skb) { 93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt printk(KERN_ERR "Failed to allocate new skb with size=%u.\n",realSize); 94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return -1; 9541a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt } 9641a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 9741a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* set the netlink header params */ 9841a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt nlh = NLMSG_PUT(skb, 0, 0, NLMSG_DONE, realSize - sizeof(*nlh)); 9941a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 10041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* get the payload pointer */ 10141a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt msg = (char *)NLMSG_DATA(nlh); 10241a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 10341a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* copy the data to the payload */ 10441a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt memcpy(msg,pEvData,msgSize); 10541a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt 10641a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt NETLINK_CB(skb).pid = 0; /* from kernel */ 107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define RTMGRP_LINK 1 10841a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt NETLINK_CB(skb).dst_group = RTMGRP_LINK; 109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 11041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* send the message*/ 11141a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt res = netlink_unicast(drv->wl_sock, skb, (( IPC_EVENT_PARAMS *) pEvData) ->uProcessID, MSG_DONTWAIT); 112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 11341a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt /* Sanity checks. As far as we're concerned this error is unrecovarable.*/ 11441a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt if (res >= 0) 11541a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt { 116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return 0; 11741a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt } 118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt 119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtnlmsg_failure: 12041a0b79959b6dd47cd62b042b1e40e815191bd88Dmitry Shmidt ti_dprintf(TIWLAN_LOG_INFO,"IPC kernel: did not send the netlink message\n"); 121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt return -1; 122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt} 123