Home | History | Annotate | Download | only in wpa_supplicant_8_lib
      1 /*
      2  * Driver interaction with extended Linux CFG8021
      3  *
      4  * This program is free software; you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License version 2 as
      6  * published by the Free Software Foundation.
      7  *
      8  * Alternatively, this software may be distributed under the terms of BSD
      9  * license.
     10  *
     11  */
     12 
     13 #include "hardware_legacy/driver_nl80211.h"
     14 #include "wpa_supplicant_i.h"
     15 #include "config.h"
     16 #ifdef ANDROID
     17 #include "android_drv.h"
     18 #endif
     19 
     20 #define MAX_WPSP2PIE_CMD_SIZE		512
     21 
     22 typedef struct android_wifi_priv_cmd {
     23 	char *buf;
     24 	int used_len;
     25 	int total_len;
     26 } android_wifi_priv_cmd;
     27 
     28 static int drv_errors = 0;
     29 
     30 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv)
     31 {
     32 	drv_errors++;
     33 	if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) {
     34 		drv_errors = 0;
     35 		wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED");
     36 	}
     37 }
     38 
     39 int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
     40 				  size_t buf_len )
     41 {
     42 	struct i802_bss *bss = priv;
     43 	struct wpa_driver_nl80211_data *drv = bss->drv;
     44 	struct ifreq ifr;
     45 	android_wifi_priv_cmd priv_cmd;
     46 	int ret = 0;
     47 
     48 	if (os_strcasecmp(cmd, "STOP") == 0) {
     49 		linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0);
     50 		wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED");
     51 	} else if (os_strcasecmp(cmd, "START") == 0) {
     52 		linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
     53 		wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED");
     54 	} else if (os_strcasecmp(cmd, "MACADDR") == 0) {
     55 		u8 macaddr[ETH_ALEN] = {};
     56 
     57 		ret = linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, macaddr);
     58 		if (!ret)
     59 			ret = os_snprintf(buf, buf_len,
     60 					  "Macaddr = " MACSTR "\n", MAC2STR(macaddr));
     61 	} else { /* Use private command */
     62 		memset(&ifr, 0, sizeof(ifr));
     63 		memset(&priv_cmd, 0, sizeof(priv_cmd));
     64 		os_memcpy(buf, cmd, strlen(cmd) + 1);
     65 		os_strncpy(ifr.ifr_name, bss->ifname, IFNAMSIZ);
     66 
     67 		priv_cmd.buf = buf;
     68 		priv_cmd.used_len = buf_len;
     69 		priv_cmd.total_len = buf_len;
     70 		ifr.ifr_data = &priv_cmd;
     71 
     72 		if ((ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) {
     73 			wpa_printf(MSG_ERROR, "%s: failed to issue private commands\n", __func__);
     74 		} else {
     75 			drv_errors = 0;
     76 			ret = 0;
     77 			if ((os_strcasecmp(cmd, "LINKSPEED") == 0) ||
     78 			    (os_strcasecmp(cmd, "RSSI") == 0) ||
     79 			    (os_strcasecmp(cmd, "GETBAND") == 0) )
     80 				ret = strlen(buf);
     81 			else if (os_strcasecmp(cmd, "COUNTRY") == 0)
     82 				wpa_supplicant_event(drv->ctx,
     83 					EVENT_CHANNEL_LIST_CHANGED, NULL);
     84 			else if (os_strncasecmp(cmd, "SETBAND", 7) == 0)
     85 				wpa_printf(MSG_DEBUG, "%s: %s ", __func__, cmd);
     86 			else if (os_strcasecmp(cmd, "P2P_DEV_ADDR") == 0)
     87 				wpa_printf(MSG_DEBUG, "%s: P2P: Device address ("MACSTR")",
     88 					__func__, MAC2STR(buf));
     89 			else if (os_strcasecmp(cmd, "P2P_SET_PS") == 0)
     90 				wpa_printf(MSG_DEBUG, "%s: P2P: %s ", __func__, buf);
     91 			else if (os_strcasecmp(cmd, "P2P_SET_NOA") == 0)
     92 				wpa_printf(MSG_DEBUG, "%s: P2P: %s ", __func__, buf);
     93 			else
     94 				wpa_printf(MSG_DEBUG, "%s %s len = %d, %d", __func__, buf, ret, strlen(buf));
     95 		}
     96 	}
     97 	return ret;
     98 }
     99 
    100 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration)
    101 {
    102 	char buf[MAX_DRV_CMD_SIZE];
    103 
    104 	memset(buf, 0, sizeof(buf));
    105 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
    106 	snprintf(buf, sizeof(buf), "P2P_SET_NOA %d %d %d", count, start, duration);
    107 	return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf)+1);
    108 }
    109 
    110 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len)
    111 {
    112 	/* Return 0 till we handle p2p_presence request completely in the driver */
    113 	return 0;
    114 }
    115 
    116 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow)
    117 {
    118 	char buf[MAX_DRV_CMD_SIZE];
    119 
    120 	memset(buf, 0, sizeof(buf));
    121 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
    122 	snprintf(buf, sizeof(buf), "P2P_SET_PS %d %d %d", legacy_ps, opp_ps, ctwindow);
    123 	return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf) + 1);
    124 }
    125 
    126 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
    127 				 const struct wpabuf *proberesp,
    128 				 const struct wpabuf *assocresp)
    129 {
    130 	char buf[MAX_WPSP2PIE_CMD_SIZE];
    131 	struct wpabuf *ap_wps_p2p_ie = NULL;
    132 	char *_cmd = "SET_AP_WPS_P2P_IE";
    133 	char *pbuf;
    134 	int ret = 0;
    135 	int i;
    136 	struct cmd_desc {
    137 		int cmd;
    138 		const struct wpabuf *src;
    139 	} cmd_arr[] = {
    140 		{0x1, beacon},
    141 		{0x2, proberesp},
    142 		{0x4, assocresp},
    143 		{-1, NULL}
    144 	};
    145 
    146 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
    147 	for (i = 0; cmd_arr[i].cmd != -1; i++) {
    148 		os_memset(buf, 0, sizeof(buf));
    149 		pbuf = buf;
    150 		pbuf += sprintf(pbuf, "%s %d", _cmd, cmd_arr[i].cmd);
    151 		*pbuf++ = '\0';
    152 		ap_wps_p2p_ie = cmd_arr[i].src ?
    153 			wpabuf_dup(cmd_arr[i].src) : NULL;
    154 		if (ap_wps_p2p_ie) {
    155 			os_memcpy(pbuf, wpabuf_head(ap_wps_p2p_ie), wpabuf_len(ap_wps_p2p_ie));
    156 			ret = wpa_driver_nl80211_driver_cmd(priv, buf, buf,
    157 				strlen(_cmd) + 3 + wpabuf_len(ap_wps_p2p_ie));
    158 			wpabuf_free(ap_wps_p2p_ie);
    159 			if (ret < 0)
    160 				break;
    161 		}
    162 	}
    163 
    164 	return ret;
    165 }
    166