PageRenderTime 66ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/CyanogenMod/cm-kernel
C | 332 lines | 173 code | 43 blank | 116 comment | 27 complexity | 8e50a3a29886a25efa42d8536f814c67 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 <stdio.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <sys/ioctl.h>
  24. #include <sys/socket.h>
  25. #include <linux/if.h>
  26. #include <linux/wireless.h>
  27. #include <stdlib.h>
  28. #include <unistd.h>
  29. #include "tiioctl.h"
  30. #include "osDot11.h"
  31. #include "linux_ioctl_common.h"
  32. #include "cli_cu_common.h"
  33. #include "TI_IPC_Api.h"
  34. static int g_socket = 0; /* socket descriptor */
  35. static int iw_sockets_open(void)
  36. {
  37. /* int netlink_sock = -1; */ /* Kernel user interface device */
  38. int ipx_sock = -1; /* IPX socket */
  39. int ax25_sock = -1; /* AX.25 socket */
  40. int inet_sock = -1; /* INET socket */
  41. int ddp_sock = -1; /* Appletalk DDP socket */
  42. /*
  43. * Now pick any (exisiting) useful socket family for generic queries
  44. * Note : don't open all the socket, only returns when one matches,
  45. * all ocols might not be valid.
  46. * Workaround by Jim Kaba <jkaba@sarnoff.com>
  47. * Note : in 99% of the case, we will just open the inet_sock.
  48. * The remaining 1% case are not fully correct...
  49. */
  50. /*netlink_sock=socket(PF_NETLINK, SOCK_DGRAM, 0);
  51. if(netlink_sock!=-1)
  52. return netlink_sock;*/
  53. inet_sock=socket(AF_INET, SOCK_DGRAM, 0);
  54. if(inet_sock!=-1)
  55. return inet_sock;
  56. ipx_sock=socket(AF_IPX, SOCK_DGRAM, 0);
  57. if(ipx_sock!=-1)
  58. return ipx_sock;
  59. ax25_sock=socket(AF_AX25, SOCK_DGRAM, 0);
  60. if(ax25_sock!=-1)
  61. return ax25_sock;
  62. ddp_sock=socket(AF_APPLETALK, SOCK_DGRAM, 0);
  63. /*
  64. * If this is -1 we have no known network layers and its time to jump.
  65. */
  66. return ddp_sock;
  67. }
  68. TI_HANDLE IPC_DeviceOpen (tiVOID* pAdapterName)
  69. {
  70. g_socket = iw_sockets_open();
  71. if( g_socket == -1 )
  72. {
  73. perror("socket");
  74. return 0;
  75. }
  76. /* create interfaces for events receiving */
  77. /*
  78. if (_ipc_CreateInterface(pAdapterName))
  79. {
  80. print_err("**IPC error**\n");
  81. return NULL;
  82. }
  83. */
  84. return (pAdapterName && *((char *) pAdapterName)) ? (TI_HANDLE) pAdapterName : NULL;
  85. }
  86. tiINT32 IPC_DeviceClose(TI_HANDLE hDevice)
  87. {
  88. if( g_socket )
  89. close( g_socket );
  90. return 0;
  91. }
  92. tiINT32 IPC_DeviceIoControl(TI_HANDLE hDevice, tiUINT32 ioctl_cmd, tiVOID* bufIn, tiUINT32 sizeIn,
  93. tiVOID* bufOut, tiUINT32 sizeOut, tiUINT32* sizeRet )
  94. {
  95. int res, max_size, cmd;
  96. struct ifreq req;
  97. tiioctl_req_t *ti_req = (tiioctl_req_t *) &req.ifr_ifru;
  98. tiVOID* buf, *setget_buf = NULL;
  99. tiUINT32 size;
  100. int cmd_type = ((bufOut) ? IOCTL_GET : 0) | ((bufIn) ? IOCTL_SET : 0);
  101. if( !g_socket )
  102. {
  103. print_err("**Socket error**\n");
  104. return -EINVAL;
  105. }
  106. if( (cmd_type & IOCTL_SETGET) == IOCTL_SETGET )
  107. {
  108. size = max( max(sizeIn, sizeOut ), 8 ); /* always pass as pointer to buffer*/
  109. if( size >= 0xFFFF )
  110. {
  111. print_err("Max. size for SET_GET ioctl - %u bytes (sizeIn=%u, sizeOut=%u)\n",
  112. 0xFFFF, sizeIn, sizeOut );
  113. return -ENOMEM;
  114. }
  115. buf = setget_buf = malloc(size);
  116. if( !setget_buf ){
  117. print_err("IPC_DeviceIoControl: setget_buf is NULL\n");
  118. return -ENOMEM;
  119. }
  120. memmove(setget_buf, bufIn, sizeIn );
  121. cmd = SIOCDEVPRIVATE;
  122. }
  123. else
  124. {
  125. if( cmd_type & IOCTL_GET )
  126. {
  127. buf = bufOut;
  128. size = sizeOut;
  129. cmd = SIOCDEVPRIVATE+1; /* for GET private ioctls */
  130. }
  131. else
  132. {
  133. buf = bufIn;
  134. size= sizeIn;
  135. cmd = SIOCDEVPRIVATE; /* for SET private ioctls */
  136. }
  137. }
  138. #if DEBUG
  139. memset(&req, 0xfe, sizeof(req) );
  140. #endif
  141. print_deb("===IPC_DeviceIoControl('%s', cmd=%u (%s%s), data=%p (%#x), size=%u, sizeRet = %p(%x))\n",
  142. (char *) hDevice, ioctl_cmd,
  143. (cmd_type & IOCTL_SET) ? "SET" : "", (cmd_type & IOCTL_GET) ? "GET" : "",
  144. buf, (buf) ? * (tiINT32 *)buf : 0, size, sizeRet, sizeRet ? *sizeRet : -1);
  145. max_size = ((char *) &req + sizeof(req)) - (char *) &ti_req->user_data_pointer;
  146. ti_req->length = size;
  147. ti_req->cmd = ioctl_cmd;
  148. ti_req->cmd_type = cmd_type;
  149. if( size > max_size )
  150. {
  151. ti_req->user_data_pointer = (tiUINT32) buf;
  152. }
  153. else
  154. {
  155. if( cmd_type & IOCTL_SET ) /* SET ioctl */
  156. {
  157. /*print_deb("util_get_ioctl(): offset=%d, data='%s', size=%d\n", offset, (char *)data, size);*/
  158. memmove( ((tiCHAR *) &ti_req->user_data_pointer), buf, size );
  159. }
  160. else
  161. ti_req->user_data_pointer = 0;
  162. }
  163. strncpy(req.ifr_ifrn.ifrn_name, (char *) hDevice, IFNAMSIZ);
  164. print_deb("===== send_ioctl: socket=%d, cmd=%d, &req=%p\n", g_socket, cmd, &req );
  165. print_deb("===== send_ioctl: req={name='%s', sub_cmd=%ld, size=%ld (max=%d), data=%p\n",
  166. req.ifr_ifrn.ifrn_name, ti_req->cmd, ti_req->length, max_size, (void *) ti_req->user_data_pointer );
  167. /* print_memory_dump( (char *) &req, sizeof(req));*/
  168. res = ioctl(g_socket, cmd, &req);
  169. #ifdef GWSI_DRIVER
  170. /* Yuck - set the result to 0 in case ioctl return error */
  171. if (res == -1) res = 0;
  172. #endif
  173. if( res )
  174. { /* for DEBUG version ONLY*/
  175. print_deb( "** IPC_DeviceIoControl() return %d\n", res /*(char *) hDevice*/ );
  176. /* return res;*/
  177. }
  178. else
  179. {
  180. if( cmd_type & IOCTL_GET )
  181. {
  182. size = ti_req->length;
  183. if( (cmd_type & IOCTL_SETGET) == IOCTL_SETGET )
  184. {
  185. memmove(bufOut,setget_buf,size);
  186. free( setget_buf );
  187. }
  188. else
  189. {
  190. if( size <= max_size )
  191. memmove( buf, (char *) &ti_req->user_data_pointer, size );
  192. print_memory_dump((char *) buf, min(32, size) );
  193. print_deb( "IPC_DeviceIoControl(): Size=%u, max_size=%d, *data=%x\n", size, max_size, * (tiUINT32*) buf );
  194. }
  195. }
  196. if( sizeRet )
  197. *sizeRet = size; /* ti_req->length */
  198. print_deb("===== send_ioctl: res=%d, sizeRet=%p (%x)\n", res, sizeRet, sizeRet ? *sizeRet : -1);
  199. }
  200. return res;
  201. }
  202. /* --------------------------------------------------------- */
  203. /* tiINT32 TI_hwReset (TI_HANDLE hAdapter)*/
  204. /* {*/
  205. /* tiUINT32 data = 1;*/
  206. /* return IPC_DeviceIoControl( hAdapter, TIWLN_HW_RESET_HW, IOCTRL_SET, &data, sizeof(data) );*/
  207. /* return tiwlan_get_ioctl(hAdapter, -1, TIWLN_HW_RESET_HW, &data, sizeof(data) ); */
  208. /* }*/
  209. /* tiINT32 TI_NumberOfAntennas (TI_HANDLE hAdapter, tiUINT32* puNumberOfAntennas )*/
  210. /* {*/
  211. /* return IPC_DeviceIoControl( hAdapter, TIWLN_802_11_NUMBER_OF_ANTENNAS, IOCTRL_GET, puNumberOfAntennas, sizeof(tiUINT32) );*/
  212. /* }*/
  213. /* int tiwlan_set_mixed_mode( U32 drv_handler, U32 data )*/
  214. /* {*/
  215. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_MIXED_MODE_SET, &data, sizeof(data) );*/
  216. /* }*/
  217. /* */
  218. /* int tiwlan_get_mixed_mode( U32 drv_handler, U32 *p_data )*/
  219. /* {*/
  220. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_MIXED_MODE_GET, p_data, sizeof(*p_data) );*/
  221. /* }*/
  222. /* */
  223. /* int tiwlan_set_privacy_mode( U32 drv_handler, U32 data )*/
  224. /* {*/
  225. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_PRIVACY_MODE_SET, &data, sizeof(data) );*/
  226. /* }*/
  227. /* */
  228. /* int tiwlan_get_privacy_mode( U32 drv_handler, U32 *p_data )*/
  229. /* {*/
  230. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_PRIVACY_MODE_GET, p_data, sizeof(*p_data) );*/
  231. /* }*/
  232. /* */
  233. /* int tiwlan_set_exc_security_type( U32 drv_handler, U32 data )*/
  234. /* {*/
  235. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_EXC_SECURITY_TYPE_SET, &data, sizeof(data) );*/
  236. /* }*/
  237. /* */
  238. /* int tiwlan_get_exc_security_type( U32 drv_handler, U32 *p_data )*/
  239. /* {*/
  240. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_EXC_SECURITY_TYPE_GET, p_data, sizeof(*p_data) );*/
  241. /* }*/
  242. /* int tiwlan_set_tx_power_val( U32 drv_handler, U32 data )*/
  243. /* {*/
  244. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_TX_POWER_VALUE_SET, &data, sizeof(data) );*/
  245. /* }*/
  246. /* */
  247. /* int tiwlan_get_tx_power_val( U32 drv_handler, U32 *p_data )*/
  248. /* {*/
  249. /* print_deb("===GET_TX_POWER_VAL: %d\n", TIWLN_TX_POWER_VALUE_GET );*/
  250. /* return tiwlan_get_ioctl( g_id_adapter, -1, TIWLN_TX_POWER_VALUE_GET, p_data, sizeof(*p_data) );*/
  251. /* }*/
  252. /* */
  253. /* int tiwlan_get_current_mac( TI_HANDLE drv_handler, OS_802_11_MAC_ADDRESS *data)*/
  254. /* {*/
  255. /* return IPC_DeviceIoControl(drv_handler, TIWLN_802_3_CURRENT_ADDRESS, NULL, 0, data, sizeof(*data), NULL);*/
  256. /* }*/
  257. /* int tiwlan_get_current_channel(TI_HANDLE drv_handler, tiUINT32 *data)*/
  258. /* {*/
  259. /* return IPC_DeviceIoControl( drv_handler, TIWLN_802_11_CHANNEL_GET, NULL, 0, data, sizeof(data), NULL );*/
  260. /* }*/
  261. /* int tiwlan_get_desired_ssid(TI_HANDLE drv_handler, char *data)*/
  262. /* {*/
  263. /* OS_802_11_SSID ssid = { 0 };*/
  264. /* int res = IPC_DeviceIoControl( drv_handler, TIWLN_802_11_DESIRED_SSID_GET, NULL, 0, &ssid, sizeof(OS_802_11_SSID), NULL );*/
  265. /* if( !res )*/
  266. /* {*/
  267. /* memmove(data, ssid.Ssid, ssid.SsidLength );*/
  268. /* data[ssid.SsidLength] = 0;*/
  269. /* }*/
  270. /* return res;*/
  271. /* }*/
  272. void print_memory_dump(char *addr, int size )
  273. {
  274. int i;
  275. char buf[4096];
  276. if( size * 4 > sizeof(buf) )
  277. {
  278. print_err("print_memory_dump(): buffer too small\n");
  279. return;
  280. }
  281. buf[0] = 0;
  282. for(i=0; i<size; i++ )
  283. {
  284. if( !(i % 16) )
  285. sprintf(&buf[strlen(buf)], "%sTI_CU:%p: ", (i) ? "\n" : "", addr+i );
  286. sprintf(&buf[strlen(buf)], "%02x ", (unsigned char) addr[i] );
  287. }
  288. print_deb("%s\n", buf);
  289. }