rtw_android.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #include <drv_types.h>
  21. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  22. #include <linux/platform_device.h>
  23. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  24. #include <linux/wlan_plat.h>
  25. #else
  26. #include <linux/wifi_tiwlan.h>
  27. #endif
  28. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */
  29. const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
  30. "START",
  31. "STOP",
  32. "SCAN-ACTIVE",
  33. "SCAN-PASSIVE",
  34. "RSSI",
  35. "LINKSPEED",
  36. "RXFILTER-START",
  37. "RXFILTER-STOP",
  38. "RXFILTER-ADD",
  39. "RXFILTER-REMOVE",
  40. "BTCOEXSCAN-START",
  41. "BTCOEXSCAN-STOP",
  42. "BTCOEXMODE",
  43. "SETSUSPENDOPT",
  44. "P2P_DEV_ADDR",
  45. "SETFWPATH",
  46. "SETBAND",
  47. "GETBAND",
  48. "COUNTRY",
  49. "P2P_SET_NOA",
  50. "P2P_GET_NOA",
  51. "P2P_SET_PS",
  52. "SET_AP_WPS_P2P_IE",
  53. #ifdef PNO_SUPPORT
  54. "PNOSSIDCLR",
  55. "PNOSETUP ",
  56. "PNOFORCE",
  57. "PNODEBUG",
  58. #endif
  59. "MACADDR",
  60. "BLOCK",
  61. "WFD-ENABLE",
  62. "WFD-DISABLE",
  63. "WFD-SET-TCPPORT",
  64. "WFD-SET-MAXTPUT",
  65. "WFD-SET-DEVTYPE",
  66. };
  67. #ifdef PNO_SUPPORT
  68. #define PNO_TLV_PREFIX 'S'
  69. #define PNO_TLV_VERSION '1'
  70. #define PNO_TLV_SUBVERSION '2'
  71. #define PNO_TLV_RESERVED '0'
  72. #define PNO_TLV_TYPE_SSID_IE 'S'
  73. #define PNO_TLV_TYPE_TIME 'T'
  74. #define PNO_TLV_FREQ_REPEAT 'R'
  75. #define PNO_TLV_FREQ_EXPO_MAX 'M'
  76. typedef struct cmd_tlv {
  77. char prefix;
  78. char version;
  79. char subver;
  80. char reserved;
  81. } cmd_tlv_t;
  82. #endif /* PNO_SUPPORT */
  83. typedef struct android_wifi_priv_cmd {
  84. #ifdef CONFIG_COMPAT
  85. compat_uptr_t buf;
  86. #else
  87. char *buf;
  88. #endif
  89. int used_len;
  90. int total_len;
  91. } android_wifi_priv_cmd;
  92. /**
  93. * Local (static) functions and variables
  94. */
  95. /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
  96. * time (only) in dhd_open, subsequential wifi on will be handled by
  97. * wl_android_wifi_on
  98. */
  99. static int g_wifi_on = _TRUE;
  100. #ifdef PNO_SUPPORT
  101. static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len)
  102. {
  103. wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT];
  104. int res = -1;
  105. int nssid = 0;
  106. cmd_tlv_t *cmd_tlv_temp;
  107. char *str_ptr;
  108. int tlv_size_left;
  109. int pno_time = 0;
  110. int pno_repeat = 0;
  111. int pno_freq_expo_max = 0;
  112. #ifdef PNO_SET_DEBUG
  113. int i;
  114. char pno_in_example[] = {
  115. 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
  116. 'S', '1', '2', '0',
  117. 'S',
  118. 0x05,
  119. 'd', 'l', 'i', 'n', 'k',
  120. 'S',
  121. 0x04,
  122. 'G', 'O', 'O', 'G',
  123. 'T',
  124. '0', 'B',
  125. 'R',
  126. '2',
  127. 'M',
  128. '2',
  129. 0x00
  130. };
  131. #endif /* PNO_SET_DEBUG */
  132. DHD_INFO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
  133. if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) {
  134. DBG_871X("%s argument=%d less min size\n", __FUNCTION__, total_len);
  135. goto exit_proc;
  136. }
  137. #ifdef PNO_SET_DEBUG
  138. memcpy(command, pno_in_example, sizeof(pno_in_example));
  139. for (i = 0; i < sizeof(pno_in_example); i++)
  140. printf("%02X ", command[i]);
  141. printf("\n");
  142. total_len = sizeof(pno_in_example);
  143. #endif
  144. str_ptr = command + strlen(CMD_PNOSETUP_SET);
  145. tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET);
  146. cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
  147. memset(ssids_local, 0, sizeof(ssids_local));
  148. if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
  149. (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
  150. (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) {
  151. str_ptr += sizeof(cmd_tlv_t);
  152. tlv_size_left -= sizeof(cmd_tlv_t);
  153. if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
  154. MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) {
  155. DBG_871X("SSID is not presented or corrupted ret=%d\n", nssid);
  156. goto exit_proc;
  157. } else {
  158. if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
  159. DBG_871X("%s scan duration corrupted field size %d\n",
  160. __FUNCTION__, tlv_size_left);
  161. goto exit_proc;
  162. }
  163. str_ptr++;
  164. pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
  165. DHD_INFO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
  166. if (str_ptr[0] != 0) {
  167. if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
  168. DBG_871X("%s pno repeat : corrupted field\n",
  169. __FUNCTION__);
  170. goto exit_proc;
  171. }
  172. str_ptr++;
  173. pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
  174. DHD_INFO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat));
  175. if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
  176. DBG_871X("%s FREQ_EXPO_MAX corrupted field size\n",
  177. __FUNCTION__);
  178. goto exit_proc;
  179. }
  180. str_ptr++;
  181. pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
  182. DHD_INFO(("%s: pno_freq_expo_max=%d\n",
  183. __FUNCTION__, pno_freq_expo_max));
  184. }
  185. }
  186. } else {
  187. DBG_871X("%s get wrong TLV command\n", __FUNCTION__);
  188. goto exit_proc;
  189. }
  190. res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
  191. exit_proc:
  192. return res;
  193. }
  194. #endif /* PNO_SUPPORT */
  195. int rtw_android_cmdstr_to_num(char *cmdstr)
  196. {
  197. int cmd_num;
  198. for(cmd_num=0 ; cmd_num<ANDROID_WIFI_CMD_MAX; cmd_num++)
  199. if(0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])) )
  200. break;
  201. return cmd_num;
  202. }
  203. int rtw_android_get_rssi(struct net_device *net, char *command, int total_len)
  204. {
  205. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  206. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  207. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  208. int bytes_written = 0;
  209. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  210. bytes_written += snprintf(&command[bytes_written], total_len, "%s rssi %d",
  211. pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
  212. }
  213. return bytes_written;
  214. }
  215. int rtw_android_get_link_speed(struct net_device *net, char *command, int total_len)
  216. {
  217. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  218. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  219. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  220. int bytes_written = 0;
  221. u16 link_speed = 0;
  222. link_speed = rtw_get_cur_max_rate(padapter)/10;
  223. bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
  224. return bytes_written;
  225. }
  226. int rtw_android_get_macaddr(struct net_device *net, char *command, int total_len)
  227. {
  228. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  229. int bytes_written = 0;
  230. bytes_written = snprintf(command, total_len, "Macaddr = "MAC_FMT, MAC_ARG(net->dev_addr));
  231. return bytes_written;
  232. }
  233. int rtw_android_set_country(struct net_device *net, char *command, int total_len)
  234. {
  235. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  236. char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
  237. int ret;
  238. ret = rtw_set_country(adapter, country_code);
  239. return (ret==_SUCCESS)?0:-1;
  240. }
  241. int rtw_android_get_p2p_dev_addr(struct net_device *net, char *command, int total_len)
  242. {
  243. int ret;
  244. int bytes_written = 0;
  245. //We use the same address as our HW MAC address
  246. _rtw_memcpy(command, net->dev_addr, ETH_ALEN);
  247. bytes_written = ETH_ALEN;
  248. return bytes_written;
  249. }
  250. int rtw_android_set_block(struct net_device *net, char *command, int total_len)
  251. {
  252. int ret;
  253. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  254. char *block_value = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_BLOCK]) + 1;
  255. #ifdef CONFIG_IOCTL_CFG80211
  256. wdev_to_priv(adapter->rtw_wdev)->block = (*block_value=='0')?_FALSE:_TRUE;
  257. #endif
  258. return 0;
  259. }
  260. int get_int_from_command( char* pcmd )
  261. {
  262. int i = 0;
  263. for( i = 0; i < strlen( pcmd ); i++ )
  264. {
  265. if ( pcmd[ i ] == '=' )
  266. {
  267. // Skip the '=' and space characters.
  268. i += 2;
  269. break;
  270. }
  271. }
  272. return ( rtw_atoi( pcmd + i ) );
  273. }
  274. int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
  275. {
  276. int ret = 0;
  277. char *command = NULL;
  278. int cmd_num;
  279. int bytes_written = 0;
  280. android_wifi_priv_cmd priv_cmd;
  281. rtw_lock_suspend();
  282. if (!ifr->ifr_data) {
  283. ret = -EINVAL;
  284. goto exit;
  285. }
  286. if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
  287. ret = -EFAULT;
  288. goto exit;
  289. }
  290. //DBG_871X("%s priv_cmd.buf=%p priv_cmd.total_len=%d priv_cmd.used_len=%d\n",__func__,priv_cmd.buf,priv_cmd.total_len,priv_cmd.used_len);
  291. command = rtw_zmalloc(priv_cmd.total_len);
  292. if (!command)
  293. {
  294. DBG_871X("%s: failed to allocate memory\n", __FUNCTION__);
  295. ret = -ENOMEM;
  296. goto exit;
  297. }
  298. if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)){
  299. DBG_871X("%s: failed to access memory\n", __FUNCTION__);
  300. ret = -EFAULT;
  301. goto exit;
  302. }
  303. if (copy_from_user(command, (void *)priv_cmd.buf, priv_cmd.total_len)) {
  304. ret = -EFAULT;
  305. goto exit;
  306. }
  307. DBG_871X("%s: Android private cmd \"%s\" on %s\n"
  308. , __FUNCTION__, command, ifr->ifr_name);
  309. cmd_num = rtw_android_cmdstr_to_num(command);
  310. switch(cmd_num) {
  311. case ANDROID_WIFI_CMD_START:
  312. //bytes_written = wl_android_wifi_on(net);
  313. goto response;
  314. case ANDROID_WIFI_CMD_SETFWPATH:
  315. goto response;
  316. }
  317. if (!g_wifi_on) {
  318. DBG_871X("%s: Ignore private cmd \"%s\" - iface %s is down\n"
  319. ,__FUNCTION__, command, ifr->ifr_name);
  320. ret = 0;
  321. goto exit;
  322. }
  323. switch(cmd_num) {
  324. case ANDROID_WIFI_CMD_STOP:
  325. //bytes_written = wl_android_wifi_off(net);
  326. break;
  327. case ANDROID_WIFI_CMD_SCAN_ACTIVE:
  328. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_ACTIVE);
  329. #ifdef CONFIG_PLATFORM_MSTAR_TITANIA12
  330. #ifdef CONFIG_IOCTL_CFG80211
  331. (wdev_to_priv(net->ieee80211_ptr))->bandroid_scan = _TRUE;
  332. #endif //CONFIG_IOCTL_CFG80211
  333. #endif //CONFIG_PLATFORM_MSTAR_TITANIA12
  334. break;
  335. case ANDROID_WIFI_CMD_SCAN_PASSIVE:
  336. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_PASSIVE);
  337. break;
  338. case ANDROID_WIFI_CMD_RSSI:
  339. bytes_written = rtw_android_get_rssi(net, command, priv_cmd.total_len);
  340. break;
  341. case ANDROID_WIFI_CMD_LINKSPEED:
  342. bytes_written = rtw_android_get_link_speed(net, command, priv_cmd.total_len);
  343. break;
  344. case ANDROID_WIFI_CMD_MACADDR:
  345. bytes_written = rtw_android_get_macaddr(net, command, priv_cmd.total_len);
  346. break;
  347. case ANDROID_WIFI_CMD_BLOCK:
  348. bytes_written = rtw_android_set_block(net, command, priv_cmd.total_len);
  349. break;
  350. case ANDROID_WIFI_CMD_RXFILTER_START:
  351. //bytes_written = net_os_set_packet_filter(net, 1);
  352. break;
  353. case ANDROID_WIFI_CMD_RXFILTER_STOP:
  354. //bytes_written = net_os_set_packet_filter(net, 0);
  355. break;
  356. case ANDROID_WIFI_CMD_RXFILTER_ADD:
  357. //int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
  358. //bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
  359. break;
  360. case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
  361. //int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
  362. //bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
  363. break;
  364. case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
  365. /* TBD: BTCOEXSCAN-START */
  366. break;
  367. case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
  368. /* TBD: BTCOEXSCAN-STOP */
  369. break;
  370. case ANDROID_WIFI_CMD_BTCOEXMODE:
  371. #if 0
  372. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  373. if (mode == 1)
  374. net_os_set_packet_filter(net, 0); /* DHCP starts */
  375. else
  376. net_os_set_packet_filter(net, 1); /* DHCP ends */
  377. #ifdef WL_CFG80211
  378. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
  379. #endif
  380. #endif
  381. break;
  382. case ANDROID_WIFI_CMD_SETSUSPENDOPT:
  383. //bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
  384. break;
  385. case ANDROID_WIFI_CMD_SETBAND:
  386. {
  387. uint band = *(command + strlen("SETBAND") + 1) - '0';
  388. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  389. if (padapter->chip_type == RTL8192D)
  390. padapter->setband = band;
  391. break;
  392. }
  393. case ANDROID_WIFI_CMD_GETBAND:
  394. //bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
  395. break;
  396. case ANDROID_WIFI_CMD_COUNTRY:
  397. bytes_written = rtw_android_set_country(net, command, priv_cmd.total_len);
  398. break;
  399. #ifdef PNO_SUPPORT
  400. case ANDROID_WIFI_CMD_PNOSSIDCLR_SET:
  401. //bytes_written = dhd_dev_pno_reset(net);
  402. break;
  403. case ANDROID_WIFI_CMD_PNOSETUP_SET:
  404. //bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
  405. break;
  406. case ANDROID_WIFI_CMD_PNOENABLE_SET:
  407. //uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
  408. //bytes_written = dhd_dev_pno_enable(net, pfn_enabled);
  409. break;
  410. #endif
  411. case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
  412. bytes_written = rtw_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  413. break;
  414. case ANDROID_WIFI_CMD_P2P_SET_NOA:
  415. //int skip = strlen(CMD_P2P_SET_NOA) + 1;
  416. //bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip, priv_cmd.total_len - skip);
  417. break;
  418. case ANDROID_WIFI_CMD_P2P_GET_NOA:
  419. //bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
  420. break;
  421. case ANDROID_WIFI_CMD_P2P_SET_PS:
  422. //int skip = strlen(CMD_P2P_SET_PS) + 1;
  423. //bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip, priv_cmd.total_len - skip);
  424. break;
  425. #ifdef CONFIG_IOCTL_CFG80211
  426. case ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE:
  427. {
  428. int skip = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE]) + 3;
  429. bytes_written = rtw_cfg80211_set_mgnt_wpsp2pie(net, command + skip, priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  430. break;
  431. }
  432. #endif //CONFIG_IOCTL_CFG80211
  433. #ifdef CONFIG_WFD
  434. case ANDROID_WIFI_CMD_WFD_ENABLE:
  435. {
  436. // Commented by Albert 2012/07/24
  437. // We can enable the WFD function by using the following command:
  438. // wpa_cli driver wfd-enable
  439. struct wifi_display_info *pwfd_info;
  440. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  441. pwfd_info = &padapter->wfd_info;
  442. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  443. pwfd_info->wfd_enable = _TRUE;
  444. break;
  445. }
  446. case ANDROID_WIFI_CMD_WFD_DISABLE:
  447. {
  448. // Commented by Albert 2012/07/24
  449. // We can disable the WFD function by using the following command:
  450. // wpa_cli driver wfd-disable
  451. struct wifi_display_info *pwfd_info;
  452. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  453. pwfd_info = &padapter->wfd_info;
  454. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  455. pwfd_info->wfd_enable = _FALSE;
  456. break;
  457. }
  458. case ANDROID_WIFI_CMD_WFD_SET_TCPPORT:
  459. {
  460. // Commented by Albert 2012/07/24
  461. // We can set the tcp port number by using the following command:
  462. // wpa_cli driver wfd-set-tcpport = 554
  463. struct wifi_display_info *pwfd_info;
  464. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  465. pwfd_info = &padapter->wfd_info;
  466. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  467. pwfd_info->rtsp_ctrlport = ( u16 ) get_int_from_command( priv_cmd.buf );
  468. break;
  469. }
  470. case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT:
  471. {
  472. break;
  473. }
  474. case ANDROID_WIFI_CMD_WFD_SET_DEVTYPE:
  475. {
  476. // Commented by Albert 2012/08/28
  477. // Specify the WFD device type ( WFD source/primary sink )
  478. struct wifi_display_info *pwfd_info;
  479. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  480. pwfd_info = &padapter->wfd_info;
  481. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  482. {
  483. pwfd_info->wfd_device_type = ( u8 ) get_int_from_command( priv_cmd.buf );
  484. pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
  485. }
  486. break;
  487. }
  488. #endif
  489. default:
  490. DBG_871X("Unknown PRIVATE command %s - ignored\n", command);
  491. snprintf(command, 3, "OK");
  492. bytes_written = strlen("OK");
  493. }
  494. response:
  495. if (bytes_written >= 0) {
  496. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  497. command[0] = '\0';
  498. if (bytes_written >= priv_cmd.total_len) {
  499. DBG_871X("%s: bytes_written = %d\n", __FUNCTION__, bytes_written);
  500. bytes_written = priv_cmd.total_len;
  501. } else {
  502. bytes_written++;
  503. }
  504. priv_cmd.used_len = bytes_written;
  505. if (copy_to_user((void *)priv_cmd.buf, command, bytes_written)) {
  506. DBG_871X("%s: failed to copy data to user buffer\n", __FUNCTION__);
  507. ret = -EFAULT;
  508. }
  509. }
  510. else {
  511. ret = bytes_written;
  512. }
  513. exit:
  514. rtw_unlock_suspend();
  515. if (command) {
  516. kfree(command);
  517. }
  518. return ret;
  519. }
  520. /**
  521. * Functions for Android WiFi card detection
  522. */
  523. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  524. static int g_wifidev_registered = 0;
  525. static struct semaphore wifi_control_sem;
  526. static struct wifi_platform_data *wifi_control_data = NULL;
  527. static struct resource *wifi_irqres = NULL;
  528. static int wifi_add_dev(void);
  529. static void wifi_del_dev(void);
  530. int rtw_android_wifictrl_func_add(void)
  531. {
  532. int ret = 0;
  533. sema_init(&wifi_control_sem, 0);
  534. ret = wifi_add_dev();
  535. if (ret) {
  536. DBG_871X("%s: platform_driver_register failed\n", __FUNCTION__);
  537. return ret;
  538. }
  539. g_wifidev_registered = 1;
  540. /* Waiting callback after platform_driver_register is done or exit with error */
  541. if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
  542. ret = -EINVAL;
  543. DBG_871X("%s: platform_driver_register timeout\n", __FUNCTION__);
  544. }
  545. return ret;
  546. }
  547. void rtw_android_wifictrl_func_del(void)
  548. {
  549. if (g_wifidev_registered)
  550. {
  551. wifi_del_dev();
  552. g_wifidev_registered = 0;
  553. }
  554. }
  555. void *wl_android_prealloc(int section, unsigned long size)
  556. {
  557. void *alloc_ptr = NULL;
  558. if (wifi_control_data && wifi_control_data->mem_prealloc) {
  559. alloc_ptr = wifi_control_data->mem_prealloc(section, size);
  560. if (alloc_ptr) {
  561. DBG_871X("success alloc section %d\n", section);
  562. if (size != 0L)
  563. memset(alloc_ptr, 0, size);
  564. return alloc_ptr;
  565. }
  566. }
  567. DBG_871X("can't alloc section %d\n", section);
  568. return NULL;
  569. }
  570. int wifi_get_irq_number(unsigned long *irq_flags_ptr)
  571. {
  572. if (wifi_irqres) {
  573. *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
  574. return (int)wifi_irqres->start;
  575. }
  576. #ifdef CUSTOM_OOB_GPIO_NUM
  577. return CUSTOM_OOB_GPIO_NUM;
  578. #else
  579. return -1;
  580. #endif
  581. }
  582. int wifi_set_power(int on, unsigned long msec)
  583. {
  584. DBG_871X("%s = %d\n", __FUNCTION__, on);
  585. if (wifi_control_data && wifi_control_data->set_power) {
  586. wifi_control_data->set_power(on);
  587. }
  588. if (msec)
  589. msleep(msec);
  590. return 0;
  591. }
  592. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  593. int wifi_get_mac_addr(unsigned char *buf)
  594. {
  595. DBG_871X("%s\n", __FUNCTION__);
  596. if (!buf)
  597. return -EINVAL;
  598. if (wifi_control_data && wifi_control_data->get_mac_addr) {
  599. return wifi_control_data->get_mac_addr(buf);
  600. }
  601. return -EOPNOTSUPP;
  602. }
  603. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
  604. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) || defined(COMPAT_KERNEL_RELEASE)
  605. void *wifi_get_country_code(char *ccode)
  606. {
  607. DBG_871X("%s\n", __FUNCTION__);
  608. if (!ccode)
  609. return NULL;
  610. if (wifi_control_data && wifi_control_data->get_country_code) {
  611. return wifi_control_data->get_country_code(ccode);
  612. }
  613. return NULL;
  614. }
  615. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  616. static int wifi_set_carddetect(int on)
  617. {
  618. DBG_871X("%s = %d\n", __FUNCTION__, on);
  619. if (wifi_control_data && wifi_control_data->set_carddetect) {
  620. wifi_control_data->set_carddetect(on);
  621. }
  622. return 0;
  623. }
  624. static int wifi_probe(struct platform_device *pdev)
  625. {
  626. struct wifi_platform_data *wifi_ctrl =
  627. (struct wifi_platform_data *)(pdev->dev.platform_data);
  628. DBG_871X("## %s\n", __FUNCTION__);
  629. wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  630. if (wifi_irqres == NULL)
  631. wifi_irqres = platform_get_resource_byname(pdev,
  632. IORESOURCE_IRQ, "bcm4329_wlan_irq");
  633. wifi_control_data = wifi_ctrl;
  634. wifi_set_power(1, 0); /* Power On */
  635. wifi_set_carddetect(1); /* CardDetect (0->1) */
  636. up(&wifi_control_sem);
  637. return 0;
  638. }
  639. static int wifi_remove(struct platform_device *pdev)
  640. {
  641. struct wifi_platform_data *wifi_ctrl =
  642. (struct wifi_platform_data *)(pdev->dev.platform_data);
  643. DBG_871X("## %s\n", __FUNCTION__);
  644. wifi_control_data = wifi_ctrl;
  645. wifi_set_power(0, 0); /* Power Off */
  646. wifi_set_carddetect(0); /* CardDetect (1->0) */
  647. up(&wifi_control_sem);
  648. return 0;
  649. }
  650. static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
  651. {
  652. DBG_871X("##> %s\n", __FUNCTION__);
  653. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  654. bcmsdh_oob_intr_set(0);
  655. #endif
  656. return 0;
  657. }
  658. static int wifi_resume(struct platform_device *pdev)
  659. {
  660. DBG_871X("##> %s\n", __FUNCTION__);
  661. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  662. if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
  663. bcmsdh_oob_intr_set(1);
  664. #endif
  665. return 0;
  666. }
  667. /* temporarily use these two */
  668. static struct platform_driver wifi_device = {
  669. .probe = wifi_probe,
  670. .remove = wifi_remove,
  671. .suspend = wifi_suspend,
  672. .resume = wifi_resume,
  673. .driver = {
  674. .name = "bcmdhd_wlan",
  675. }
  676. };
  677. static struct platform_driver wifi_device_legacy = {
  678. .probe = wifi_probe,
  679. .remove = wifi_remove,
  680. .suspend = wifi_suspend,
  681. .resume = wifi_resume,
  682. .driver = {
  683. .name = "bcm4329_wlan",
  684. }
  685. };
  686. static int wifi_add_dev(void)
  687. {
  688. DBG_871X("## Calling platform_driver_register\n");
  689. platform_driver_register(&wifi_device);
  690. platform_driver_register(&wifi_device_legacy);
  691. return 0;
  692. }
  693. static void wifi_del_dev(void)
  694. {
  695. DBG_871X("## Unregister platform_driver_register\n");
  696. platform_driver_unregister(&wifi_device);
  697. platform_driver_unregister(&wifi_device_legacy);
  698. }
  699. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */