PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/bcmdhd/wl_android.c

https://bitbucket.org/arter97/arter97-cm-i9300
C | 2560 lines | 2100 code | 364 blank | 96 comment | 480 complexity | e79d2cfe161750fb625461f3a16e927b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Linux cfg80211 driver - Android related functions
  3. *
  4. * Copyright (C) 1999-2012, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: wl_android.c 393894 2013-03-29 07:14:35Z $
  25. */
  26. #include <linux/module.h>
  27. #include <linux/netdevice.h>
  28. #include <wl_android.h>
  29. #include <wldev_common.h>
  30. #include <wlioctl.h>
  31. #include <bcmutils.h>
  32. #include <linux_osl.h>
  33. #include <dhd_dbg.h>
  34. #include <dngl_stats.h>
  35. #include <dhd.h>
  36. #include <bcmsdbus.h>
  37. #ifdef WL_CFG80211
  38. #include <wl_cfg80211.h>
  39. #endif
  40. #if defined(CONFIG_WIFI_CONTROL_FUNC)
  41. #include <linux/platform_device.h>
  42. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  43. #include <linux/wlan_plat.h>
  44. #else
  45. #include <linux/wifi_tiwlan.h>
  46. #endif
  47. #endif /* CONFIG_WIFI_CONTROL_FUNC */
  48. /*
  49. * Android private command strings, PLEASE define new private commands here
  50. * so they can be updated easily in the future (if needed)
  51. */
  52. #define CMD_START "START"
  53. #define CMD_STOP "STOP"
  54. #define CMD_SCAN_ACTIVE "SCAN-ACTIVE"
  55. #define CMD_SCAN_PASSIVE "SCAN-PASSIVE"
  56. #define CMD_RSSI "RSSI"
  57. #define CMD_LINKSPEED "LINKSPEED"
  58. #define CMD_RXFILTER_START "RXFILTER-START"
  59. #define CMD_RXFILTER_STOP "RXFILTER-STOP"
  60. #define CMD_RXFILTER_ADD "RXFILTER-ADD"
  61. #define CMD_RXFILTER_REMOVE "RXFILTER-REMOVE"
  62. #define CMD_BTCOEXSCAN_START "BTCOEXSCAN-START"
  63. #define CMD_BTCOEXSCAN_STOP "BTCOEXSCAN-STOP"
  64. #define CMD_BTCOEXMODE "BTCOEXMODE"
  65. #define CMD_SETSUSPENDOPT "SETSUSPENDOPT"
  66. #define CMD_SETSUSPENDMODE "SETSUSPENDMODE"
  67. #define CMD_P2P_DEV_ADDR "P2P_DEV_ADDR"
  68. #define CMD_SETFWPATH "SETFWPATH"
  69. #define CMD_SETBAND "SETBAND"
  70. #define CMD_GETBAND "GETBAND"
  71. #define CMD_COUNTRY "COUNTRY"
  72. #define CMD_P2P_SET_NOA "P2P_SET_NOA"
  73. #if !defined WL_ENABLE_P2P_IF
  74. #define CMD_P2P_GET_NOA "P2P_GET_NOA"
  75. #endif
  76. #define CMD_P2P_SD_OFFLOAD "P2P_SD_"
  77. #define CMD_P2P_SET_PS "P2P_SET_PS"
  78. #define CMD_SET_AP_WPS_P2P_IE "SET_AP_WPS_P2P_IE"
  79. #define CMD_SETROAMMODE "SETROAMMODE"
  80. #ifdef CUSTOMER_HW4
  81. #ifdef SUPPORT_AUTO_CHANNEL
  82. #define CMD_SET_HAPD_AUTO_CHANNEL "HAPD_AUTO_CHANNEL"
  83. #endif /* SUPPORT_AUTO_CHANNEL */
  84. #ifdef SUPPORT_HIDDEN_AP
  85. /* Hostapd private command */
  86. #define CMD_SET_HAPD_MAX_NUM_STA "HAPD_MAX_NUM_STA"
  87. #define CMD_SET_HAPD_SSID "HAPD_SSID"
  88. #define CMD_SET_HAPD_HIDE_SSID "HAPD_HIDE_SSID"
  89. #endif /* SUPPORT_HIDDEN_AP */
  90. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  91. #define CMD_HAPD_STA_DISASSOC "HAPD_STA_DISASSOC"
  92. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  93. #ifdef SUPPORT_SET_LPC
  94. #define CMD_HAPD_LPC_ENABLED "HAPD_LPC_ENABLED"
  95. #endif /* SUPPORT_SET_LPC */
  96. #ifdef SUPPORT_TRIGGER_HANG_EVENT
  97. #define CMD_TEST_FORCE_HANG "TEST_FORCE_HANG"
  98. #endif /* SUPPORT_TRIGGER_HANG_EVENT */
  99. #endif /* CUSTOMER_HW4 */
  100. /* CCX Private Commands */
  101. #ifdef BCMCCX
  102. #define CMD_GETCCKM_RN "get cckm_rn"
  103. #define CMD_SETCCKM_KRK "set cckm_krk"
  104. #define CMD_GET_ASSOC_RES_IES "get assoc_res_ies"
  105. #endif
  106. #ifdef PNO_SUPPORT
  107. #define CMD_PNOSSIDCLR_SET "PNOSSIDCLR"
  108. #define CMD_PNOSETUP_SET "PNOSETUP "
  109. #define CMD_PNOENABLE_SET "PNOFORCE"
  110. #define CMD_PNODEBUG_SET "PNODEBUG"
  111. #define PNO_TLV_PREFIX 'S'
  112. #define PNO_TLV_VERSION '1'
  113. #define PNO_TLV_SUBVERSION '2'
  114. #define PNO_TLV_RESERVED '0'
  115. #define PNO_TLV_TYPE_SSID_IE 'S'
  116. #define PNO_TLV_TYPE_TIME 'T'
  117. #define PNO_TLV_FREQ_REPEAT 'R'
  118. #define PNO_TLV_FREQ_EXPO_MAX 'M'
  119. typedef struct cmd_tlv {
  120. char prefix;
  121. char version;
  122. char subver;
  123. char reserved;
  124. } cmd_tlv_t;
  125. #endif /* PNO_SUPPORT */
  126. #define CMD_OKC_SET_PMK "SET_PMK"
  127. #define CMD_OKC_ENABLE "OKC_ENABLE"
  128. #ifdef CUSTOMER_HW4
  129. #ifdef ROAM_API
  130. #define CMD_ROAMTRIGGER_SET "SETROAMTRIGGER"
  131. #define CMD_ROAMTRIGGER_GET "GETROAMTRIGGER"
  132. #define CMD_ROAMDELTA_SET "SETROAMDELTA"
  133. #define CMD_ROAMDELTA_GET "GETROAMDELTA"
  134. #define CMD_ROAMSCANPERIOD_SET "SETROAMSCANPERIOD"
  135. #define CMD_ROAMSCANPERIOD_GET "GETROAMSCANPERIOD"
  136. #define CMD_FULLROAMSCANPERIOD_SET "SETFULLROAMSCANPERIOD"
  137. #define CMD_FULLROAMSCANPERIOD_GET "GETFULLROAMSCANPERIOD"
  138. #define CMD_COUNTRYREV_SET "SETCOUNTRYREV"
  139. #define CMD_COUNTRYREV_GET "GETCOUNTRYREV"
  140. #endif /* ROAM_API */
  141. #ifdef WES_SUPPORT
  142. #define CMD_GETROAMSCANCONTROL "GETROAMSCANCONTROL"
  143. #define CMD_SETROAMSCANCONTROL "SETROAMSCANCONTROL"
  144. #define CMD_GETROAMSCANCHANNELS "GETROAMSCANCHANNELS"
  145. #define CMD_SETROAMSCANCHANNELS "SETROAMSCANCHANNELS"
  146. #define CMD_GETSCANCHANNELTIME "GETSCANCHANNELTIME"
  147. #define CMD_SETSCANCHANNELTIME "SETSCANCHANNELTIME"
  148. #define CMD_GETSCANHOMETIME "GETSCANHOMETIME"
  149. #define CMD_SETSCANHOMETIME "SETSCANHOMETIME"
  150. #define CMD_GETSCANHOMEAWAYTIME "GETSCANHOMEAWAYTIME"
  151. #define CMD_SETSCANHOMEAWAYTIME "SETSCANHOMEAWAYTIME"
  152. #define CMD_GETSCANNPROBES "GETSCANNPROBES"
  153. #define CMD_SETSCANNPROBES "SETSCANNPROBES"
  154. #define CMD_SENDACTIONFRAME "SENDACTIONFRAME"
  155. #define CMD_REASSOC "REASSOC"
  156. #define CMD_GETWESMODE "GETWESMODE"
  157. #define CMD_SETWESMODE "SETWESMODE"
  158. #define CMD_GETOKCMODE "GETOKCMODE"
  159. #define CMD_SETOKCMODE "SETOKCMODE"
  160. #define ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS 100
  161. typedef struct android_wifi_reassoc_params {
  162. unsigned char bssid[18];
  163. int channel;
  164. } android_wifi_reassoc_params_t;
  165. #define ANDROID_WIFI_REASSOC_PARAMS_SIZE sizeof(struct android_wifi_reassoc_params)
  166. #define ANDROID_WIFI_ACTION_FRAME_SIZE 1040
  167. typedef struct android_wifi_af_params {
  168. unsigned char bssid[18];
  169. int channel;
  170. int dwell_time;
  171. int len;
  172. unsigned char data[ANDROID_WIFI_ACTION_FRAME_SIZE];
  173. } android_wifi_af_params_t;
  174. #define ANDROID_WIFI_AF_PARAMS_SIZE sizeof(struct android_wifi_af_params)
  175. #endif /* WES_SUPPORT */
  176. #ifdef SUPPORT_AMPDU_MPDU_CMD
  177. #define CMD_AMPDU_MPDU "AMPDU_MPDU"
  178. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  179. #define CMD_CHANGE_RL "CHANGE_RL"
  180. #define CMD_RESTORE_RL "RESTORE_RL"
  181. #endif /* CUSTOMER_HW4 */
  182. typedef struct android_wifi_priv_cmd {
  183. char *buf;
  184. int used_len;
  185. int total_len;
  186. } android_wifi_priv_cmd;
  187. #ifdef WL_GENL
  188. static s32 wl_genl_handle_msg(struct sk_buff *skb, struct genl_info *info);
  189. static int wl_genl_init(void);
  190. static int wl_genl_deinit(void);
  191. extern struct net init_net;
  192. /* attribute policy: defines which attribute has which type (e.g int, char * etc)
  193. * possible values defined in net/netlink.h
  194. */
  195. static struct nla_policy wl_genl_policy[BCM_GENL_ATTR_MAX + 1] = {
  196. [BCM_GENL_ATTR_STRING] = { .type = NLA_NUL_STRING },
  197. [BCM_GENL_ATTR_MSG] = { .type = NLA_BINARY },
  198. };
  199. #define WL_GENL_VER 1
  200. /* family definition */
  201. static struct genl_family wl_genl_family = {
  202. .id = GENL_ID_GENERATE, /* Genetlink would generate the ID */
  203. .hdrsize = 0,
  204. .name = "bcm-genl", /* Netlink I/F for Android */
  205. .version = WL_GENL_VER, /* Version Number */
  206. .maxattr = BCM_GENL_ATTR_MAX,
  207. };
  208. /* commands: mapping between the command enumeration and the actual function */
  209. struct genl_ops wl_genl_ops = {
  210. .cmd = BCM_GENL_CMD_MSG,
  211. .flags = 0,
  212. .policy = wl_genl_policy,
  213. .doit = wl_genl_handle_msg,
  214. .dumpit = NULL,
  215. };
  216. static struct genl_multicast_group wl_genl_mcast = {
  217. .id = GENL_ID_GENERATE, /* Genetlink would generate the ID */
  218. .name = "bcm-genl-mcast",
  219. };
  220. #endif /* WL_GENL */
  221. /**
  222. * Extern function declarations (TODO: move them to dhd_linux.h)
  223. */
  224. void dhd_customer_gpio_wlan_ctrl(int onoff);
  225. int dhd_dev_reset(struct net_device *dev, uint8 flag);
  226. int dhd_dev_init_ioctl(struct net_device *dev);
  227. #ifdef WL_CFG80211
  228. int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr);
  229. int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, char *command);
  230. #if defined(CUSTOMER_HW4) && defined(WES_SUPPORT)
  231. int wl_cfg80211_set_wes_mode(int mode);
  232. int wl_cfg80211_get_wes_mode(void);
  233. int wl_cfg80211_get_ioctl_version(void);
  234. #endif
  235. #else
  236. int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr)
  237. { return 0; }
  238. int wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len)
  239. { return 0; }
  240. int wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len)
  241. { return 0; }
  242. int wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len)
  243. { return 0; }
  244. #endif /* WK_CFG80211 */
  245. extern int dhd_os_check_if_up(void *dhdp);
  246. extern void *bcmsdh_get_drvdata(void);
  247. #if defined(PROP_TXSTATUS) && !defined(PROP_TXSTATUS_VSDB)
  248. extern int dhd_wlfc_init(dhd_pub_t *dhd);
  249. extern void dhd_wlfc_deinit(dhd_pub_t *dhd);
  250. #endif
  251. #if defined(CUSTOMER_HW4) && defined(WES_SUPPORT)
  252. /* wl_roam.c */
  253. extern int get_roamscan_mode(struct net_device *dev, int *mode);
  254. extern int set_roamscan_mode(struct net_device *dev, int mode);
  255. extern int get_roamscan_channel_list(struct net_device *dev, unsigned char channels[]);
  256. extern int set_roamscan_channel_list(struct net_device *dev, unsigned char n,
  257. unsigned char channels[], int ioctl_ver);
  258. #endif
  259. #ifdef ENABLE_4335BT_WAR
  260. extern int bcm_bt_lock(int cookie);
  261. extern void bcm_bt_unlock(int cookie);
  262. static int lock_cookie_wifi = 'W' | 'i'<<8 | 'F'<<16 | 'i'<<24; /* cookie is "WiFi" */
  263. #endif /* ENABLE_4335BT_WAR */
  264. extern bool ap_fw_loaded;
  265. #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW4)
  266. extern char iface_name[IFNAMSIZ];
  267. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  268. #ifndef WIFI_TURNOFF_DELAY
  269. #define WIFI_TURNOFF_DELAY 0
  270. #endif
  271. /**
  272. * Local (static) functions and variables
  273. */
  274. /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
  275. * time (only) in dhd_open, subsequential wifi on will be handled by
  276. * wl_android_wifi_on
  277. */
  278. static int g_wifi_on = TRUE;
  279. /**
  280. * Local (static) function definitions
  281. */
  282. static int wl_android_get_link_speed(struct net_device *net, char *command, int total_len)
  283. {
  284. int link_speed;
  285. int bytes_written;
  286. int error;
  287. error = wldev_get_link_speed(net, &link_speed);
  288. if (error)
  289. return -1;
  290. /* Convert Kbps to Android Mbps */
  291. link_speed = link_speed / 1000;
  292. bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
  293. DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command));
  294. return bytes_written;
  295. }
  296. static int wl_android_get_rssi(struct net_device *net, char *command, int total_len)
  297. {
  298. wlc_ssid_t ssid = {0};
  299. int rssi;
  300. int bytes_written = 0;
  301. int error;
  302. error = wldev_get_rssi(net, &rssi);
  303. if (error)
  304. return -1;
  305. error = wldev_get_ssid(net, &ssid);
  306. if (error)
  307. return -1;
  308. if ((ssid.SSID_len == 0) || (ssid.SSID_len > DOT11_MAX_SSID_LEN)) {
  309. DHD_ERROR(("%s: wldev_get_ssid failed\n", __FUNCTION__));
  310. } else {
  311. memcpy(command, ssid.SSID, ssid.SSID_len);
  312. bytes_written = ssid.SSID_len;
  313. }
  314. bytes_written += snprintf(&command[bytes_written], total_len, " rssi %d", rssi);
  315. DHD_INFO(("%s: command result is %s (%d)\n", __FUNCTION__, command, bytes_written));
  316. return bytes_written;
  317. }
  318. static int wl_android_set_suspendopt(struct net_device *dev, char *command, int total_len)
  319. {
  320. int suspend_flag;
  321. int ret_now;
  322. int ret = 0;
  323. #ifdef CUSTOMER_HW4
  324. if (!dhd_download_fw_on_driverload) {
  325. #endif /* CUSTOMER_HW4 */
  326. suspend_flag = *(command + strlen(CMD_SETSUSPENDOPT) + 1) - '0';
  327. if (suspend_flag != 0)
  328. suspend_flag = 1;
  329. ret_now = net_os_set_suspend_disable(dev, suspend_flag);
  330. if (ret_now != suspend_flag) {
  331. if (!(ret = net_os_set_suspend(dev, ret_now, 1)))
  332. DHD_INFO(("%s: Suspend Flag %d -> %d\n",
  333. __FUNCTION__, ret_now, suspend_flag));
  334. else
  335. DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret));
  336. }
  337. #ifdef CUSTOMER_HW4
  338. }
  339. #endif /* CUSTOMER_HW4 */
  340. return ret;
  341. }
  342. static int wl_android_set_suspendmode(struct net_device *dev, char *command, int total_len)
  343. {
  344. int ret = 0;
  345. #if !defined(CONFIG_HAS_EARLYSUSPEND) || !defined(DHD_USE_EARLYSUSPEND)
  346. int suspend_flag;
  347. suspend_flag = *(command + strlen(CMD_SETSUSPENDMODE) + 1) - '0';
  348. if (suspend_flag != 0)
  349. suspend_flag = 1;
  350. if (!(ret = net_os_set_suspend(dev, suspend_flag, 0)))
  351. DHD_INFO(("%s: Suspend Mode %d\n", __FUNCTION__, suspend_flag));
  352. else
  353. DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret));
  354. #endif
  355. return ret;
  356. }
  357. static int wl_android_get_band(struct net_device *dev, char *command, int total_len)
  358. {
  359. uint band;
  360. int bytes_written;
  361. int error;
  362. error = wldev_get_band(dev, &band);
  363. if (error)
  364. return -1;
  365. bytes_written = snprintf(command, total_len, "Band %d", band);
  366. return bytes_written;
  367. }
  368. #ifdef CUSTOMER_HW4
  369. #ifdef ROAM_API
  370. int wl_android_set_roam_trigger(
  371. struct net_device *dev, char* command, int total_len)
  372. {
  373. int roam_trigger[2];
  374. sscanf(command, "%*s %10d", &roam_trigger[0]);
  375. roam_trigger[1] = WLC_BAND_ALL;
  376. return wldev_ioctl(dev, WLC_SET_ROAM_TRIGGER, roam_trigger,
  377. sizeof(roam_trigger), 1);
  378. }
  379. static int wl_android_get_roam_trigger(
  380. struct net_device *dev, char *command, int total_len)
  381. {
  382. int bytes_written;
  383. int roam_trigger[2] = {0, 0};
  384. roam_trigger[1] = WLC_BAND_2G;
  385. if (wldev_ioctl(dev, WLC_GET_ROAM_TRIGGER, roam_trigger,
  386. sizeof(roam_trigger), 0)) {
  387. roam_trigger[1] = WLC_BAND_5G;
  388. if (wldev_ioctl(dev, WLC_GET_ROAM_TRIGGER, roam_trigger,
  389. sizeof(roam_trigger), 0))
  390. return -1;
  391. }
  392. bytes_written = snprintf(command, total_len, "%s %d",
  393. CMD_ROAMTRIGGER_GET, roam_trigger[0]);
  394. return bytes_written;
  395. }
  396. int wl_android_set_roam_delta(
  397. struct net_device *dev, char* command, int total_len)
  398. {
  399. int roam_delta[2];
  400. sscanf(command, "%*s %10d", &roam_delta[0]);
  401. roam_delta[1] = WLC_BAND_ALL;
  402. return wldev_ioctl(dev, WLC_SET_ROAM_DELTA, roam_delta,
  403. sizeof(roam_delta), 1);
  404. }
  405. static int wl_android_get_roam_delta(
  406. struct net_device *dev, char *command, int total_len)
  407. {
  408. int bytes_written;
  409. int roam_delta[2] = {0, 0};
  410. roam_delta[1] = WLC_BAND_2G;
  411. if (wldev_ioctl(dev, WLC_GET_ROAM_DELTA, roam_delta,
  412. sizeof(roam_delta), 0)) {
  413. roam_delta[1] = WLC_BAND_5G;
  414. if (wldev_ioctl(dev, WLC_GET_ROAM_DELTA, roam_delta,
  415. sizeof(roam_delta), 0))
  416. return -1;
  417. }
  418. bytes_written = snprintf(command, total_len, "%s %d",
  419. CMD_ROAMDELTA_GET, roam_delta[0]);
  420. return bytes_written;
  421. }
  422. int wl_android_set_roam_scan_period(
  423. struct net_device *dev, char* command, int total_len)
  424. {
  425. int roam_scan_period = 0;
  426. sscanf(command, "%*s %10d", &roam_scan_period);
  427. return wldev_ioctl(dev, WLC_SET_ROAM_SCAN_PERIOD, &roam_scan_period,
  428. sizeof(roam_scan_period), 1);
  429. }
  430. static int wl_android_get_roam_scan_period(
  431. struct net_device *dev, char *command, int total_len)
  432. {
  433. int bytes_written;
  434. int roam_scan_period = 0;
  435. if (wldev_ioctl(dev, WLC_GET_ROAM_SCAN_PERIOD, &roam_scan_period,
  436. sizeof(roam_scan_period), 0))
  437. return -1;
  438. bytes_written = snprintf(command, total_len, "%s %d",
  439. CMD_ROAMSCANPERIOD_GET, roam_scan_period);
  440. return bytes_written;
  441. }
  442. int wl_android_set_full_roam_scan_period(
  443. struct net_device *dev, char* command, int total_len)
  444. {
  445. int error = 0;
  446. int full_roam_scan_period = 0;
  447. char smbuf[WLC_IOCTL_SMLEN];
  448. sscanf(command+sizeof("SETFULLROAMSCANPERIOD"), "%d", &full_roam_scan_period);
  449. WL_TRACE(("fullroamperiod = %d\n", full_roam_scan_period));
  450. error = wldev_iovar_setbuf(dev, "fullroamperiod", &full_roam_scan_period,
  451. sizeof(full_roam_scan_period), smbuf, sizeof(smbuf), NULL);
  452. if (error) {
  453. DHD_ERROR(("Failed to set full roam scan period, error = %d\n", error));
  454. }
  455. return error;
  456. }
  457. static int wl_android_get_full_roam_scan_period(
  458. struct net_device *dev, char *command, int total_len)
  459. {
  460. int error;
  461. int bytes_written;
  462. int full_roam_scan_period = 0;
  463. error = wldev_iovar_getint(dev, "fullroamperiod", &full_roam_scan_period);
  464. if (error) {
  465. DHD_ERROR(("%s: get full roam scan period failed code %d\n",
  466. __func__, error));
  467. return -1;
  468. } else {
  469. DHD_INFO(("%s: get full roam scan period %d\n", __func__, full_roam_scan_period));
  470. }
  471. bytes_written = snprintf(command, total_len, "%s %d",
  472. CMD_FULLROAMSCANPERIOD_GET, full_roam_scan_period);
  473. return bytes_written;
  474. }
  475. int wl_android_set_country_rev(
  476. struct net_device *dev, char* command, int total_len)
  477. {
  478. int error = 0;
  479. wl_country_t cspec = {{0}, 0, {0} };
  480. char country_code[WLC_CNTRY_BUF_SZ];
  481. char smbuf[WLC_IOCTL_SMLEN];
  482. int rev = 0;
  483. memset(country_code, 0, sizeof(country_code));
  484. sscanf(command+sizeof("SETCOUNTRYREV"), "%10s %10d", country_code, &rev);
  485. WL_TRACE(("country_code = %s, rev = %d\n", country_code, rev));
  486. memcpy(cspec.country_abbrev, country_code, sizeof(country_code));
  487. memcpy(cspec.ccode, country_code, sizeof(country_code));
  488. cspec.rev = rev;
  489. error = wldev_iovar_setbuf(dev, "country", (char *)&cspec,
  490. sizeof(cspec), smbuf, sizeof(smbuf), NULL);
  491. if (error) {
  492. DHD_ERROR(("%s: set country '%s/%d' failed code %d\n",
  493. __FUNCTION__, cspec.ccode, cspec.rev, error));
  494. } else {
  495. dhd_bus_country_set(dev, &cspec);
  496. DHD_INFO(("%s: set country '%s/%d'\n",
  497. __FUNCTION__, cspec.ccode, cspec.rev));
  498. }
  499. return error;
  500. }
  501. static int wl_android_get_country_rev(
  502. struct net_device *dev, char *command, int total_len)
  503. {
  504. int error;
  505. int bytes_written;
  506. char smbuf[WLC_IOCTL_SMLEN];
  507. wl_country_t cspec;
  508. error = wldev_iovar_getbuf(dev, "country", NULL, 0, smbuf,
  509. sizeof(smbuf), NULL);
  510. if (error) {
  511. DHD_ERROR(("%s: get country failed code %d\n",
  512. __FUNCTION__, error));
  513. return -1;
  514. } else {
  515. memcpy(&cspec, smbuf, sizeof(cspec));
  516. DHD_INFO(("%s: get country '%c%c %d'\n",
  517. __FUNCTION__, cspec.ccode[0], cspec.ccode[1], cspec.rev));
  518. }
  519. bytes_written = snprintf(command, total_len, "%s %c%c %d",
  520. CMD_COUNTRYREV_GET, cspec.ccode[0], cspec.ccode[1], cspec.rev);
  521. return bytes_written;
  522. }
  523. #endif /* ROAM_API */
  524. #ifdef WES_SUPPORT
  525. int wl_android_get_roam_scan_control(struct net_device *dev, char *command, int total_len)
  526. {
  527. int error = 0;
  528. int bytes_written = 0;
  529. int mode = 0;
  530. error = get_roamscan_mode(dev, &mode);
  531. if (error) {
  532. DHD_ERROR(("%s: Failed to get Scan Control, error = %d\n", __FUNCTION__, error));
  533. return -1;
  534. }
  535. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETROAMSCANCONTROL, mode);
  536. return bytes_written;
  537. }
  538. int wl_android_set_roam_scan_control(struct net_device *dev, char *command, int total_len)
  539. {
  540. int error = 0;
  541. int mode = 0;
  542. if (sscanf(command, "%*s %d", &mode) != 1) {
  543. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  544. return -1;
  545. }
  546. error = set_roamscan_mode(dev, mode);
  547. if (error) {
  548. DHD_ERROR(("%s: Failed to set Scan Control %d, error = %d\n",
  549. __FUNCTION__, mode, error));
  550. return -1;
  551. }
  552. return 0;
  553. }
  554. int wl_android_get_roam_scan_channels(struct net_device *dev, char *command, int total_len)
  555. {
  556. int bytes_written = 0;
  557. unsigned char channels[ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS] = {0};
  558. int channel_cnt = 0;
  559. char channel_info[10 + (ANDROID_WIFI_MAX_ROAM_SCAN_CHANNELS * 3)] = {0};
  560. int channel_info_len = 0;
  561. int i = 0;
  562. channel_cnt = get_roamscan_channel_list(dev, channels);
  563. channel_info_len += sprintf(&channel_info[channel_info_len], "%d ", channel_cnt);
  564. for (i = 0; i < channel_cnt; i++) {
  565. channel_info_len += sprintf(&channel_info[channel_info_len], "%d ", channels[i]);
  566. if (channel_info_len > (sizeof(channel_info) - 10))
  567. break;
  568. }
  569. channel_info_len += sprintf(&channel_info[channel_info_len], "%s", "\0");
  570. bytes_written = snprintf(command, total_len, "%s %s",
  571. CMD_GETROAMSCANCHANNELS, channel_info);
  572. return bytes_written;
  573. }
  574. int wl_android_set_roam_scan_channels(struct net_device *dev, char *command, int total_len)
  575. {
  576. int error = 0;
  577. unsigned char *p = (unsigned char *)(command + strlen(CMD_SETROAMSCANCHANNELS) + 1);
  578. int ioctl_version = wl_cfg80211_get_ioctl_version();
  579. error = set_roamscan_channel_list(dev, p[0], &p[1], ioctl_version);
  580. if (error) {
  581. DHD_ERROR(("%s: Failed to set Scan Channels %d, error = %d\n",
  582. __FUNCTION__, p[0], error));
  583. return -1;
  584. }
  585. return 0;
  586. }
  587. int wl_android_get_scan_channel_time(struct net_device *dev, char *command, int total_len)
  588. {
  589. int error = 0;
  590. int bytes_written = 0;
  591. int time = 0;
  592. error = wldev_ioctl(dev, WLC_GET_SCAN_CHANNEL_TIME, &time, sizeof(time), 0);
  593. if (error) {
  594. DHD_ERROR(("%s: Failed to get Scan Channel Time, error = %d\n",
  595. __FUNCTION__, error));
  596. return -1;
  597. }
  598. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANCHANNELTIME, time);
  599. return bytes_written;
  600. }
  601. int wl_android_set_scan_channel_time(struct net_device *dev, char *command, int total_len)
  602. {
  603. int error = 0;
  604. int time = 0;
  605. if (sscanf(command, "%*s %d", &time) != 1) {
  606. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  607. return -1;
  608. }
  609. error = wldev_ioctl(dev, WLC_SET_SCAN_CHANNEL_TIME, &time, sizeof(time), 1);
  610. if (error) {
  611. DHD_ERROR(("%s: Failed to set Scan Channel Time %d, error = %d\n",
  612. __FUNCTION__, time, error));
  613. return -1;
  614. }
  615. return 0;
  616. }
  617. int wl_android_get_scan_home_time(struct net_device *dev, char *command, int total_len)
  618. {
  619. int error = 0;
  620. int bytes_written = 0;
  621. int time = 0;
  622. error = wldev_ioctl(dev, WLC_GET_SCAN_HOME_TIME, &time, sizeof(time), 0);
  623. if (error) {
  624. DHD_ERROR(("Failed to get Scan Home Time, error = %d\n", error));
  625. return -1;
  626. }
  627. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANHOMETIME, time);
  628. return bytes_written;
  629. }
  630. int wl_android_set_scan_home_time(struct net_device *dev, char *command, int total_len)
  631. {
  632. int error = 0;
  633. int time = 0;
  634. if (sscanf(command, "%*s %d", &time) != 1) {
  635. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  636. return -1;
  637. }
  638. error = wldev_ioctl(dev, WLC_SET_SCAN_HOME_TIME, &time, sizeof(time), 1);
  639. if (error) {
  640. DHD_ERROR(("%s: Failed to set Scan Home Time %d, error = %d\n",
  641. __FUNCTION__, time, error));
  642. return -1;
  643. }
  644. return 0;
  645. }
  646. int wl_android_get_scan_home_away_time(struct net_device *dev, char *command, int total_len)
  647. {
  648. int error = 0;
  649. int bytes_written = 0;
  650. int time = 0;
  651. error = wldev_iovar_getint(dev, "scan_home_away_time", &time);
  652. if (error) {
  653. DHD_ERROR(("%s: Failed to get Scan Home Away Time, error = %d\n",
  654. __FUNCTION__, error));
  655. return -1;
  656. }
  657. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANHOMEAWAYTIME, time);
  658. return bytes_written;
  659. }
  660. int wl_android_set_scan_home_away_time(struct net_device *dev, char *command, int total_len)
  661. {
  662. int error = 0;
  663. int time = 0;
  664. if (sscanf(command, "%*s %d", &time) != 1) {
  665. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  666. return -1;
  667. }
  668. error = wldev_iovar_setint(dev, "scan_home_away_time", time);
  669. if (error) {
  670. DHD_ERROR(("%s: Failed to set Scan Home Away Time %d, error = %d\n",
  671. __FUNCTION__, time, error));
  672. return -1;
  673. }
  674. return 0;
  675. }
  676. int wl_android_get_scan_nprobes(struct net_device *dev, char *command, int total_len)
  677. {
  678. int error = 0;
  679. int bytes_written = 0;
  680. int num = 0;
  681. error = wldev_ioctl(dev, WLC_GET_SCAN_NPROBES, &num, sizeof(num), 0);
  682. if (error) {
  683. DHD_ERROR(("%s: Failed to get Scan NProbes, error = %d\n", __FUNCTION__, error));
  684. return -1;
  685. }
  686. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETSCANNPROBES, num);
  687. return bytes_written;
  688. }
  689. int wl_android_set_scan_nprobes(struct net_device *dev, char *command, int total_len)
  690. {
  691. int error = 0;
  692. int num = 0;
  693. if (sscanf(command, "%*s %d", &num) != 1) {
  694. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  695. return -1;
  696. }
  697. error = wldev_ioctl(dev, WLC_SET_SCAN_NPROBES, &num, sizeof(num), 1);
  698. if (error) {
  699. DHD_ERROR(("%s: Failed to set Scan NProbes %d, error = %d\n",
  700. __FUNCTION__, num, error));
  701. return -1;
  702. }
  703. return 0;
  704. }
  705. int wl_android_send_action_frame(struct net_device *dev, char *command, int total_len)
  706. {
  707. int error = -1;
  708. android_wifi_af_params_t *params = NULL;
  709. wl_action_frame_t *action_frame = NULL;
  710. wl_af_params_t *af_params = NULL;
  711. char *smbuf = NULL;
  712. struct ether_addr tmp_bssid;
  713. int tmp_channel = 0;
  714. params = (android_wifi_af_params_t *)(command + strlen(CMD_SENDACTIONFRAME) + 1);
  715. if (params == NULL) {
  716. DHD_ERROR(("%s: Invalid params \n", __FUNCTION__));
  717. goto send_action_frame_out;
  718. }
  719. smbuf = kmalloc(WLC_IOCTL_MAXLEN, GFP_KERNEL);
  720. if (smbuf == NULL) {
  721. DHD_ERROR(("%s: failed to allocated memory %d bytes\n",
  722. __FUNCTION__, WLC_IOCTL_MAXLEN));
  723. goto send_action_frame_out;
  724. }
  725. af_params = (wl_af_params_t *) kzalloc(WL_WIFI_AF_PARAMS_SIZE, GFP_KERNEL);
  726. if (af_params == NULL)
  727. {
  728. DHD_ERROR(("%s: unable to allocate frame\n", __FUNCTION__));
  729. goto send_action_frame_out;
  730. }
  731. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  732. if (bcm_ether_atoe((const char *)params->bssid, (struct ether_addr *)&tmp_bssid) == 0) {
  733. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  734. error = wldev_ioctl(dev, WLC_GET_BSSID, &tmp_bssid, ETHER_ADDR_LEN, false);
  735. if (error) {
  736. memset(&tmp_bssid, 0, ETHER_ADDR_LEN);
  737. DHD_ERROR(("%s: failed to get bssid, error=%d\n", __FUNCTION__, error));
  738. goto send_action_frame_out;
  739. }
  740. }
  741. if (params->channel < 0) {
  742. struct channel_info ci;
  743. error = wldev_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci), false);
  744. if (error) {
  745. DHD_ERROR(("%s: failed to get channel, error=%d\n", __FUNCTION__, error));
  746. goto send_action_frame_out;
  747. }
  748. tmp_channel = ci.hw_channel;
  749. }
  750. else {
  751. tmp_channel = params->channel;
  752. }
  753. af_params->channel = tmp_channel;
  754. af_params->dwell_time = params->dwell_time;
  755. memcpy(&af_params->BSSID, &tmp_bssid, ETHER_ADDR_LEN);
  756. action_frame = &af_params->action_frame;
  757. action_frame->packetId = 0;
  758. memcpy(&action_frame->da, &tmp_bssid, ETHER_ADDR_LEN);
  759. action_frame->len = params->len;
  760. memcpy(action_frame->data, params->data, action_frame->len);
  761. error = wldev_iovar_setbuf(dev, "actframe", af_params,
  762. sizeof(wl_af_params_t), smbuf, WLC_IOCTL_MAXLEN, NULL);
  763. if (error) {
  764. DHD_ERROR(("%s: failed to set action frame, error=%d\n", __FUNCTION__, error));
  765. }
  766. send_action_frame_out:
  767. if (af_params)
  768. kfree(af_params);
  769. if (smbuf)
  770. kfree(smbuf);
  771. if (error)
  772. return -1;
  773. else
  774. return 0;
  775. }
  776. int wl_android_reassoc(struct net_device *dev, char *command, int total_len)
  777. {
  778. int error = 0;
  779. android_wifi_reassoc_params_t *params = NULL;
  780. uint band;
  781. chanspec_t channel;
  782. u32 params_size;
  783. wl_reassoc_params_t reassoc_params;
  784. params = (android_wifi_reassoc_params_t *)(command + strlen(CMD_REASSOC) + 1);
  785. if (params == NULL) {
  786. DHD_ERROR(("%s: Invalid params \n", __FUNCTION__));
  787. return -1;
  788. }
  789. memset(&reassoc_params, 0, WL_REASSOC_PARAMS_FIXED_SIZE);
  790. if (bcm_ether_atoe((const char *)params->bssid,
  791. (struct ether_addr *)&reassoc_params.bssid) == 0) {
  792. DHD_ERROR(("%s: Invalid bssid \n", __FUNCTION__));
  793. return -1;
  794. }
  795. if (params->channel < 0) {
  796. DHD_ERROR(("%s: Invalid Channel \n", __FUNCTION__));
  797. return -1;
  798. }
  799. reassoc_params.chanspec_num = 1;
  800. channel = params->channel;
  801. #ifdef D11AC_IOTYPES
  802. if (wl_cfg80211_get_ioctl_version() == 1) {
  803. band = ((channel <= CH_MAX_2G_CHANNEL) ?
  804. WL_LCHANSPEC_BAND_2G : WL_LCHANSPEC_BAND_5G);
  805. reassoc_params.chanspec_list[0] = channel |
  806. band | WL_LCHANSPEC_BW_20 | WL_LCHANSPEC_CTL_SB_NONE;
  807. }
  808. else {
  809. band = ((channel <= CH_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
  810. reassoc_params.chanspec_list[0] = channel | band | WL_CHANSPEC_BW_20;
  811. }
  812. #else
  813. band = ((channel <= CH_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
  814. reassoc_params.chanspec_list[0] = channel |
  815. band | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
  816. #endif /* D11AC_IOTYPES */
  817. params_size = WL_REASSOC_PARAMS_FIXED_SIZE + sizeof(chanspec_t);
  818. error = wldev_ioctl(dev, WLC_REASSOC, &reassoc_params, params_size, true);
  819. if (error) {
  820. DHD_ERROR(("%s: failed to reassoc, error=%d\n", __FUNCTION__, error));
  821. }
  822. if (error)
  823. return -1;
  824. else
  825. return 0;
  826. }
  827. int wl_android_get_wes_mode(struct net_device *dev, char *command, int total_len)
  828. {
  829. int bytes_written = 0;
  830. int mode = 0;
  831. mode = wl_cfg80211_get_wes_mode();
  832. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETWESMODE, mode);
  833. return bytes_written;
  834. }
  835. int wl_android_set_wes_mode(struct net_device *dev, char *command, int total_len)
  836. {
  837. int error = 0;
  838. int mode = 0;
  839. if (sscanf(command, "%*s %d", &mode) != 1) {
  840. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  841. return -1;
  842. }
  843. error = wl_cfg80211_set_wes_mode(mode);
  844. if (error) {
  845. DHD_ERROR(("%s: Failed to set WES Mode %d, error = %d\n",
  846. __FUNCTION__, mode, error));
  847. return -1;
  848. }
  849. return 0;
  850. }
  851. int wl_android_get_okc_mode(struct net_device *dev, char *command, int total_len)
  852. {
  853. int error = 0;
  854. int bytes_written = 0;
  855. int mode = 0;
  856. error = wldev_iovar_getint(dev, "okc_enable", &mode);
  857. if (error) {
  858. DHD_ERROR(("%s: Failed to get OKC Mode, error = %d\n", __FUNCTION__, error));
  859. return -1;
  860. }
  861. bytes_written = snprintf(command, total_len, "%s %d", CMD_GETOKCMODE, mode);
  862. return bytes_written;
  863. }
  864. int wl_android_set_okc_mode(struct net_device *dev, char *command, int total_len)
  865. {
  866. int error = 0;
  867. int mode = 0;
  868. if (sscanf(command, "%*s %d", &mode) != 1) {
  869. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  870. return -1;
  871. }
  872. error = wldev_iovar_setint(dev, "okc_enable", mode);
  873. if (error) {
  874. DHD_ERROR(("%s: Failed to set OKC Mode %d, error = %d\n",
  875. __FUNCTION__, mode, error));
  876. return -1;
  877. }
  878. if (mode)
  879. wldev_iovar_setint(dev, "ccx_enable", 0);
  880. return error;
  881. }
  882. #endif /* WES_SUPPORT */
  883. #endif /* CUSTOMER_HW4 */
  884. #if defined(PNO_SUPPORT) && !defined(WL_SCHED_SCAN)
  885. static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len)
  886. {
  887. wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT];
  888. int res = -1;
  889. int nssid = 0;
  890. cmd_tlv_t *cmd_tlv_temp;
  891. char *str_ptr;
  892. int tlv_size_left;
  893. int pno_time = 0;
  894. int pno_repeat = 0;
  895. int pno_freq_expo_max = 0;
  896. #ifdef PNO_SET_DEBUG
  897. int i;
  898. char pno_in_example[] = {
  899. 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
  900. 'S', '1', '2', '0',
  901. 'S',
  902. 0x05,
  903. 'd', 'l', 'i', 'n', 'k',
  904. 'S',
  905. 0x04,
  906. 'G', 'O', 'O', 'G',
  907. 'T',
  908. '0', 'B',
  909. 'R',
  910. '2',
  911. 'M',
  912. '2',
  913. 0x00
  914. };
  915. #endif /* PNO_SET_DEBUG */
  916. DHD_INFO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
  917. if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) {
  918. DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len));
  919. goto exit_proc;
  920. }
  921. #ifdef PNO_SET_DEBUG
  922. memcpy(command, pno_in_example, sizeof(pno_in_example));
  923. for (i = 0; i < sizeof(pno_in_example); i++)
  924. printf("%02X ", command[i]);
  925. printf("\n");
  926. total_len = sizeof(pno_in_example);
  927. #endif
  928. str_ptr = command + strlen(CMD_PNOSETUP_SET);
  929. tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET);
  930. cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
  931. memset(ssids_local, 0, sizeof(ssids_local));
  932. if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
  933. (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
  934. (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) {
  935. str_ptr += sizeof(cmd_tlv_t);
  936. tlv_size_left -= sizeof(cmd_tlv_t);
  937. if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
  938. MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) {
  939. DHD_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid));
  940. goto exit_proc;
  941. } else {
  942. if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
  943. DHD_ERROR(("%s scan duration corrupted field size %d\n",
  944. __FUNCTION__, tlv_size_left));
  945. goto exit_proc;
  946. }
  947. str_ptr++;
  948. pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
  949. DHD_INFO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
  950. if (str_ptr[0] != 0) {
  951. if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
  952. DHD_ERROR(("%s pno repeat : corrupted field\n",
  953. __FUNCTION__));
  954. goto exit_proc;
  955. }
  956. str_ptr++;
  957. pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
  958. DHD_INFO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat));
  959. if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
  960. DHD_ERROR(("%s FREQ_EXPO_MAX corrupted field size\n",
  961. __FUNCTION__));
  962. goto exit_proc;
  963. }
  964. str_ptr++;
  965. pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
  966. DHD_INFO(("%s: pno_freq_expo_max=%d\n",
  967. __FUNCTION__, pno_freq_expo_max));
  968. }
  969. }
  970. } else {
  971. DHD_ERROR(("%s get wrong TLV command\n", __FUNCTION__));
  972. goto exit_proc;
  973. }
  974. res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
  975. exit_proc:
  976. return res;
  977. }
  978. #endif /* PNO_SUPPORT && !WL_SCHED_SCAN */
  979. static int wl_android_get_p2p_dev_addr(struct net_device *ndev, char *command, int total_len)
  980. {
  981. int ret;
  982. int bytes_written = 0;
  983. ret = wl_cfg80211_get_p2p_dev_addr(ndev, (struct ether_addr*)command);
  984. if (ret)
  985. return 0;
  986. bytes_written = sizeof(struct ether_addr);
  987. return bytes_written;
  988. }
  989. #ifdef BCMCCX
  990. static int wl_android_get_cckm_rn(struct net_device *dev, char *command)
  991. {
  992. int error, rn;
  993. WL_TRACE(("%s:wl_android_get_cckm_rn\n", dev->name));
  994. error = wldev_iovar_getint(dev, "cckm_rn", &rn);
  995. if (unlikely(error)) {
  996. WL_ERR(("wl_android_get_cckm_rn error (%d)\n", error));
  997. return -1;
  998. }
  999. memcpy(command, &rn, sizeof(int));
  1000. return sizeof(int);
  1001. }
  1002. static int wl_android_set_cckm_krk(struct net_device *dev, char *command)
  1003. {
  1004. int error;
  1005. unsigned char key[16];
  1006. static char iovar_buf[WLC_IOCTL_MEDLEN];
  1007. WL_TRACE(("%s: wl_iw_set_cckm_krk\n", dev->name));
  1008. memset(iovar_buf, 0, sizeof(iovar_buf));
  1009. memcpy(key, command+strlen("set cckm_krk")+1, 16);
  1010. error = wldev_iovar_setbuf(dev, "cckm_krk", key, sizeof(key),
  1011. iovar_buf, WLC_IOCTL_MEDLEN, NULL);
  1012. if (unlikely(error))
  1013. {
  1014. WL_ERR((" cckm_krk set error (%d)\n", error));
  1015. return -1;
  1016. }
  1017. return 0;
  1018. }
  1019. static int wl_android_get_assoc_res_ies(struct net_device *dev, char *command)
  1020. {
  1021. int error;
  1022. u8 buf[WL_ASSOC_INFO_MAX];
  1023. wl_assoc_info_t assoc_info;
  1024. u32 resp_ies_len = 0;
  1025. int bytes_written = 0;
  1026. WL_TRACE(("%s: wl_iw_get_assoc_res_ies\n", dev->name));
  1027. error = wldev_iovar_getbuf(dev, "assoc_info", NULL, 0, buf, WL_ASSOC_INFO_MAX, NULL);
  1028. if (unlikely(error)) {
  1029. WL_ERR(("could not get assoc info (%d)\n", error));
  1030. return -1;
  1031. }
  1032. memcpy(&assoc_info, buf, sizeof(wl_assoc_info_t));
  1033. assoc_info.req_len = htod32(assoc_info.req_len);
  1034. assoc_info.resp_len = htod32(assoc_info.resp_len);
  1035. assoc_info.flags = htod32(assoc_info.flags);
  1036. if (assoc_info.resp_len) {
  1037. resp_ies_len = assoc_info.resp_len - sizeof(struct dot11_assoc_resp);
  1038. }
  1039. /* first 4 bytes are ie len */
  1040. memcpy(command, &resp_ies_len, sizeof(u32));
  1041. bytes_written = sizeof(u32);
  1042. /* get the association resp IE's if there are any */
  1043. if (resp_ies_len) {
  1044. error = wldev_iovar_getbuf(dev, "assoc_resp_ies", NULL, 0,
  1045. buf, WL_ASSOC_INFO_MAX, NULL);
  1046. if (unlikely(error)) {
  1047. WL_ERR(("could not get assoc resp_ies (%d)\n", error));
  1048. return -1;
  1049. }
  1050. memcpy(command+sizeof(u32), buf, resp_ies_len);
  1051. bytes_written += resp_ies_len;
  1052. }
  1053. return bytes_written;
  1054. }
  1055. #endif /* BCMCCX */
  1056. /**
  1057. * Global function definitions (declared in wl_android.h)
  1058. */
  1059. int wl_android_wifi_on(struct net_device *dev)
  1060. {
  1061. int ret = 0;
  1062. int retry = POWERUP_MAX_RETRY;
  1063. printk("%s in\n", __FUNCTION__);
  1064. if (!dev) {
  1065. DHD_ERROR(("%s: dev is null\n", __FUNCTION__));
  1066. return -EINVAL;
  1067. }
  1068. dhd_net_if_lock(dev);
  1069. if (!g_wifi_on) {
  1070. do {
  1071. dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON);
  1072. ret = sdioh_start(NULL, 0);
  1073. if (ret == 0)
  1074. break;
  1075. DHD_ERROR(("\nfailed to power up wifi chip, retry again (%d left) **\n\n",
  1076. retry+1));
  1077. dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
  1078. } while (retry-- >= 0);
  1079. if (ret != 0) {
  1080. DHD_ERROR(("\nfailed to power up wifi chip, max retry reached **\n\n"));
  1081. goto exit;
  1082. }
  1083. ret = dhd_dev_reset(dev, FALSE);
  1084. sdioh_start(NULL, 1);
  1085. if (!ret) {
  1086. if (dhd_dev_init_ioctl(dev) < 0)
  1087. ret = -EFAULT;
  1088. }
  1089. #if defined(PROP_TXSTATUS) && !defined(PROP_TXSTATUS_VSDB)
  1090. dhd_wlfc_init(bcmsdh_get_drvdata());
  1091. #endif
  1092. g_wifi_on = TRUE;
  1093. }
  1094. exit:
  1095. dhd_net_if_unlock(dev);
  1096. return ret;
  1097. }
  1098. int wl_android_wifi_off(struct net_device *dev)
  1099. {
  1100. int ret = 0;
  1101. printk("%s in\n", __FUNCTION__);
  1102. if (!dev) {
  1103. DHD_TRACE(("%s: dev is null\n", __FUNCTION__));
  1104. return -EINVAL;
  1105. }
  1106. dhd_net_if_lock(dev);
  1107. if (g_wifi_on) {
  1108. #if defined(PROP_TXSTATUS) && !defined(PROP_TXSTATUS_VSDB)
  1109. dhd_wlfc_deinit(bcmsdh_get_drvdata());
  1110. #endif
  1111. ret = dhd_dev_reset(dev, TRUE);
  1112. sdioh_stop(NULL);
  1113. dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
  1114. g_wifi_on = FALSE;
  1115. }
  1116. dhd_net_if_unlock(dev);
  1117. return ret;
  1118. }
  1119. static int wl_android_set_fwpath(struct net_device *net, char *command, int total_len)
  1120. {
  1121. if ((strlen(command) - strlen(CMD_SETFWPATH)) > MOD_PARAM_PATHLEN)
  1122. return -1;
  1123. bcm_strncpy_s(fw_path, sizeof(fw_path),
  1124. command + strlen(CMD_SETFWPATH) + 1, MOD_PARAM_PATHLEN - 1);
  1125. if (strstr(fw_path, "apsta") != NULL) {
  1126. DHD_INFO(("GOT APSTA FIRMWARE\n"));
  1127. ap_fw_loaded = TRUE;
  1128. } else {
  1129. DHD_INFO(("GOT STA FIRMWARE\n"));
  1130. ap_fw_loaded = FALSE;
  1131. }
  1132. return 0;
  1133. }
  1134. static int
  1135. wl_android_set_pmk(struct net_device *dev, char *command, int total_len)
  1136. {
  1137. uchar pmk[33];
  1138. int error = 0;
  1139. char smbuf[WLC_IOCTL_SMLEN];
  1140. #ifdef OKC_DEBUG
  1141. int i = 0;
  1142. #endif
  1143. bzero(pmk, sizeof(pmk));
  1144. memcpy((char *)pmk, command + strlen("SET_PMK "), 32);
  1145. error = wldev_iovar_setbuf(dev, "okc_info_pmk", pmk, 32, smbuf, sizeof(smbuf), NULL);
  1146. if (error) {
  1147. DHD_ERROR(("Failed to set PMK for OKC, error = %d\n", error));
  1148. }
  1149. #ifdef OKC_DEBUG
  1150. DHD_ERROR(("PMK is "));
  1151. for (i = 0; i < 32; i++)
  1152. DHD_ERROR(("%02X ", pmk[i]));
  1153. DHD_ERROR(("\n"));
  1154. #endif
  1155. return error;
  1156. }
  1157. static int
  1158. wl_android_okc_enable(struct net_device *dev, char *command, int total_len)
  1159. {
  1160. int error = 0;
  1161. char okc_enable = 0;
  1162. okc_enable = command[strlen(CMD_OKC_ENABLE) + 1] - '0';
  1163. error = wldev_iovar_setint(dev, "okc_enable", okc_enable);
  1164. if (error) {
  1165. DHD_ERROR(("Failed to %s OKC, error = %d\n",
  1166. okc_enable ? "enable" : "disable", error));
  1167. }
  1168. wldev_iovar_setint(dev, "ccx_enable", 0);
  1169. return error;
  1170. }
  1171. #ifdef CUSTOMER_HW4
  1172. #ifdef SUPPORT_AMPDU_MPDU_CMD
  1173. /* CMD_AMPDU_MPDU */
  1174. static int
  1175. wl_android_set_ampdu_mpdu(struct net_device *dev, const char* string_num)
  1176. {
  1177. int err = 0;
  1178. int ampdu_mpdu;
  1179. ampdu_mpdu = bcm_atoi(string_num);
  1180. if (ampdu_mpdu > 32) {
  1181. DHD_ERROR(("%s : ampdu_mpdu MAX value is 32.\n", __FUNCTION__));
  1182. return -1;
  1183. }
  1184. DHD_ERROR(("%s : ampdu_mpdu = %d\n", __FUNCTION__, ampdu_mpdu));
  1185. err = wldev_iovar_setint(dev, "ampdu_mpdu", ampdu_mpdu);
  1186. if (err < 0) {
  1187. DHD_ERROR(("%s : ampdu_mpdu set error. %d\n", __FUNCTION__, err));
  1188. return -1;
  1189. }
  1190. return 0;
  1191. }
  1192. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  1193. /* SoftAP feature */
  1194. #ifdef SUPPORT_AUTO_CHANNEL
  1195. static int
  1196. wl_android_set_auto_channel(struct net_device *dev, const char* string_num,
  1197. char* command, int total_len)
  1198. {
  1199. int channel;
  1200. int chosen = 0;
  1201. int retry = 0;
  1202. int ret = 0;
  1203. /* Restrict channel to 1 - 7: 2GHz, 20MHz BW, No SB */
  1204. u32 req_buf[8] = {7, 0x2B01, 0x2B02, 0x2B03, 0x2B04, 0x2B05, 0x2B06,
  1205. 0x2B07};
  1206. /* Auto channel select */
  1207. wl_uint32_list_t request;
  1208. channel = bcm_atoi(string_num);
  1209. DHD_INFO(("%s : HAPD_AUTO_CHANNEL = %d\n", __FUNCTION__, channel));
  1210. if (channel == 20)
  1211. ret = wldev_ioctl(dev, WLC_START_CHANNEL_SEL, (void *)&req_buf,
  1212. sizeof(req_buf), true);
  1213. else { /* channel == 0 */
  1214. request.count = htod32(0);
  1215. ret = wldev_ioctl(dev, WLC_START_CHANNEL_SEL, (void *)&request,
  1216. sizeof(request), true);
  1217. }
  1218. if (ret < 0) {
  1219. DHD_ERROR(("%s: can't start auto channel scan, err = %d\n",
  1220. __FUNCTION__, ret));
  1221. channel = 0;
  1222. goto done;
  1223. }
  1224. /* Wait for auto channel selection, max 2500 ms */
  1225. bcm_mdelay(500);
  1226. retry = 10;
  1227. while (retry--) {
  1228. ret = wldev_ioctl(dev, WLC_GET_CHANNEL_SEL, &chosen, sizeof(chosen),
  1229. false);
  1230. if (ret < 0 || dtoh32(chosen) == 0) {
  1231. DHD_INFO(("%s: %d tried, ret = %d, chosen = %d\n",
  1232. __FUNCTION__, (10 - retry), ret, chosen));
  1233. bcm_mdelay(200);
  1234. }
  1235. else {
  1236. channel = (u16)chosen & 0x00FF;
  1237. DHD_ERROR(("%s: selected channel = %d\n", __FUNCTION__, channel));
  1238. break;
  1239. }
  1240. }
  1241. if (retry == 0) {
  1242. DHD_ERROR(("%s: auto channel timed out, failed\n", __FUNCTION__));
  1243. channel = 0;
  1244. }
  1245. done:
  1246. snprintf(command, 4, "%d", channel);
  1247. DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command));
  1248. return 4;
  1249. }
  1250. #endif /* SUPPORT_AUTO_CHANNEL */
  1251. #ifdef SUPPORT_HIDDEN_AP
  1252. static int
  1253. wl_android_set_max_num_sta(struct net_device *dev, const char* string_num)
  1254. {
  1255. int max_assoc;
  1256. max_assoc = bcm_atoi(string_num);
  1257. DHD_INFO(("%s : HAPD_MAX_NUM_STA = %d\n", __FUNCTION__, max_assoc));
  1258. wldev_iovar_setint(dev, "maxassoc", max_assoc);
  1259. return 1;
  1260. }
  1261. static int
  1262. wl_android_set_ssid(struct net_device *dev, const char* hapd_ssid)
  1263. {
  1264. wlc_ssid_t ssid;
  1265. s32 ret;
  1266. ssid.SSID_len = strlen(hapd_ssid);
  1267. if (ssid.SSID_len > DOT11_MAX_SSID_LEN) {
  1268. ssid.SSID_len = DOT11_MAX_SSID_LEN;
  1269. DHD_ERROR(("%s : Too long SSID Length %d\n", __FUNCTION__, strlen(hapd_ssid)));
  1270. }
  1271. bcm_strncpy_s(ssid.SSID, sizeof(ssid.SSID), hapd_ssid, ssid.SSID_len);
  1272. DHD_INFO(("%s: HAPD_SSID = %s\n", __FUNCTION__, ssid.SSID));
  1273. ret = wldev_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(wlc_ssid_t), true);
  1274. if (ret < 0) {
  1275. DHD_ERROR(("%s : WLC_SET_SSID Error:%d\n", __FUNCTION__, ret));
  1276. }
  1277. return 1;
  1278. }
  1279. static int
  1280. wl_android_set_hide_ssid(struct net_device *dev, const char* string_num)
  1281. {
  1282. int hide_ssid;
  1283. int enable = 0;
  1284. hide_ssid = bcm_atoi(string_num);
  1285. DHD_INFO(("%s: HAPD_HIDE_SSID = %d\n", __FUNCTION__, hide_ssid));
  1286. if (hide_ssid)
  1287. enable = 1;
  1288. wldev_iovar_setint(dev, "closednet", enable);
  1289. return 1;
  1290. }
  1291. #endif /* SUPPORT_HIDDEN_AP */
  1292. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  1293. static int
  1294. wl_android_sta_diassoc(struct net_device *dev, const char* straddr)
  1295. {
  1296. scb_val_t scbval;
  1297. int error = 0;
  1298. DHD_INFO(("%s: deauth STA %s\n", __FUNCTION__, straddr));
  1299. /* Unspecified reason */
  1300. scbval.val = htod32(1);
  1301. bcm_ether_atoe(straddr, &scbval.ea);
  1302. DHD_ERROR(("%s: deauth STA: "MACDBG " scb_val.val %d\n", __FUNCTION__,
  1303. MAC2STRDBG(scbval.ea.octet), scbval.val));
  1304. error = wldev_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
  1305. sizeof(scb_val_t), true);
  1306. if (error) {
  1307. DHD_ERROR(("Fail to DEAUTH station, error = %d\n", error));
  1308. }
  1309. return 1;
  1310. }
  1311. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  1312. #ifdef SUPPORT_SET_LPC
  1313. static int
  1314. wl_android_set_lpc(struct net_device *dev, const char* string_num)
  1315. {
  1316. int lpc_enabled, ret;
  1317. s32 val = 1;
  1318. lpc_enabled = bcm_atoi(string_num);
  1319. DHD_INFO(("%s : HAPD_LPC_ENABLED = %d\n", __FUNCTION__, lpc_enabled));
  1320. ret = wldev_ioctl(dev, WLC_DOWN, &val, sizeof(s32), true);
  1321. if (ret < 0)
  1322. DHD_ERROR(("WLC_DOWN error %d\n", ret));
  1323. wldev_iovar_setint(dev, "lpc", lpc_enabled);
  1324. ret = wldev_ioctl(dev, WLC_UP, &val, sizeof(s32), true);
  1325. if (ret < 0)
  1326. DHD_ERROR(("WLC_UP error %d\n", ret));
  1327. return 1;
  1328. }
  1329. #endif /* SUPPORT_SET_LPC */
  1330. static int
  1331. wl_android_ch_res_rl(struct net_device *dev, bool change)
  1332. {
  1333. int error = 0;
  1334. s32 srl = 7;
  1335. s32 lrl = 4;
  1336. printk("%s enter\n", __FUNCTION__);
  1337. if (change) {
  1338. srl = 4;
  1339. lrl = 2;
  1340. }
  1341. error = wldev_ioctl(dev, WLC_SET_SRL, &srl, sizeof(s32), true);
  1342. if (error) {
  1343. DHD_ERROR(("Failed to set SRL, error = %d\n", error));
  1344. }
  1345. error = wldev_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(s32), true);
  1346. if (error) {
  1347. DHD_ERROR(("Failed to set LRL, error = %d\n", error));
  1348. }
  1349. return error;
  1350. }
  1351. #endif /* CUSTOMER_HW4 */
  1352. int wl_android_set_roam_mode(struct net_device *dev, char *command, int total_len)
  1353. {
  1354. int error = 0;
  1355. int mode = 0;
  1356. if (sscanf(command, "%*s %d", &mode) != 1) {
  1357. DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__));
  1358. return -1;
  1359. }
  1360. error = wldev_iovar_setint(dev, "roam_off", mode);
  1361. if (error) {
  1362. DHD_ERROR(("%s: Failed to set roaming Mode %d, error = %d\n",
  1363. __FUNCTION__, mode, error));
  1364. return -1;
  1365. }
  1366. else
  1367. DHD_ERROR(("%s: succeeded to set roaming Mode %d, error = %d\n",
  1368. __FUNCTION__, mode, error));
  1369. return 0;
  1370. }
  1371. int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
  1372. {
  1373. #ifdef CUSTOMER_HW4
  1374. /* DO NOT CHANGE THIS: Samsung JBP branch requires 16KB buffer size */
  1375. #define PRIVATE_COMMAND_MAX_LEN 16384
  1376. #else
  1377. #define PRIVATE_COMMAND_MAX_LEN 8192
  1378. #endif /* CUSTOMER_HW4 */
  1379. int ret = 0;
  1380. char *command = NULL;
  1381. int bytes_written = 0;
  1382. android_wifi_priv_cmd priv_cmd;
  1383. net_os_wake_lock(net);
  1384. if (!ifr->ifr_data) {
  1385. ret = -EINVAL;
  1386. goto exit;
  1387. }
  1388. if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
  1389. ret = -EFAULT;
  1390. goto exit;
  1391. }
  1392. if (priv_cmd.total_len > PRIVATE_COMMAND_MAX_LEN)
  1393. {
  1394. DHD_ERROR(("%s: too long priavte command\n", __FUNCTION__));
  1395. ret = -EINVAL;
  1396. goto exit;
  1397. }
  1398. command = kmalloc((priv_cmd.total_len + 1), GFP_KERNEL);
  1399. if (!command)
  1400. {
  1401. DHD_ERROR(("%s: failed to allocate memory\n", __FUNCTION__));
  1402. ret = -ENOMEM;
  1403. goto exit;
  1404. }
  1405. if (copy_from_user(command, priv_cmd.buf, priv_cmd.total_len)) {
  1406. ret = -EFAULT;
  1407. goto exit;
  1408. }
  1409. command[priv_cmd.total_len] = '\0';
  1410. DHD_INFO(("%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, command, ifr->ifr_name));
  1411. if (strnicmp(command, CMD_START, strlen(CMD_START)) == 0) {
  1412. DHD_INFO(("%s, Received regular START command\n", __FUNCTION__));
  1413. #ifdef SUPPORT_DEEP_SLEEP
  1414. trigger_deep_sleep = 1;
  1415. #else
  1416. bytes_written = wl_android_wifi_on(net);
  1417. #endif /* SUPPORT_DEEP_SLEEP */
  1418. }
  1419. else if (strnicmp(command, CMD_SETFWPATH, strlen(CMD_SETFWPATH)) == 0) {
  1420. bytes_written = wl_android_set_fwpath(net, command, priv_cmd.total_len);
  1421. }
  1422. if (!g_wifi_on) {
  1423. DHD_ERROR(("%s: Ignore private cmd \"%s\" - iface %s is down\n",
  1424. __FUNCTION__, command, ifr->ifr_name));
  1425. ret = 0;
  1426. goto exit;
  1427. }
  1428. if (strnicmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) {
  1429. #ifdef SUPPORT_DEEP_SLEEP
  1430. trigger_deep_sleep = 1;
  1431. #else
  1432. bytes_written = wl_android_wifi_off(net);
  1433. #endif /* SUPPORT_DEEP_SLEEP */
  1434. }
  1435. else if (strnicmp(command, CMD_SCAN_ACTIVE, strlen(CMD_SCAN_ACTIVE)) == 0) {
  1436. /* TBD: SCAN-ACTIVE */
  1437. }
  1438. else if (strnicmp(command, CMD_SCAN_PASSIVE, strlen(CMD_SCAN_PASSIVE)) == 0) {
  1439. /* TBD: SCAN-PASSIVE */
  1440. }
  1441. else if (strnicmp(command, CMD_RSSI, strlen(CMD_RSSI)) == 0) {
  1442. bytes_written = wl_android_get_rssi(net, command, priv_cmd.total_len);
  1443. }
  1444. else if (strnicmp(command, CMD_LINKSPEED, strlen(CMD_LINKSPEED)) == 0) {
  1445. bytes_written = wl_android_get_link_speed(net, command, priv_cmd.total_len);
  1446. }
  1447. #ifdef PKT_FILTER_SUPPORT
  1448. else if (strnicmp(command, CMD_RXFILTER_START, strlen(CMD_RXFILTER_START)) == 0) {
  1449. bytes_written = net_os_enable_packet_filter(net, 1);
  1450. }
  1451. else if (strnicmp(command, CMD_RXFILTER_STOP, strlen(CMD_RXFILTER_STOP)) == 0) {
  1452. bytes_written = net_os_enable_packet_filter(net, 0);
  1453. }
  1454. else if (strnicmp(command, CMD_RXFILTER_ADD, strlen(CMD_RXFILTER_ADD)) == 0) {
  1455. int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
  1456. bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
  1457. }
  1458. else if (strnicmp(command, CMD_RXFILTER_REMOVE, strlen(CMD_RXFILTER_REMOVE)) == 0) {
  1459. int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
  1460. bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
  1461. }
  1462. #endif /* PKT_FILTER_SUPPORT */
  1463. else if (strnicmp(command, CMD_BTCOEXSCAN_START, strlen(CMD_BTCOEXSCAN_START)) == 0) {
  1464. /* TBD: BTCOEXSCAN-START */
  1465. }
  1466. else if (strnicmp(command, CMD_BTCOEXSCAN_STOP, strlen(CMD_BTCOEXSCAN_STOP)) == 0) {
  1467. /* TBD: BTCOEXSCAN-STOP */
  1468. }
  1469. else if (strnicmp(command, CMD_BTCOEXMODE, strlen(CMD_BTCOEXMODE)) == 0) {
  1470. #ifdef WL_CFG80211
  1471. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
  1472. #else
  1473. #ifdef PKT_FILTER_SUPPORT
  1474. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  1475. if (mode == 1)
  1476. net_os_enable_packet_filter(net, 0); /* DHCP starts */
  1477. else
  1478. net_os_enable_packet_filter(net, 1); /* DHCP ends */
  1479. #endif /* PKT_FILTER_SUPPORT */
  1480. #endif /* WL_CFG80211 */
  1481. }
  1482. else if (strnicmp(command, CMD_SETSUSPENDOPT, strlen(CMD_SETSUSPENDOPT)) == 0) {
  1483. bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
  1484. }
  1485. else if (strnicmp(command, CMD_SETSUSPENDMODE, strlen(CMD_SETSUSPENDMODE)) == 0) {
  1486. bytes_written = wl_android_set_suspendmode(net, command, priv_cmd.total_len);
  1487. }
  1488. else if (strnicmp(command, CMD_SETBAND, strlen(CMD_SETBAND)) == 0) {
  1489. uint band = *(command + strlen(CMD_SETBAND) + 1) - '0';
  1490. #ifdef WL_HOST_BAND_MGMT
  1491. s32 ret = 0;
  1492. if ((ret = wl_cfg80211_set_band(net, band)) < 0) {
  1493. if (ret == BCME_UNSUPPORTED) {
  1494. /* If roam_var is unsupported, fallback to the original method */
  1495. WL_ERR(("WL_HOST_BAND_MGMT defined, "
  1496. "but roam_band iovar unsupported in the firmware\n"));
  1497. } else {
  1498. bytes_written = -1;
  1499. goto exit;
  1500. }
  1501. }
  1502. if ((band == WLC_BAND_AUTO) || (ret == BCME_UNSUPPORTED))
  1503. bytes_written = wldev_set_band(net, band);
  1504. #else
  1505. bytes_written = wldev_set_band(net, band);
  1506. #endif /* WL_HOST_BAND_MGMT */
  1507. }
  1508. else if (strnicmp(command, CMD_GETBAND, strlen(CMD_GETBAND)) == 0) {
  1509. bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
  1510. }
  1511. #ifdef WL_CFG80211
  1512. #ifndef CUSTOMER_SET_COUNTRY
  1513. /* CUSTOMER_SET_COUNTRY feature is define for only GGSM model */
  1514. else if (strnicmp(command, CMD_COUNTRY, strlen(CMD_COUNTRY)) == 0) {
  1515. char *country_code = command + strlen(CMD_COUNTRY) + 1;
  1516. bytes_written = wldev_set_country(net, country_code);
  1517. }
  1518. #endif /* CUSTOMER_SET_COUNTRY */
  1519. #endif /* WL_CFG80211 */
  1520. #ifdef CUSTOMER_HW4
  1521. #ifdef ROAM_API
  1522. else if (strnicmp(command, CMD_ROAMTRIGGER_SET,
  1523. strlen(CMD_ROAMTRIGGER_SET)) == 0) {
  1524. bytes_written = wl_android_set_roam_trigger(net, command,
  1525. priv_cmd.total_len);
  1526. } else if (strnicmp(command, CMD_ROAMTRIGGER_GET,
  1527. strlen(CMD_ROAMTRIGGER_GET)) == 0) {
  1528. bytes_written = wl_android_get_roam_trigger(net, command,
  1529. priv_cmd.total_len);
  1530. } else if (strnicmp(command, CMD_ROAMDELTA_SET,
  1531. strlen(CMD_ROAMDELTA_SET)) == 0) {
  1532. bytes_written = wl_android_set_roam_delta(net, command,
  1533. priv_cmd.total_len);
  1534. } else if (strnicmp(command, CMD_ROAMDELTA_GET,
  1535. strlen(CMD_ROAMDELTA_GET)) == 0) {
  1536. bytes_written = wl_android_get_roam_delta(net, command,
  1537. priv_cmd.total_len);
  1538. } else if (strnicmp(command, CMD_ROAMSCANPERIOD_SET,
  1539. strlen(CMD_ROAMSCANPERIOD_SET)) == 0) {
  1540. bytes_written = wl_android_set_roam_scan_period(net, command,
  1541. priv_cmd.total_len);
  1542. } else if (strnicmp(command, CMD_ROAMSCANPERIOD_GET,
  1543. strlen(CMD_ROAMSCANPERIOD_GET)) == 0) {
  1544. bytes_written = wl_android_get_roam_scan_period(net, command,
  1545. priv_cmd.total_len);
  1546. } else if (strnicmp(command, CMD_FULLROAMSCANPERIOD_SET,
  1547. strlen(CMD_FULLROAMSCANPERIOD_SET)) == 0) {
  1548. bytes_written = wl_android_set_full_roam_scan_period(net, command,
  1549. priv_cmd.total_len);
  1550. } else if (strnicmp(command, CMD_FULLROAMSCANPERIOD_GET,
  1551. strlen(CMD_FULLROAMSCANPERIOD_GET)) == 0) {
  1552. bytes_written = wl_android_get_full_roam_scan_period(net, command,
  1553. priv_cmd.total_len);
  1554. } else if (strnicmp(command, CMD_COUNTRYREV_SET,
  1555. strlen(CMD_COUNTRYREV_SET)) == 0) {
  1556. bytes_written = wl_android_set_country_rev(net, command,
  1557. priv_cmd.total_len);
  1558. } else if (strnicmp(command, CMD_COUNTRYREV_GET,
  1559. strlen(CMD_COUNTRYREV_GET)) == 0) {
  1560. bytes_written = wl_android_get_country_rev(net, command,
  1561. priv_cmd.total_len);
  1562. }
  1563. #endif /* ROAM_API */
  1564. #ifdef WES_SUPPORT
  1565. else if (strnicmp(command, CMD_GETROAMSCANCONTROL, strlen(CMD_GETROAMSCANCONTROL)) == 0) {
  1566. bytes_written = wl_android_get_roam_scan_control(net, command, priv_cmd.total_len);
  1567. }
  1568. else if (strnicmp(command, CMD_SETROAMSCANCONTROL, strlen(CMD_SETROAMSCANCONTROL)) == 0) {
  1569. bytes_written = wl_android_set_roam_scan_control(net, command, priv_cmd.total_len);
  1570. }
  1571. else if (strnicmp(command, CMD_GETROAMSCANCHANNELS, strlen(CMD_GETROAMSCANCHANNELS)) == 0) {
  1572. bytes_written = wl_android_get_roam_scan_channels(net, command, priv_cmd.total_len);
  1573. }
  1574. else if (strnicmp(command, CMD_SETROAMSCANCHANNELS, strlen(CMD_SETROAMSCANCHANNELS)) == 0) {
  1575. bytes_written = wl_android_set_roam_scan_channels(net, command, priv_cmd.total_len);
  1576. }
  1577. else if (strnicmp(command, CMD_SENDACTIONFRAME, strlen(CMD_SENDACTIONFRAME)) == 0) {
  1578. bytes_written = wl_android_send_action_frame(net, command, priv_cmd.total_len);
  1579. }
  1580. else if (strnicmp(command, CMD_REASSOC, strlen(CMD_REASSOC)) == 0) {
  1581. bytes_written = wl_android_reassoc(net, command, priv_cmd.total_len);
  1582. }
  1583. else if (strnicmp(command, CMD_GETSCANCHANNELTIME, strlen(CMD_GETSCANCHANNELTIME)) == 0) {
  1584. bytes_written = wl_android_get_scan_channel_time(net, command, priv_cmd.total_len);
  1585. }
  1586. else if (strnicmp(command, CMD_SETSCANCHANNELTIME, strlen(CMD_SETSCANCHANNELTIME)) == 0) {
  1587. bytes_written = wl_android_set_scan_channel_time(net, command, priv_cmd.total_len);
  1588. }
  1589. else if (strnicmp(command, CMD_GETSCANHOMETIME, strlen(CMD_GETSCANHOMETIME)) == 0) {
  1590. bytes_written = wl_android_get_scan_home_time(net, command, priv_cmd.total_len);
  1591. }
  1592. else if (strnicmp(command, CMD_SETSCANHOMETIME, strlen(CMD_SETSCANHOMETIME)) == 0) {
  1593. bytes_written = wl_android_set_scan_home_time(net, command, priv_cmd.total_len);
  1594. }
  1595. else if (strnicmp(command, CMD_GETSCANHOMEAWAYTIME, strlen(CMD_GETSCANHOMEAWAYTIME)) == 0) {
  1596. bytes_written = wl_android_get_scan_home_away_time(net, command,
  1597. priv_cmd.total_len);
  1598. }
  1599. else if (strnicmp(command, CMD_SETSCANHOMEAWAYTIME, strlen(CMD_SETSCANHOMEAWAYTIME)) == 0) {
  1600. bytes_written = wl_android_set_scan_home_away_time(net, command,
  1601. priv_cmd.total_len);
  1602. }
  1603. else if (strnicmp(command, CMD_GETSCANNPROBES, strlen(CMD_GETSCANNPROBES)) == 0) {
  1604. bytes_written = wl_android_get_scan_nprobes(net, command, priv_cmd.total_len);
  1605. }
  1606. else if (strnicmp(command, CMD_SETSCANNPROBES, strlen(CMD_SETSCANNPROBES)) == 0) {
  1607. bytes_written = wl_android_set_scan_nprobes(net, command, priv_cmd.total_len);
  1608. }
  1609. else if (strnicmp(command, CMD_GETWESMODE, strlen(CMD_GETWESMODE)) == 0) {
  1610. bytes_written = wl_android_get_wes_mode(net, command, priv_cmd.total_len);
  1611. }
  1612. else if (strnicmp(command, CMD_SETWESMODE, strlen(CMD_SETWESMODE)) == 0) {
  1613. bytes_written = wl_android_set_wes_mode(net, command, priv_cmd.total_len);
  1614. }
  1615. else if (strnicmp(command, CMD_GETOKCMODE, strlen(CMD_GETOKCMODE)) == 0) {
  1616. bytes_written = wl_android_get_okc_mode(net, command, priv_cmd.total_len);
  1617. }
  1618. else if (strnicmp(command, CMD_SETOKCMODE, strlen(CMD_SETOKCMODE)) == 0) {
  1619. bytes_written = wl_android_set_okc_mode(net, command, priv_cmd.total_len);
  1620. }
  1621. #endif /* WES_SUPPORT */
  1622. #endif /* CUSTOMER_HW4 */
  1623. #if defined(PNO_SUPPORT) && !defined(WL_SCHED_SCAN)
  1624. else if (strnicmp(command, CMD_PNOSSIDCLR_SET, strlen(CMD_PNOSSIDCLR_SET)) == 0) {
  1625. bytes_written = dhd_dev_pno_reset(net);
  1626. }
  1627. else if (strnicmp(command, CMD_PNOSETUP_SET, strlen(CMD_PNOSETUP_SET)) == 0) {
  1628. bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
  1629. }
  1630. else if (strnicmp(command, CMD_PNOENABLE_SET, strlen(CMD_PNOENABLE_SET)) == 0) {
  1631. uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
  1632. bytes_written = dhd_dev_pno_enable(net, pfn_enabled);
  1633. }
  1634. #endif /* PNO_SUPPORT && !WL_SCHED_SCAN */
  1635. else if (strnicmp(command, CMD_P2P_DEV_ADDR, strlen(CMD_P2P_DEV_ADDR)) == 0) {
  1636. bytes_written = wl_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  1637. }
  1638. else if (strnicmp(command, CMD_P2P_SET_NOA, strlen(CMD_P2P_SET_NOA)) == 0) {
  1639. int skip = strlen(CMD_P2P_SET_NOA) + 1;
  1640. bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip,
  1641. priv_cmd.total_len - skip);
  1642. }
  1643. #if !defined WL_ENABLE_P2P_IF
  1644. else if (strnicmp(command, CMD_P2P_GET_NOA, strlen(CMD_P2P_GET_NOA)) == 0) {
  1645. bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
  1646. }
  1647. #endif /* WL_ENABLE_P2P_IF */
  1648. else if (strnicmp(command, CMD_P2P_SET_PS, strlen(CMD_P2P_SET_PS)) == 0) {
  1649. int skip = strlen(CMD_P2P_SET_PS) + 1;
  1650. bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip,
  1651. priv_cmd.total_len - skip);
  1652. }
  1653. #ifdef WL_CFG80211
  1654. else if (strnicmp(command, CMD_SET_AP_WPS_P2P_IE,
  1655. strlen(CMD_SET_AP_WPS_P2P_IE)) == 0) {
  1656. int skip = strlen(CMD_SET_AP_WPS_P2P_IE) + 3;
  1657. bytes_written = wl_cfg80211_set_wps_p2p_ie(net, command + skip,
  1658. priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  1659. }
  1660. #endif /* WL_CFG80211 */
  1661. else if (strnicmp(command, CMD_OKC_SET_PMK, strlen(CMD_OKC_SET_PMK)) == 0)
  1662. bytes_written = wl_android_set_pmk(net, command, priv_cmd.total_len);
  1663. else if (strnicmp(command, CMD_OKC_ENABLE, strlen(CMD_OKC_ENABLE)) == 0)
  1664. bytes_written = wl_android_okc_enable(net, command, priv_cmd.total_len);
  1665. #ifdef BCMCCX
  1666. else if (strnicmp(command, CMD_GETCCKM_RN, strlen(CMD_GETCCKM_RN)) == 0) {
  1667. bytes_written = wl_android_get_cckm_rn(net, command);
  1668. }
  1669. else if (strnicmp(command, CMD_SETCCKM_KRK, strlen(CMD_SETCCKM_KRK)) == 0) {
  1670. bytes_written = wl_android_set_cckm_krk(net, command);
  1671. }
  1672. else if (strnicmp(command, CMD_GET_ASSOC_RES_IES, strlen(CMD_GET_ASSOC_RES_IES)) == 0) {
  1673. bytes_written = wl_android_get_assoc_res_ies(net, command);
  1674. }
  1675. #endif /* BCMCCX */
  1676. #ifdef CUSTOMER_HW4
  1677. #ifdef SUPPORT_AMPDU_MPDU_CMD
  1678. /* CMD_AMPDU_MPDU */
  1679. else if (strnicmp(command, CMD_AMPDU_MPDU, strlen(CMD_AMPDU_MPDU)) == 0) {
  1680. int skip = strlen(CMD_AMPDU_MPDU) + 1;
  1681. bytes_written = wl_android_set_ampdu_mpdu(net, (const char*)command+skip);
  1682. }
  1683. #endif /* SUPPORT_AMPDU_MPDU_CMD */
  1684. #ifdef SUPPORT_AUTO_CHANNEL
  1685. else if (strnicmp(command, CMD_SET_HAPD_AUTO_CHANNEL,
  1686. strlen(CMD_SET_HAPD_AUTO_CHANNEL)) == 0) {
  1687. int skip = strlen(CMD_SET_HAPD_AUTO_CHANNEL) + 3;
  1688. bytes_written = wl_android_set_auto_channel(net, (const char*)command+skip, command,
  1689. priv_cmd.total_len);
  1690. }
  1691. #endif /* SUPPORT_AUTO_CHANNEL */
  1692. #ifdef SUPPORT_HIDDEN_AP
  1693. else if (strnicmp(command, CMD_SET_HAPD_MAX_NUM_STA,
  1694. strlen(CMD_SET_HAPD_MAX_NUM_STA)) == 0) {
  1695. int skip = strlen(CMD_SET_HAPD_MAX_NUM_STA) + 3;
  1696. wl_android_set_max_num_sta(net, (const char*)command+skip);
  1697. }
  1698. else if (strnicmp(command, CMD_SET_HAPD_SSID,
  1699. strlen(CMD_SET_HAPD_SSID)) == 0) {
  1700. int skip = strlen(CMD_SET_HAPD_SSID) + 3;
  1701. wl_android_set_ssid(net, (const char*)command+skip);
  1702. }
  1703. else if (strnicmp(command, CMD_SET_HAPD_HIDE_SSID,
  1704. strlen(CMD_SET_HAPD_HIDE_SSID)) == 0) {
  1705. int skip = strlen(CMD_SET_HAPD_HIDE_SSID) + 3;
  1706. wl_android_set_hide_ssid(net, (const char*)command+skip);
  1707. }
  1708. #endif /* SUPPORT_HIDDEN_AP */
  1709. #ifdef SUPPORT_SOFTAP_SINGL_DISASSOC
  1710. else if (strnicmp(command, CMD_HAPD_STA_DISASSOC,
  1711. strlen(CMD_HAPD_STA_DISASSOC)) == 0) {
  1712. int skip = strlen(CMD_HAPD_STA_DISASSOC) + 1;
  1713. wl_android_sta_diassoc(net, (const char*)command+skip);
  1714. }
  1715. #endif /* SUPPORT_SOFTAP_SINGL_DISASSOC */
  1716. #ifdef SUPPORT_SET_LPC
  1717. else if (strnicmp(command, CMD_HAPD_LPC_ENABLED,
  1718. strlen(CMD_HAPD_LPC_ENABLED)) == 0) {
  1719. int skip = strlen(CMD_HAPD_LPC_ENABLED) + 3;
  1720. wl_android_set_lpc(net, (const char*)command+skip);
  1721. }
  1722. #endif /* SUPPORT_SET_LPC */
  1723. #ifdef SUPPORT_TRIGGER_HANG_EVENT
  1724. else if (strnicmp(command, CMD_TEST_FORCE_HANG,
  1725. strlen(CMD_TEST_FORCE_HANG)) == 0) {
  1726. net_os_send_hang_message(net);
  1727. }
  1728. #endif /* SUPPORT_TRIGGER_HANG_EVENT */
  1729. else if (strnicmp(command, CMD_CHANGE_RL, strlen(CMD_CHANGE_RL)) == 0)
  1730. bytes_written = wl_android_ch_res_rl(net, true);
  1731. else if (strnicmp(command, CMD_RESTORE_RL, strlen(CMD_RESTORE_RL)) == 0)
  1732. bytes_written = wl_android_ch_res_rl(net, false);
  1733. #endif /* CUSTOMER_HW4 */
  1734. else if (strnicmp(command, CMD_SETROAMMODE, strlen(CMD_SETROAMMODE)) == 0)
  1735. bytes_written = wl_android_set_roam_mode(net, command, priv_cmd.total_len);
  1736. else {
  1737. DHD_ERROR(("Unknown PRIVATE command %s - ignored\n", command));
  1738. snprintf(command, 3, "OK");
  1739. bytes_written = strlen("OK");
  1740. }
  1741. if (bytes_written >= 0) {
  1742. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  1743. command[0] = '\0';
  1744. if (bytes_written >= priv_cmd.total_len) {
  1745. DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written));
  1746. bytes_written = priv_cmd.total_len;
  1747. } else {
  1748. bytes_written++;
  1749. }
  1750. priv_cmd.used_len = bytes_written;
  1751. if (copy_to_user(priv_cmd.buf, command, bytes_written)) {
  1752. DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__));
  1753. ret = -EFAULT;
  1754. }
  1755. }
  1756. else {
  1757. ret = bytes_written;
  1758. }
  1759. exit:
  1760. net_os_wake_unlock(net);
  1761. if (command) {
  1762. kfree(command);
  1763. }
  1764. return ret;
  1765. }
  1766. int wl_android_init(void)
  1767. {
  1768. int ret = 0;
  1769. #ifdef ENABLE_INSMOD_NO_FW_LOAD
  1770. dhd_download_fw_on_driverload = FALSE;
  1771. #endif /* ENABLE_INSMOD_NO_FW_LOAD */
  1772. #if defined(CUSTOMER_HW2) || defined(CUSTOMER_HW4)
  1773. if (!iface_name[0]) {
  1774. memset(iface_name, 0, IFNAMSIZ);
  1775. bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ);
  1776. }
  1777. #endif /* CUSTOMER_HW2 || CUSTOMER_HW4 */
  1778. #ifdef WL_GENL
  1779. wl_genl_init();
  1780. #endif
  1781. return ret;
  1782. }
  1783. int wl_android_exit(void)
  1784. {
  1785. int ret = 0;
  1786. #ifdef WL_GENL
  1787. wl_genl_deinit();
  1788. #endif /* WL_GENL */
  1789. return ret;
  1790. }
  1791. void wl_android_post_init(void)
  1792. {
  1793. #ifdef ENABLE_4335BT_WAR
  1794. bcm_bt_unlock(lock_cookie_wifi);
  1795. printk("%s: btlock released\n", __FUNCTION__);
  1796. #endif /* ENABLE_4335BT_WAR */
  1797. if (!dhd_download_fw_on_driverload) {
  1798. /* Call customer gpio to turn off power with WL_REG_ON signal */
  1799. dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF);
  1800. g_wifi_on = 0;
  1801. }
  1802. }
  1803. #ifdef WL_GENL
  1804. /* Generic Netlink Initializaiton */
  1805. static int wl_genl_init(void)
  1806. {
  1807. int ret;
  1808. WL_DBG(("GEN Netlink Init\n\n"));
  1809. /* register new family */
  1810. ret = genl_register_family(&wl_genl_family);
  1811. if (ret != 0)
  1812. goto failure;
  1813. /* register functions (commands) of the new family */
  1814. ret = genl_register_ops(&wl_genl_family, &wl_genl_ops);
  1815. if (ret != 0) {
  1816. WL_ERR(("register ops failed: %i\n", ret));
  1817. genl_unregister_family(&wl_genl_family);
  1818. goto failure;
  1819. }
  1820. ret = genl_register_mc_group(&wl_genl_family, &wl_genl_mcast);
  1821. if (ret != 0) {
  1822. WL_ERR(("register mc_group failed: %i\n", ret));
  1823. genl_unregister_ops(&wl_genl_family, &wl_genl_ops);
  1824. genl_unregister_family(&wl_genl_family);
  1825. goto failure;
  1826. }
  1827. return 0;
  1828. failure:
  1829. WL_ERR(("Registering Netlink failed!!\n"));
  1830. return -1;
  1831. }
  1832. /* Generic netlink deinit */
  1833. static int wl_genl_deinit(void)
  1834. {
  1835. if (genl_unregister_ops(&wl_genl_family, &wl_genl_ops) < 0)
  1836. WL_ERR(("Unregister wl_genl_ops failed\n"));
  1837. if (genl_unregister_family(&wl_genl_family) < 0)
  1838. WL_ERR(("Unregister wl_genl_ops failed\n"));
  1839. return 0;
  1840. }
  1841. s32 wl_event_to_bcm_event(u16 event_type)
  1842. {
  1843. u16 event = -1;
  1844. switch (event_type) {
  1845. case WLC_E_SERVICE_FOUND:
  1846. event = BCM_E_SVC_FOUND;
  1847. break;
  1848. case WLC_E_P2PO_ADD_DEVICE:
  1849. event = BCM_E_DEV_FOUND;
  1850. break;
  1851. case WLC_E_P2PO_DEL_DEVICE:
  1852. event = BCM_E_DEV_LOST;
  1853. break;
  1854. /* Above events are supported from BCM Supp ver 47 Onwards */
  1855. default:
  1856. WL_ERR(("Event not supported\n"));
  1857. }
  1858. return event;
  1859. }
  1860. s32
  1861. wl_genl_send_msg(
  1862. struct net_device *ndev,
  1863. u32 event_type,
  1864. u8 *buf,
  1865. u16 len,
  1866. u8 *subhdr,
  1867. u16 subhdr_len)
  1868. {
  1869. int ret = 0;
  1870. struct sk_buff *skb;
  1871. void *msg;
  1872. u32 attr_type = 0;
  1873. bcm_event_hdr_t *hdr = NULL;
  1874. int mcast = 1; /* By default sent as mutlicast type */
  1875. int pid = 0;
  1876. u8 *ptr = NULL, *p = NULL;
  1877. u32 tot_len = sizeof(bcm_event_hdr_t) + subhdr_len + len;
  1878. u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
  1879. WL_DBG(("Enter \n"));
  1880. /* Decide between STRING event and Data event */
  1881. if (event_type == 0)
  1882. attr_type = BCM_GENL_ATTR_STRING;
  1883. else
  1884. attr_type = BCM_GENL_ATTR_MSG;
  1885. skb = genlmsg_new(NLMSG_GOODSIZE, kflags);
  1886. if (skb == NULL) {
  1887. ret = -ENOMEM;
  1888. goto out;
  1889. }
  1890. msg = genlmsg_put(skb, 0, 0, &wl_genl_family, 0, BCM_GENL_CMD_MSG);
  1891. if (msg == NULL) {
  1892. ret = -ENOMEM;
  1893. goto out;
  1894. }
  1895. if (attr_type == BCM_GENL_ATTR_STRING) {
  1896. /* Add a BCM_GENL_MSG attribute. Since it is specified as a string.
  1897. * make sure it is null terminated
  1898. */
  1899. if (subhdr || subhdr_len) {
  1900. WL_ERR(("No sub hdr support for the ATTR STRING type \n"));
  1901. ret = -EINVAL;
  1902. goto out;
  1903. }
  1904. ret = nla_put_string(skb, BCM_GENL_ATTR_STRING, buf);
  1905. if (ret != 0) {
  1906. WL_ERR(("nla_put_string failed\n"));
  1907. goto out;
  1908. }
  1909. } else {
  1910. /* ATTR_MSG */
  1911. /* Create a single buffer for all */
  1912. p = ptr = kzalloc(tot_len, kflags);
  1913. if (!ptr) {
  1914. ret = -ENOMEM;
  1915. WL_ERR(("ENOMEM!!\n"));
  1916. goto out;
  1917. }
  1918. /* Include the bcm event header */
  1919. hdr = (bcm_event_hdr_t *)ptr;
  1920. hdr->event_type = wl_event_to_bcm_event(event_type);
  1921. hdr->len = len + subhdr_len;
  1922. ptr += sizeof(bcm_event_hdr_t);
  1923. /* Copy subhdr (if any) */
  1924. if (subhdr && subhdr_len) {
  1925. memcpy(ptr, subhdr, subhdr_len);
  1926. ptr += subhdr_len;
  1927. }
  1928. /* Copy the data */
  1929. if (buf && len) {
  1930. memcpy(ptr, buf, len);
  1931. }
  1932. ret = nla_put(skb, BCM_GENL_ATTR_MSG, tot_len, p);
  1933. if (ret != 0) {
  1934. WL_ERR(("nla_put_string failed\n"));
  1935. goto out;
  1936. }
  1937. }
  1938. if (mcast) {
  1939. int err = 0;
  1940. /* finalize the message */
  1941. genlmsg_end(skb, msg);
  1942. /* NETLINK_CB(skb).dst_group = 1; */
  1943. if ((err = genlmsg_multicast(skb, 0, wl_genl_mcast.id, GFP_ATOMIC)) < 0)
  1944. WL_ERR(("genlmsg_multicast for attr(%d) failed. Error:%d \n",
  1945. attr_type, err));
  1946. else
  1947. WL_DBG(("Multicast msg sent successfully. attr_type:%d len:%d \n",
  1948. attr_type, tot_len));
  1949. } else {
  1950. NETLINK_CB(skb).dst_group = 0; /* Not in multicast group */
  1951. /* finalize the message */
  1952. genlmsg_end(skb, msg);
  1953. /* send the message back */
  1954. if (genlmsg_unicast(&init_net, skb, pid) < 0)
  1955. WL_ERR(("genlmsg_unicast failed\n"));
  1956. }
  1957. out:
  1958. if (p)
  1959. kfree(p);
  1960. if (ret)
  1961. nlmsg_free(skb);
  1962. return ret;
  1963. }
  1964. static s32
  1965. wl_genl_handle_msg(
  1966. struct sk_buff *skb,
  1967. struct genl_info *info)
  1968. {
  1969. struct nlattr *na;
  1970. u8 *data = NULL;
  1971. WL_DBG(("Enter \n"));
  1972. if (info == NULL) {
  1973. return -EINVAL;
  1974. }
  1975. na = info->attrs[BCM_GENL_ATTR_MSG];
  1976. if (!na) {
  1977. WL_ERR(("nlattribute NULL\n"));
  1978. return -EINVAL;
  1979. }
  1980. data = (char *)nla_data(na);
  1981. if (!data) {
  1982. WL_ERR(("Invalid data\n"));
  1983. return -EINVAL;
  1984. } else {
  1985. /* Handle the data */
  1986. WL_DBG(("Data received from pid (%d) \n", info->snd_pid));
  1987. }
  1988. return 0;
  1989. }
  1990. #endif /* WL_GENL */
  1991. /**
  1992. * Functions for Android WiFi card detection
  1993. */
  1994. #if defined(CONFIG_WIFI_CONTROL_FUNC)
  1995. bool g_wifi_poweron = FALSE;
  1996. static int g_wifidev_registered = 0;
  1997. static struct semaphore wifi_control_sem;
  1998. static struct wifi_platform_data *wifi_control_data = NULL;
  1999. static struct resource *wifi_irqres = NULL;
  2000. static int wifi_add_dev(void);
  2001. static void wifi_del_dev(void);
  2002. int wl_android_wifictrl_func_add(void)
  2003. {
  2004. int ret = 0;
  2005. sema_init(&wifi_control_sem, 0);
  2006. ret = wifi_add_dev();
  2007. if (ret) {
  2008. DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__));
  2009. return ret;
  2010. }
  2011. g_wifidev_registered = 1;
  2012. /* Waiting callback after platform_driver_register is done or exit with error */
  2013. if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
  2014. ret = -EINVAL;
  2015. DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__));
  2016. }
  2017. return ret;
  2018. }
  2019. void wl_android_wifictrl_func_del(void)
  2020. {
  2021. if (g_wifidev_registered)
  2022. {
  2023. wifi_del_dev();
  2024. g_wifidev_registered = 0;
  2025. }
  2026. }
  2027. void* wl_android_prealloc(int section, unsigned long size)
  2028. {
  2029. void *alloc_ptr = NULL;
  2030. if (wifi_control_data && wifi_control_data->mem_prealloc) {
  2031. alloc_ptr = wifi_control_data->mem_prealloc(section, size);
  2032. if (alloc_ptr) {
  2033. DHD_INFO(("success alloc section %d\n", section));
  2034. if (size != 0L)
  2035. bzero(alloc_ptr, size);
  2036. return alloc_ptr;
  2037. }
  2038. }
  2039. DHD_ERROR(("can't alloc section %d\n", section));
  2040. return NULL;
  2041. }
  2042. int wifi_get_irq_number(unsigned long *irq_flags_ptr)
  2043. {
  2044. if (wifi_irqres) {
  2045. *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
  2046. return (int)wifi_irqres->start;
  2047. }
  2048. #ifdef CUSTOM_OOB_GPIO_NUM
  2049. return CUSTOM_OOB_GPIO_NUM;
  2050. #else
  2051. return -1;
  2052. #endif
  2053. }
  2054. int wifi_set_power(int on, unsigned long msec)
  2055. {
  2056. int ret = 0;
  2057. DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
  2058. if (wifi_control_data && wifi_control_data->set_power) {
  2059. #ifdef ENABLE_4335BT_WAR
  2060. if (on) {
  2061. printk("WiFi: trying to acquire BT lock\n");
  2062. if (bcm_bt_lock(lock_cookie_wifi) != 0)
  2063. printk("** WiFi: timeout in acquiring bt lock**\n");
  2064. printk("%s: btlock acquired\n", __FUNCTION__);
  2065. }
  2066. else {
  2067. /* For a exceptional case, release btlock */
  2068. bcm_bt_unlock(lock_cookie_wifi);
  2069. }
  2070. #endif /* ENABLE_4335BT_WAR */
  2071. ret = wifi_control_data->set_power(on);
  2072. }
  2073. if (msec && !ret)
  2074. msleep(msec);
  2075. return ret;
  2076. }
  2077. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  2078. int wifi_get_mac_addr(unsigned char *buf)
  2079. {
  2080. DHD_ERROR(("%s\n", __FUNCTION__));
  2081. if (!buf)
  2082. return -EINVAL;
  2083. if (wifi_control_data && wifi_control_data->get_mac_addr) {
  2084. return wifi_control_data->get_mac_addr(buf);
  2085. }
  2086. return -EOPNOTSUPP;
  2087. }
  2088. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
  2089. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39))
  2090. void *wifi_get_country_code(char *ccode)
  2091. {
  2092. DHD_TRACE(("%s\n", __FUNCTION__));
  2093. if (!ccode)
  2094. return NULL;
  2095. if (wifi_control_data && wifi_control_data->get_country_code) {
  2096. return wifi_control_data->get_country_code(ccode);
  2097. }
  2098. return NULL;
  2099. }
  2100. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  2101. static int wifi_set_carddetect(int on)
  2102. {
  2103. DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
  2104. if (wifi_control_data && wifi_control_data->set_carddetect) {
  2105. wifi_control_data->set_carddetect(on);
  2106. }
  2107. return 0;
  2108. }
  2109. static int wifi_probe(struct platform_device *pdev)
  2110. {
  2111. int err;
  2112. struct wifi_platform_data *wifi_ctrl =
  2113. (struct wifi_platform_data *)(pdev->dev.platform_data);
  2114. wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  2115. if (wifi_irqres == NULL)
  2116. wifi_irqres = platform_get_resource_byname(pdev,
  2117. IORESOURCE_IRQ, "bcm4329_wlan_irq");
  2118. wifi_control_data = wifi_ctrl;
  2119. err = wifi_set_power(1, 200); /* Power On */
  2120. if (unlikely(err)) {
  2121. DHD_ERROR(("%s: set_power failed. err=%d\n", __FUNCTION__, err));
  2122. wifi_set_power(0, WIFI_TURNOFF_DELAY);
  2123. /* WL_REG_ON state unknown, Power off forcely */
  2124. } else {
  2125. wifi_set_carddetect(1); /* CardDetect (0->1) */
  2126. g_wifi_poweron = TRUE;
  2127. }
  2128. up(&wifi_control_sem);
  2129. return 0;
  2130. }
  2131. static int wifi_remove(struct platform_device *pdev)
  2132. {
  2133. struct wifi_platform_data *wifi_ctrl =
  2134. (struct wifi_platform_data *)(pdev->dev.platform_data);
  2135. DHD_ERROR(("## %s\n", __FUNCTION__));
  2136. wifi_control_data = wifi_ctrl;
  2137. if (g_wifi_poweron) {
  2138. wifi_set_power(0, WIFI_TURNOFF_DELAY); /* Power Off */
  2139. wifi_set_carddetect(0); /* CardDetect (1->0) */
  2140. g_wifi_poweron = FALSE;
  2141. }
  2142. up(&wifi_control_sem);
  2143. return 0;
  2144. }
  2145. static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
  2146. {
  2147. DHD_TRACE(("##> %s\n", __FUNCTION__));
  2148. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY) && 1
  2149. bcmsdh_oob_intr_set(0);
  2150. #endif /* (OOB_INTR_ONLY) */
  2151. return 0;
  2152. }
  2153. static int wifi_resume(struct platform_device *pdev)
  2154. {
  2155. DHD_TRACE(("##> %s\n", __FUNCTION__));
  2156. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY) && 1
  2157. if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
  2158. bcmsdh_oob_intr_set(1);
  2159. #endif /* (OOB_INTR_ONLY) */
  2160. return 0;
  2161. }
  2162. static struct platform_driver wifi_device = {
  2163. .probe = wifi_probe,
  2164. .remove = wifi_remove,
  2165. .suspend = wifi_suspend,
  2166. .resume = wifi_resume,
  2167. .driver = {
  2168. .name = "bcmdhd_wlan",
  2169. }
  2170. };
  2171. static struct platform_driver wifi_device_legacy = {
  2172. .probe = wifi_probe,
  2173. .remove = wifi_remove,
  2174. .suspend = wifi_suspend,
  2175. .resume = wifi_resume,
  2176. .driver = {
  2177. .name = "bcm4329_wlan",
  2178. }
  2179. };
  2180. static int wifi_add_dev(void)
  2181. {
  2182. int ret = 0;
  2183. DHD_TRACE(("## Calling platform_driver_register\n"));
  2184. ret = platform_driver_register(&wifi_device);
  2185. if (ret)
  2186. return ret;
  2187. ret = platform_driver_register(&wifi_device_legacy);
  2188. return ret;
  2189. }
  2190. static void wifi_del_dev(void)
  2191. {
  2192. DHD_TRACE(("## Unregister platform_driver_register\n"));
  2193. platform_driver_unregister(&wifi_device);
  2194. platform_driver_unregister(&wifi_device_legacy);
  2195. }
  2196. #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */