Commit | Line | Data |
---|---|---|
02b2b8ab S |
1 | #include <stdint.h>\r |
2 | #include <stddef.h>\r | |
3 | #include <fcntl.h>\r | |
4 | #include <sys/socket.h>\r | |
5 | #include <netlink/genl/genl.h>\r | |
6 | #include <netlink/genl/family.h>\r | |
7 | #include <netlink/genl/ctrl.h>\r | |
8 | #include <linux/rtnetlink.h>\r | |
9 | #include <netpacket/packet.h>\r | |
10 | #include <linux/filter.h>\r | |
11 | #include <linux/errqueue.h>\r | |
12 | \r | |
13 | #include <linux/pkt_sched.h>\r | |
14 | #include <netlink/object-api.h>\r | |
15 | #include <netlink/netlink.h>\r | |
16 | #include <netlink/socket.h>\r | |
17 | #include <netlink/handlers.h>\r | |
18 | \r | |
19 | #include "sync.h"\r | |
20 | \r | |
21 | #define LOG_TAG "WifiHAL"\r | |
22 | \r | |
23 | #include <utils/Log.h>\r | |
24 | \r | |
25 | #include "wifi_hal.h"\r | |
26 | #include "common.h"\r | |
27 | #include "cpp_bindings.h"\r | |
28 | \r | |
29 | #define REQUEST_ID_MAX 1000\r | |
30 | #define get_requestid() ((arc4random()%REQUEST_ID_MAX) + 1)\r | |
31 | \r | |
47e18f37 JPS |
32 | enum roam_attributes {\r |
33 | SLSI_ATTR_ROAM_CAPABILITY_BLACKLIST_SIZE,\r | |
34 | SLSI_ATTR_ROAM_CAPABILITY_WHITELIST_SIZE,\r | |
35 | SLSI_ATTR_ROAM_STATE\r | |
36 | };\r | |
37 | \r | |
02b2b8ab S |
38 | class BssidBlacklistCommand : public WifiCommand\r |
39 | {\r | |
40 | private:\r | |
41 | wifi_bssid_params *mParams;\r | |
42 | public:\r | |
43 | BssidBlacklistCommand(wifi_interface_handle handle, int id,\r | |
44 | wifi_bssid_params *params)\r | |
45 | : WifiCommand(handle, id), mParams(params)\r | |
46 | { }\r | |
47 | int createRequest(WifiRequest& request) {\r | |
48 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_BSSID_BLACKLIST);\r | |
49 | if (result < 0) {\r | |
50 | return result;\r | |
51 | }\r | |
52 | \r | |
53 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA);\r | |
54 | result = request.put_u32(GSCAN_ATTRIBUTE_NUM_BSSID, mParams->num_bssid);\r | |
55 | if (result < 0) {\r | |
56 | return result;\r | |
57 | }\r | |
58 | \r | |
59 | for (int i = 0; i < mParams->num_bssid; i++) {\r | |
60 | result = request.put_addr(GSCAN_ATTRIBUTE_BLACKLIST_BSSID, mParams->bssids[i]);\r | |
61 | if (result < 0) {\r | |
62 | return result;\r | |
63 | }\r | |
64 | }\r | |
65 | request.attr_end(data);\r | |
66 | return result;\r | |
67 | }\r | |
68 | \r | |
69 | int start() {\r | |
70 | WifiRequest request(familyId(), ifaceId());\r | |
71 | int result = createRequest(request);\r | |
72 | if (result < 0) {\r | |
73 | return result;\r | |
74 | }\r | |
75 | \r | |
76 | result = requestResponse(request);\r | |
77 | if (result < 0) {\r | |
78 | ALOGE("Failed to execute bssid blacklist request, result = %d", result);\r | |
79 | return result;\r | |
80 | }\r | |
81 | \r | |
82 | return result;\r | |
83 | }\r | |
84 | \r | |
85 | \r | |
86 | virtual int handleResponse(WifiEvent& reply) {\r | |
87 | /* Nothing to do on response! */\r | |
88 | return NL_SKIP;\r | |
89 | }\r | |
90 | };\r | |
91 | \r | |
92 | wifi_error wifi_set_bssid_blacklist(wifi_request_id id, wifi_interface_handle iface,\r | |
93 | wifi_bssid_params params)\r | |
94 | {\r | |
95 | BssidBlacklistCommand *cmd = new BssidBlacklistCommand(iface, id, ¶ms);\r | |
96 | wifi_error result = (wifi_error)cmd->start();\r | |
97 | //release the reference of command as well\r | |
98 | cmd->releaseRef();\r | |
99 | return result;\r | |
100 | }\r | |
101 | \r | |
02b2b8ab | 102 | \r |
47e18f37 JPS |
103 | class RoamingCapabilitiesCommand : public WifiCommand\r |
104 | {\r | |
105 | private:\r | |
106 | wifi_roaming_capabilities *mCaps;\r | |
107 | \r | |
108 | public:\r | |
109 | RoamingCapabilitiesCommand(wifi_interface_handle handle, wifi_roaming_capabilities *caps)\r | |
110 | : WifiCommand(handle, 0) {\r | |
111 | mCaps = caps;\r | |
112 | }\r | |
113 | \r | |
114 | virtual int create() {\r | |
115 | int ret;\r | |
116 | \r | |
117 | ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_GET_ROAMING_CAPABILITIES);\r | |
118 | if (ret < 0) {\r | |
119 | ALOGE("Can't create message to send to driver - %d", ret);\r | |
120 | return ret;\r | |
121 | }\r | |
122 | return WIFI_SUCCESS;\r | |
123 | \r | |
124 | }\r | |
125 | \r | |
126 | virtual int handleResponse(WifiEvent& reply) {\r | |
127 | \r | |
128 | if (reply.get_cmd() != NL80211_CMD_VENDOR) {\r | |
129 | ALOGD("Ignore reply; cmd = %d", reply.get_cmd());\r | |
130 | return NL_SKIP;\r | |
131 | }\r | |
132 | \r | |
133 | nlattr *vendor_data = reply.get_attribute(NL80211_ATTR_VENDOR_DATA);\r | |
134 | int len = reply.get_vendor_data_len();\r | |
135 | \r | |
136 | if (vendor_data == NULL || len == 0) {\r | |
137 | ALOGE("vendor data in GetFeatureSetCommand missing!!");\r | |
138 | return NL_SKIP;\r | |
139 | }\r | |
140 | \r | |
141 | for (nl_iterator it(vendor_data); it.has_next(); it.next()) {\r | |
142 | switch(it.get_type()) {\r | |
143 | case SLSI_ATTR_ROAM_CAPABILITY_BLACKLIST_SIZE:\r | |
144 | mCaps->max_blacklist_size = it.get_u32();\r | |
145 | break;\r | |
146 | case SLSI_ATTR_ROAM_CAPABILITY_WHITELIST_SIZE:\r | |
147 | mCaps->max_whitelist_size = it.get_u32();\r | |
148 | break;\r | |
149 | default :\r | |
150 | break;\r | |
151 | }\r | |
152 | }\r | |
153 | return NL_OK;\r | |
154 | }\r | |
155 | };\r | |
156 | \r | |
157 | wifi_error wifi_get_roaming_capabilities(wifi_interface_handle handle,\r | |
158 | wifi_roaming_capabilities *caps)\r | |
159 | {\r | |
160 | RoamingCapabilitiesCommand cmd(handle, caps);\r | |
161 | return (wifi_error) cmd.requestResponse();\r | |
162 | }\r | |
163 | \r | |
164 | class RoamingStateCommand : public WifiCommand\r | |
165 | {\r | |
166 | private:\r | |
167 | fw_roaming_state_t mRoamingState;\r | |
168 | \r | |
169 | public:\r | |
170 | RoamingStateCommand(wifi_interface_handle handle, fw_roaming_state_t roaming_state)\r | |
171 | : WifiCommand(handle, 0) {\r | |
172 | mRoamingState = roaming_state;\r | |
173 | }\r | |
174 | \r | |
175 | virtual int create() {\r | |
176 | int ret;\r | |
177 | ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_SET_ROAMING_STATE);\r | |
178 | if (ret < 0) {\r | |
179 | ALOGE("Can't create message to send to driver - %d", ret);\r | |
180 | return ret;\r | |
181 | }\r | |
182 | \r | |
183 | nlattr *data = mMsg.attr_start(NL80211_ATTR_VENDOR_DATA);\r | |
184 | ret = mMsg.put_u8(SLSI_ATTR_ROAM_STATE, mRoamingState);\r | |
185 | if (ret < 0) {\r | |
186 | return ret;\r | |
187 | }\r | |
188 | mMsg.attr_end(data);\r | |
189 | return WIFI_SUCCESS;\r | |
190 | }\r | |
191 | };\r | |
192 | \r | |
193 | wifi_error wifi_enable_firmware_roaming(wifi_interface_handle handle, fw_roaming_state_t state) {\r | |
194 | RoamingStateCommand cmd(handle, state);\r | |
195 | wifi_error ret = (wifi_error) cmd.requestResponse();\r | |
196 | return ret;\r | |
197 | }\r | |
02b2b8ab S |
198 | \r |
199 | wifi_error wifi_configure_roaming(wifi_interface_handle iface, wifi_roaming_config *roaming_config)\r | |
200 | {\r | |
201 | wifi_error ret;\r | |
202 | int requestId;\r | |
203 | wifi_bssid_params bssid_params;\r | |
02b2b8ab S |
204 | \r |
205 | if (!roaming_config) {\r | |
206 | ALOGE("%s: Invalid Buffer provided. Exit", __FUNCTION__);\r | |
207 | return WIFI_ERROR_INVALID_ARGS;\r | |
208 | }\r | |
209 | \r | |
210 | /* Generate request id randomly*/\r | |
211 | requestId = get_requestid();\r | |
212 | bssid_params.num_bssid = roaming_config->num_blacklist_bssid;\r | |
213 | \r | |
214 | memcpy(bssid_params.bssids, roaming_config->blacklist_bssid,\r | |
215 | (bssid_params.num_bssid * sizeof(mac_addr)));\r | |
216 | \r | |
217 | ret = wifi_set_bssid_blacklist(requestId, iface, bssid_params);\r | |
218 | if (ret != WIFI_SUCCESS) {\r | |
219 | ALOGE("%s: Failed to configure blacklist bssids", __FUNCTION__);\r | |
220 | return WIFI_ERROR_UNKNOWN;\r | |
221 | }\r | |
222 | \r | |
223 | return ret;\r | |
224 | }\r |