• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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 
wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data * drv)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 
wpa_driver_nl80211_driver_cmd(void * priv,char * cmd,char * buf,size_t buf_len)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 		os_memcpy(buf, cmd, strlen(cmd) + 1);
63 		memset(&ifr, 0, sizeof(ifr));
64 		memset(&priv_cmd, 0, sizeof(priv_cmd));
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 			wpa_driver_send_hang_msg(drv);
75 		} else {
76 			drv_errors = 0;
77 			ret = 0;
78 			if ((os_strcasecmp(cmd, "LINKSPEED") == 0) ||
79 			    (os_strcasecmp(cmd, "RSSI") == 0) ||
80 			    (os_strcasecmp(cmd, "GETBAND") == 0) )
81 				ret = strlen(buf);
82 			else if (os_strncasecmp(cmd, "COUNTRY", 7) == 0)
83 				wpa_supplicant_event(drv->ctx,
84 					EVENT_CHANNEL_LIST_CHANGED, NULL);
85 			wpa_printf(MSG_DEBUG, "%s %s len = %d, %d", __func__, buf, ret, strlen(buf));
86 		}
87 	}
88 	return ret;
89 }
90 
wpa_driver_set_p2p_noa(void * priv,u8 count,int start,int duration)91 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration)
92 {
93 	char buf[MAX_DRV_CMD_SIZE];
94 
95 	memset(buf, 0, sizeof(buf));
96 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
97 	snprintf(buf, sizeof(buf), "P2P_SET_NOA %d %d %d", count, start, duration);
98 	return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf)+1);
99 }
100 
wpa_driver_get_p2p_noa(void * priv,u8 * buf,size_t len)101 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len)
102 {
103 	/* Return 0 till we handle p2p_presence request completely in the driver */
104 	return 0;
105 }
106 
wpa_driver_set_p2p_ps(void * priv,int legacy_ps,int opp_ps,int ctwindow)107 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow)
108 {
109 	char buf[MAX_DRV_CMD_SIZE];
110 
111 	memset(buf, 0, sizeof(buf));
112 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
113 	snprintf(buf, sizeof(buf), "P2P_SET_PS %d %d %d", legacy_ps, opp_ps, ctwindow);
114 	return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf) + 1);
115 }
116 
wpa_driver_set_ap_wps_p2p_ie(void * priv,const struct wpabuf * beacon,const struct wpabuf * proberesp,const struct wpabuf * assocresp)117 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
118 				 const struct wpabuf *proberesp,
119 				 const struct wpabuf *assocresp)
120 {
121 	char buf[MAX_WPSP2PIE_CMD_SIZE];
122 	struct wpabuf *ap_wps_p2p_ie = NULL;
123 	char *_cmd = "SET_AP_WPS_P2P_IE";
124 	char *pbuf;
125 	int ret = 0;
126 	int i;
127 	struct cmd_desc {
128 		int cmd;
129 		const struct wpabuf *src;
130 	} cmd_arr[] = {
131 		{0x1, beacon},
132 		{0x2, proberesp},
133 		{0x4, assocresp},
134 		{-1, NULL}
135 	};
136 
137 	wpa_printf(MSG_DEBUG, "%s: Entry", __func__);
138 	for (i = 0; cmd_arr[i].cmd != -1; i++) {
139 		os_memset(buf, 0, sizeof(buf));
140 		pbuf = buf;
141 		pbuf += sprintf(pbuf, "%s %d", _cmd, cmd_arr[i].cmd);
142 		*pbuf++ = '\0';
143 		ap_wps_p2p_ie = cmd_arr[i].src ?
144 			wpabuf_dup(cmd_arr[i].src) : NULL;
145 		if (ap_wps_p2p_ie) {
146 			os_memcpy(pbuf, wpabuf_head(ap_wps_p2p_ie), wpabuf_len(ap_wps_p2p_ie));
147 			ret = wpa_driver_nl80211_driver_cmd(priv, buf, buf,
148 				strlen(_cmd) + 3 + wpabuf_len(ap_wps_p2p_ie));
149 			wpabuf_free(ap_wps_p2p_ie);
150 			if (ret < 0)
151 				break;
152 		}
153 	}
154 
155 	return ret;
156 }
157