int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, size_t buf_len ) { struct i802_bss *bss = priv; struct wpa_driver_nl80211_data *drv = bss->drv; struct ifreq ifr; android_wifi_priv_cmd priv_cmd; int ret = 0; if (os_strcasecmp(cmd, "STOP") == 0) { linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0); wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED"); } else if (os_strcasecmp(cmd, "START") == 0) { linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED"); } else if (os_strcasecmp(cmd, "MACADDR") == 0) { u8 macaddr[ETH_ALEN] = {}; ret = linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, macaddr); if (!ret) ret = os_snprintf(buf, buf_len, "Macaddr = " MACSTR "\n", MAC2STR(macaddr)); } else { /* Use private command */ memset(&ifr, 0, sizeof(ifr)); memset(&priv_cmd, 0, sizeof(priv_cmd)); os_memcpy(buf, cmd, strlen(cmd) + 1); os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); priv_cmd.buf = buf; priv_cmd.used_len = buf_len; priv_cmd.total_len = buf_len; ifr.ifr_data = &priv_cmd; if ((ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) { wpa_printf(MSG_ERROR, "%s: failed to issue private commands\n", __func__); } else { drv_errors = 0; ret = 0; if ((os_strcasecmp(cmd, "LINKSPEED") == 0) || (os_strcasecmp(cmd, "RSSI") == 0) || (os_strcasecmp(cmd, "GETBAND") == 0) ) ret = strlen(buf); else if (os_strcasecmp(cmd, "P2P_DEV_ADDR") == 0) wpa_printf(MSG_DEBUG, "%s: P2P: Device address ("MACSTR")", __func__, MAC2STR(buf)); else if (os_strcasecmp(cmd, "P2P_SET_PS") == 0) wpa_printf(MSG_DEBUG, "%s: P2P: %s ", __func__, buf); else if (os_strcasecmp(cmd, "P2P_SET_NOA") == 0) wpa_printf(MSG_DEBUG, "%s: P2P: %s ", __func__, buf); else wpa_printf(MSG_DEBUG, "%s %s len = %d, %d", __func__, buf, ret, strlen(buf)); wpa_driver_notify_country_change(drv->ctx, cmd); } } return ret; }
int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, size_t buf_len ) { struct i802_bss *bss = priv; struct wpa_driver_nl80211_data *drv = bss->drv; struct ifreq ifr; struct wpa_supplicant *wpa_s; struct hostapd_data *hapd; int handled = 0; int cmd_len = 0; union wpa_event_data event; static int user_force_band = 0; int ret = -1; if (drv == NULL) { wpa_printf(MSG_ERROR, "%s: drv is NULL. Exiting", __func__); return -1; } if (drv->ctx == NULL) { wpa_printf(MSG_ERROR, "%s: drv->ctx is NULL. Exiting", __func__); return -1; } if (os_strcmp(bss->ifname, "ap0") == 0) { hapd = (struct hostapd_data *)(drv->ctx); } else { wpa_s = (struct wpa_supplicant *)(drv->ctx); if (wpa_s->conf == NULL) { wpa_printf(MSG_ERROR, "%s: wpa_s->conf is NULL. Exiting", __func__); return -1; } } wpa_printf(MSG_DEBUG, "iface %s recv cmd %s", bss->ifname, cmd); handled = 1; if (os_strncasecmp(cmd, "POWERMODE ", 10) == 0) { int state; state = atoi(cmd + 10); wpa_printf(MSG_DEBUG, "POWERMODE=%d", state); } else if (os_strncmp(cmd, "MACADDR", os_strlen("MACADDR")) == 0) { u8 macaddr[ETH_ALEN] = {}; os_memcpy(&macaddr, wpa_s->own_addr, ETH_ALEN); ret = snprintf(buf, buf_len, "Macaddr = " MACSTR "\n", MAC2STR(macaddr)); wpa_printf(MSG_DEBUG, "%s", buf); } else if(os_strncasecmp(cmd, "COUNTRY", os_strlen("COUNTRY"))==0) { if (os_strlen(cmd) != os_strlen("COUNTRY") + 3) { wpa_printf(MSG_DEBUG, "Ignore COUNTRY cmd %s", cmd); ret = 0; } else { wpa_printf(MSG_INFO, "set country: %s", cmd+8); // ret = wpa_drv_set_country(wpa_s, cmd+8); ret = wpa_driver_mediatek_set_country(priv, cmd+8); if (ret == 0) { wpa_printf(MSG_DEBUG, "Update channel list after country code changed"); wpa_driver_notify_country_change(wpa_s, cmd); } } } else if (os_strcasecmp(cmd, "start") == 0) { if (ret = linux_set_iface_flags(drv->global->ioctl_sock, drv->first_bss->ifname, 1)) { wpa_printf(MSG_INFO, "nl80211: Could not set interface UP, ret=%d \n", ret); } else { wpa_msg(drv->ctx, MSG_INFO, "CTRL-EVENT-DRIVER-STATE STARTED"); } } else if (os_strcasecmp(cmd, "stop") == 0) { if (drv->associated) { ret = wpa_drv_deauthenticate(wpa_s, drv->bssid, WLAN_REASON_DEAUTH_LEAVING); if (ret != 0) wpa_printf(MSG_DEBUG, "DRIVER-STOP error, ret=%d", ret); } else { wpa_printf(MSG_INFO, "nl80211: not associated, no need to deauthenticate \n"); } if (ret = linux_set_iface_flags(drv->global->ioctl_sock, drv->first_bss->ifname, 0)) { wpa_printf(MSG_INFO, "nl80211: Could not set interface Down, ret=%d \n", ret); } else { wpa_msg(drv->ctx, MSG_INFO, "CTRL-EVENT-DRIVER-STATE STOPPED"); } } else if (os_strncasecmp(cmd, "getpower", 8) == 0) { u32 mode; // ret = wpa_driver_wext_driver_get_power(drv, &mode); if (ret == 0) { ret = snprintf(buf, buf_len, "powermode = %u\n", mode); wpa_printf(MSG_DEBUG, "%s", buf); if (ret < (int)buf_len) return ret; } } else if (os_strncasecmp(cmd, "get-rts-threshold", 17) == 0) { u32 thd; // ret = wpa_driver_wext_driver_get_rts(drv, &thd); if (ret == 0) { ret = snprintf(buf, buf_len, "rts-threshold = %u\n", thd); wpa_printf(MSG_DEBUG, "%s", buf); if (ret < (int)buf_len) return ret; } } else if (os_strncasecmp(cmd, "set-rts-threshold", 17) == 0) { u32 thd = 0; char *cp = cmd + 17; char *endp; if (*cp != '\0') { thd = (u32)strtol(cp, &endp, 0); // if (endp != cp) // ret = wpa_driver_wext_driver_set_rts(drv, thd); } } else if (os_strcasecmp(cmd, "btcoexscan-start") == 0) { ret = 0; /* mt5921 linux driver not implement yet */ } else if (os_strcasecmp(cmd, "btcoexscan-stop") == 0) { ret = 0; /* mt5921 linux driver not implement yet */ } else if (os_strncasecmp(cmd, "btcoexmode", 10) == 0) { ret = 0; /* mt5921 linux driver not implement yet */ } else { handled = 0; wpa_printf(MSG_INFO, "Unsupported command"); } return ret; }