PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/CUDK/IPC/Linux/ipc_event.c

http://github.com/CyanogenMod/cm-kernel
C | 338 lines | 212 code | 56 blank | 70 comment | 27 complexity | aa0b5765dbaa00778e9d164a2bc7aa60 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. #include <string.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <errno.h>
  24. #include <sys/types.h>
  25. #include <sys/socket.h>
  26. #include <sys/un.h>
  27. #include <unistd.h>
  28. #include <linux/stddef.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/rtnetlink.h>
  31. #include <pthread.h>
  32. #include "ipc_event.h"
  33. #include "cli_cu_common.h"
  34. #include "tiioctl.h"
  35. #include "TI_IPC_Api.h"
  36. static int dev_socket = -1;
  37. static int serv_sfd = -1;
  38. config_registry_t cnfg_registry_table;
  39. UINT32 prId;
  40. static tiINT32 ipc_start = 0;
  41. /******************************************************************
  42. _ipc_EventHandler
  43. Driver events handler
  44. */
  45. tiVOID _ipc_EventHandler(UINT8* pEvMessage, tiUINT32 nEvMessageSize )
  46. {
  47. /* print_memory_dump((char*)pEvMessage, nEvMessageSize );*/
  48. if (((IPC_EVENT_PARAMS*) pEvMessage)->pfEventCallback == NULL)
  49. {
  50. printf("\n---_ipc_EventHandler: ERROR Bad Callback pointer\n");
  51. return;
  52. }
  53. if(nEvMessageSize < sizeof(IPC_EVENT_PARAMS))
  54. {
  55. print_err("\n---_ipc_EventHandler: ERROR event size - %x\n ",nEvMessageSize);
  56. return;
  57. }
  58. print_deb("--_ipc_EventHandler: \n");
  59. ((IPC_EVENT_PARAMS*) pEvMessage)->pfEventCallback((IPC_EV_DATA * )pEvMessage);
  60. }
  61. /*********************************************************************
  62. _ipc_cu_handler
  63. CLI configuration events handler
  64. */
  65. tiVOID _ipc_cu_handler(UINT8* pMessage, tiUINT32 nMessageSize)
  66. {
  67. print_deb("\n---_ipc_cu_handler() data size - %d\n ",nMessageSize);
  68. print_memory_dump((char*)pMessage, nMessageSize );
  69. IPC_CONFIG_PARAMS *pData_tosend = (IPC_CONFIG_PARAMS *)malloc(sizeof(IPC_CONFIG_PARAMS));
  70. pData_tosend->F_ConfigNotification = cnfg_registry_table.cfg_cb;
  71. (*pData_tosend->F_ConfigNotification)(pMessage, nMessageSize );
  72. free(pData_tosend);
  73. }
  74. /*********************************************************************/
  75. void check_unbound(void)
  76. {
  77. /*
  78. OS_802_11_MAC_ADDRESS curr_mac = { 0 };
  79. UINT32 size;
  80. if(IPC_DeviceIoControl((TI_HANDLE)ti_drv_name, TIWLN_802_3_CURRENT_ADDRESS, NULL, 0, &curr_mac,
  81. sizeof(OS_802_11_MAC_ADDRESS), (tiUINT32*)nSize ))
  82. {
  83. send unbound
  84. }
  85. */
  86. }
  87. /**************************************************************/
  88. void *_ipc_EventThread(void *args)
  89. {
  90. /* set timeout for select*/
  91. int fd;
  92. char* buf = (char*)malloc(4096); /* the maximum acceptable size*/
  93. fd_set fds_read;
  94. struct nlmsghdr * nlHdr;
  95. UINT8 * pData;
  96. tiUINT32 nDataLen;
  97. if (dev_socket > serv_sfd)
  98. fd = dev_socket+1;
  99. else
  100. fd = serv_sfd+1;
  101. print_deb("---_ipc_EventThread() - thread is running fd = %d\n", fd);
  102. while(1)
  103. {
  104. /* create fd_set*/
  105. FD_ZERO(&fds_read);
  106. if (dev_socket != -1)
  107. FD_SET(dev_socket, &fds_read);
  108. if (serv_sfd != -1)
  109. FD_SET(serv_sfd, &fds_read);
  110. /* wait for packet on two sockets*/
  111. int n = select(fd, &fds_read, NULL, NULL,NULL );
  112. /* if data is available, receive it*/
  113. if( n > 0 )
  114. {
  115. /* this is event from the driver*/
  116. if( FD_ISSET(dev_socket, &fds_read) )
  117. {
  118. /* get 'n' bytes from driver socket*/
  119. n = recvfrom(dev_socket, buf, 4096, 0, NULL,NULL/*(struct sockaddr*)&sanl, &sanllen*/);
  120. if (n <= 0)
  121. {
  122. perror(__FUNCTION__);
  123. continue;
  124. }
  125. nlHdr = (struct nlmsghdr *)buf;
  126. /* Check if header is valid */
  127. if((NLMSG_OK(nlHdr, n) == 0) || (nlHdr->nlmsg_type == NLMSG_ERROR)){
  128. perror("Error in recieved NetLink packet");
  129. continue;
  130. }
  131. pData = (UINT8 *)NLMSG_DATA(nlHdr);
  132. nDataLen = NLMSG_PAYLOAD(nlHdr,n);
  133. _ipc_EventHandler (pData, nDataLen );
  134. }
  135. else if( FD_ISSET(serv_sfd, &fds_read) )
  136. {
  137. print_deb(" ---_ipc_EventThread() cu receive socket: %x \n",
  138. serv_sfd);
  139. /*printf(" ---_ipc_EventThread() cu receive enable cnfg_registry_table.enable\n");*/
  140. /* read, get # bytes read*/
  141. n = recvfrom(serv_sfd, buf, 4096, 0,NULL,NULL);
  142. if(n < 0)
  143. {
  144. print_err("--- _ipc_EventThread() -ERROR receiving config msg \n");
  145. continue;
  146. }
  147. else
  148. _ipc_cu_handler((UINT8*) buf, n);
  149. }
  150. else
  151. print_err(" ---_ipc_EventThread() cu not a socket: %x \n",serv_sfd);
  152. }
  153. }
  154. print_err("IPC exits \n");
  155. return 0;
  156. }
  157. /******************************************************************************/
  158. tiINT32 rtnl_open(void)
  159. {
  160. int fd;
  161. struct sockaddr_nl local;
  162. prId = getpid();
  163. /*printf("PROCCESS: %d\n", prId);*/
  164. fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);
  165. if (fd < 0) {
  166. perror(__FUNCTION__);
  167. return -1;
  168. }
  169. memset(&local, 0, sizeof(local));
  170. local.nl_family = AF_NETLINK;
  171. /* local.nl_groups = RTMGRP_LINK;*/
  172. local.nl_pid = prId;
  173. if (bind(fd, (struct sockaddr*)&local, sizeof(local)) < 0) {
  174. perror(__FUNCTION__);
  175. return -1;
  176. }
  177. /*printf("User: socket - %d\n",fd);*/
  178. return fd;
  179. }
  180. /*****************************************************************************/
  181. tiINT32 cnfg_open(void)
  182. {
  183. /*int rc;*/
  184. struct sockaddr_un serv_addr;/* clnt_addr;*/
  185. int serv_addr_len;/* clnt_addr_len, max_clnt_len, n;*/
  186. unlink("/var/run/echo_server");
  187. /* Create socket */
  188. if(( serv_sfd = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0)
  189. {
  190. print_err("--Server: error creating socket\n");
  191. return -1;
  192. }
  193. print_deb("---cnfg_open(): socket - %d\n", serv_sfd);
  194. /*bzero(serv_addr,sizeof(serv_addr));*/
  195. /* Store the client s name in the socket address. */
  196. serv_addr.sun_family = AF_LOCAL;
  197. strcpy (serv_addr.sun_path, "/var/run/echo_server");
  198. serv_addr_len = sizeof(serv_addr.sun_family)+strlen(serv_addr.sun_path);
  199. if(bind(serv_sfd, (struct sockaddr*)&serv_addr, serv_addr_len) <0 )
  200. {
  201. print_err("--Server: error binding to server socket - err %d(%s)\n", errno, strerror(errno));
  202. return -1;
  203. }
  204. return 0;
  205. }
  206. /*****************************************************************************/
  207. tiINT32 ipc_interfaces_init(tiVOID)
  208. {
  209. int rc;
  210. pthread_t ev_thread_id;
  211. /* Open netlink channel */
  212. if((dev_socket = rtnl_open()) < 0)
  213. {
  214. printf("\nCan't initialize rtnetlink socket\n");
  215. return -1;
  216. }
  217. print_deb("---ipc_interfaces_init - rtnetlink socket is created \n");
  218. rc = pthread_create(&ev_thread_id, NULL, _ipc_EventThread, (void*)NULL);
  219. print_deb("---ipc_CreateInterface() - thread is created \n");
  220. if (rc)
  221. printf("---ipc_CreateInterface() - ERROR code from pthread_create() is %d\n", rc);
  222. return 0;
  223. }
  224. /******************************************************************************/
  225. tiINT32 IPC_RegisterEvent(TI_HANDLE hDevice, IPC_EVENT_PARAMS* pEvParams)
  226. {
  227. /*set ioctl event enable*/
  228. IPC_EVENT_PARAMS* pReg = (IPC_EVENT_PARAMS*)pEvParams;
  229. IPC_EVENT_PARAMS ouput;
  230. tiINT32 res;
  231. tiUINT32 bytesReturned;
  232. if(pReg->uEventType == IPC_EVENT_UNBOUND)/*insert UNBOUND*/
  233. {
  234. return 0;
  235. }
  236. pEvParams->uDeliveryType = DELIVERY_PUSH;
  237. pEvParams->uProcessID = prId;
  238. print_deb("---IPC_RegisterEvent() event - %#x\n", pReg->uEventType);
  239. res = IPC_DeviceIoControl(hDevice, TIWLN_802_11_ENABLE_EVENT, (tiVOID*)pEvParams, sizeof(IPC_EVENT_PARAMS), /*NULL,0*/&ouput, sizeof(IPC_EVENT_PARAMS), &bytesReturned );
  240. pReg->uEventID = ouput.uEventID;
  241. return res;
  242. }
  243. /******************************************************************************/
  244. tiINT32 IPC_UnRegisterEvent(TI_HANDLE hDevice, IPC_EVENT_PARAMS* pEvParams)
  245. {
  246. UINT32 id = (UINT32)pEvParams->uEventID;
  247. tiUINT32 bytesReturned;
  248. /*set ioctl event disable*/
  249. return IPC_DeviceIoControl(hDevice, TIWLN_802_11_DISABLE_EVENT, (tiVOID*)&id, sizeof(UINT32), NULL, 0, &bytesReturned );
  250. }
  251. /******************************************************************************/
  252. tiINT32 IPC_RegisterConfig(tiVOID* pEvParams, tiUINT32 EvParamsSize)
  253. {
  254. /*set ioctl event enable*/
  255. IPC_CONFIG_PARAMS *pData = (IPC_CONFIG_PARAMS*)pEvParams;
  256. cnfg_registry_table.len = EvParamsSize;
  257. cnfg_registry_table.cfg_cb = pData->F_ConfigNotification;
  258. cnfg_registry_table.enable = 1;
  259. print_deb("---IPC_RegisterConfig() l - %x \n", cnfg_registry_table.len);
  260. return 0;
  261. }
  262. /*****************************************************************************/
  263. TI_HANDLE IPC_Init(void)
  264. {
  265. int rc = 0;
  266. if(ipc_start)
  267. return (TI_HANDLE)rc;
  268. else
  269. {
  270. rc = ipc_interfaces_init();
  271. ipc_start++;
  272. }
  273. return (TI_HANDLE)rc;
  274. }
  275. /*****************************************************************************/
  276. tiINT32 IPC_DeInit (void)
  277. {
  278. /* close(dev_socket );*/
  279. /* close(serv_sfd );*/
  280. return 0;
  281. }