5 #include <sys/socket.h>
6 #include <netlink/genl/genl.h>
7 #include <netlink/genl/family.h>
8 #include <netlink/genl/ctrl.h>
9 #include <linux/rtnetlink.h>
10 #include <netpacket/packet.h>
11 #include <linux/filter.h>
12 #include <linux/errqueue.h>
14 #include <linux/pkt_sched.h>
15 #include <netlink/object-api.h>
16 #include <netlink/netlink.h>
17 #include <netlink/socket.h>
18 #include <netlink/attr.h>
19 #include <netlink/handlers.h>
20 #include <netlink/msg.h>
27 #define LOG_TAG "WifiHAL"
29 #include <utils/Log.h>
32 #include "cpp_bindings.h"
36 #define WIFI_HAL_CMD_SOCK_PORT 644
37 #define WIFI_HAL_EVENT_SOCK_PORT 645
40 #define FEATURE_SET_MATRIX 1
41 #define ATTR_NODFS_VALUE 3
42 #define ATTR_COUNTRY_CODE 4
44 static void internal_event_handler(wifi_handle handle
, int events
);
45 static int internal_no_seq_check(nl_msg
*msg
, void *arg
);
46 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
);
47 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
);
48 static int wifi_add_membership(wifi_handle handle
, const char *group
);
49 static wifi_error
wifi_init_interfaces(wifi_handle handle
);
51 typedef enum wifi_attr
{
52 ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_CONFIG
,
53 ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
56 enum wifi_rssi_monitor_attr
{
57 RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
,
58 RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
,
59 RSSI_MONITOR_ATTRIBUTE_START
,
62 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
63 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
);
64 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
);
66 /* Initialize/Cleanup */
68 void wifi_socket_set_local_port(struct nl_sock
*sock
, uint32_t port
)
70 uint32_t pid
= getpid() & 0x3FFFFF;
71 nl_socket_set_local_port(sock
, pid
+ (port
<< 22));
74 static nl_sock
* wifi_create_nl_socket(int port
)
76 struct nl_sock
*sock
= nl_socket_alloc();
78 ALOGE("Could not create handle");
82 wifi_socket_set_local_port(sock
, port
);
84 if (nl_connect(sock
, NETLINK_GENERIC
)) {
85 ALOGE("Could not connect handle");
93 /* Initialize HAL function pointer table */
94 wifi_error
init_wifi_vendor_hal_func_table(wifi_hal_fn
*fn
)
97 return WIFI_ERROR_UNKNOWN
;
99 fn
->wifi_initialize
= wifi_initialize
;
100 fn
->wifi_cleanup
= wifi_cleanup
;
101 fn
->wifi_event_loop
= wifi_event_loop
;
102 fn
->wifi_get_supported_feature_set
= wifi_get_supported_feature_set
;
103 fn
->wifi_get_concurrency_matrix
= wifi_get_concurrency_matrix
;
104 fn
->wifi_set_scanning_mac_oui
= wifi_set_scanning_mac_oui
;
105 fn
->wifi_get_ifaces
= wifi_get_ifaces
;
106 fn
->wifi_get_iface_name
= wifi_get_iface_name
;
107 fn
->wifi_start_gscan
= wifi_start_gscan
;
108 fn
->wifi_stop_gscan
= wifi_stop_gscan
;
109 fn
->wifi_get_cached_gscan_results
= wifi_get_cached_gscan_results
;
110 fn
->wifi_set_bssid_hotlist
= wifi_set_bssid_hotlist
;
111 fn
->wifi_reset_bssid_hotlist
= wifi_reset_bssid_hotlist
;
112 fn
->wifi_set_significant_change_handler
= wifi_set_significant_change_handler
;
113 fn
->wifi_reset_significant_change_handler
= wifi_reset_significant_change_handler
;
114 fn
->wifi_get_gscan_capabilities
= wifi_get_gscan_capabilities
;
115 fn
->wifi_get_valid_channels
= wifi_get_valid_channels
;
116 fn
->wifi_rtt_range_request
= wifi_rtt_range_request
;
117 fn
->wifi_rtt_range_cancel
= wifi_rtt_range_cancel
;
118 fn
->wifi_get_rtt_capabilities
= wifi_get_rtt_capabilities
;
119 fn
->wifi_set_nodfs_flag
= wifi_set_nodfs_flag
;
120 fn
->wifi_start_sending_offloaded_packet
= wifi_start_sending_offloaded_packet
;
121 fn
->wifi_stop_sending_offloaded_packet
= wifi_stop_sending_offloaded_packet
;
122 fn
->wifi_set_epno_list
= wifi_set_epno_list
;
123 fn
->wifi_reset_epno_list
= wifi_reset_epno_list
;
124 fn
->wifi_set_passpoint_list
= wifi_set_passpoint_list
;
125 fn
->wifi_reset_passpoint_list
= wifi_reset_passpoint_list
;
126 fn
->wifi_start_rssi_monitoring
= wifi_start_rssi_monitoring
;
127 fn
->wifi_stop_rssi_monitoring
= wifi_stop_rssi_monitoring
;
128 fn
->wifi_set_link_stats
= wifi_set_link_stats
;
129 fn
->wifi_get_link_stats
= wifi_get_link_stats
;
130 fn
->wifi_clear_link_stats
= wifi_clear_link_stats
;
131 fn
->wifi_set_country_code
= wifi_set_country_code
;
132 fn
->wifi_configure_roaming
= wifi_configure_roaming
;
133 fn
->wifi_configure_nd_offload
= wifi_configure_nd_offload
;
134 fn
->wifi_get_packet_filter_capabilities
= wifi_get_packet_filter_capabilities
;
139 wifi_error
wifi_initialize(wifi_handle
*handle
)
143 ALOGI("Initializing wifi");
144 hal_info
*info
= (hal_info
*)malloc(sizeof(hal_info
));
146 ALOGE("Could not allocate hal_info");
147 return WIFI_ERROR_UNKNOWN
;
150 memset(info
, 0, sizeof(*info
));
152 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, info
->cleanup_socks
) == -1) {
153 ALOGE("Could not create cleanup sockets");
155 return WIFI_ERROR_UNKNOWN
;
158 struct nl_sock
*cmd_sock
= wifi_create_nl_socket(WIFI_HAL_CMD_SOCK_PORT
);
159 if (cmd_sock
== NULL
) {
160 ALOGE("Could not create handle");
162 return WIFI_ERROR_UNKNOWN
;
165 struct nl_sock
*event_sock
= wifi_create_nl_socket(WIFI_HAL_EVENT_SOCK_PORT
);
166 if (event_sock
== NULL
) {
167 ALOGE("Could not create handle");
168 nl_socket_free(cmd_sock
);
170 return WIFI_ERROR_UNKNOWN
;
173 struct nl_cb
*cb
= nl_socket_get_cb(event_sock
);
175 ALOGE("Could not create handle");
176 nl_socket_free(cmd_sock
);
177 nl_socket_free(event_sock
);
179 return WIFI_ERROR_UNKNOWN
;
182 // ALOGI("cb->refcnt = %d", cb->cb_refcnt);
183 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, internal_no_seq_check
, info
);
184 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, internal_valid_message_handler
, info
);
187 info
->cmd_sock
= cmd_sock
;
188 info
->event_sock
= event_sock
;
189 info
->clean_up
= false;
190 info
->in_event_loop
= false;
192 info
->event_cb
= (cb_info
*)malloc(sizeof(cb_info
) * DEFAULT_EVENT_CB_SIZE
);
193 info
->alloc_event_cb
= DEFAULT_EVENT_CB_SIZE
;
194 info
->num_event_cb
= 0;
196 info
->cmd
= (cmd_info
*)malloc(sizeof(cmd_info
) * DEFAULT_CMD_SIZE
);
197 info
->alloc_cmd
= DEFAULT_CMD_SIZE
;
200 info
->nl80211_family_id
= genl_ctrl_resolve(cmd_sock
, "nl80211");
201 if (info
->nl80211_family_id
< 0) {
202 ALOGE("Could not resolve nl80211 familty id");
203 nl_socket_free(cmd_sock
);
204 nl_socket_free(event_sock
);
206 return WIFI_ERROR_UNKNOWN
;
209 pthread_mutex_init(&info
->cb_lock
, NULL
);
211 *handle
= (wifi_handle
) info
;
213 wifi_add_membership(*handle
, "scan");
214 wifi_add_membership(*handle
, "mlme");
215 wifi_add_membership(*handle
, "regulatory");
216 wifi_add_membership(*handle
, "vendor");
218 wifi_init_interfaces(*handle
);
219 char intf_name_buff
[10 * 10 + 4]; /* Randomly choosen max interface 10. each interface name max 9 + 1(for space) */
220 char *pos
= intf_name_buff
;
221 for (int i
= 0; i
< (info
->num_interfaces
< 10 ? info
->num_interfaces
: 10); i
++) {
222 strncpy(pos
, info
->interfaces
[i
]->name
, sizeof(intf_name_buff
) - (pos
- intf_name_buff
));
225 if (info
->num_interfaces
> 10) {
226 strncpy(pos
, "...", 3);
229 ALOGD("Found %d interfaces[%s]. Initialized Wifi HAL Successfully", info
->num_interfaces
, intf_name_buff
);
234 static int wifi_add_membership(wifi_handle handle
, const char *group
)
236 hal_info
*info
= getHalInfo(handle
);
238 int id
= wifi_get_multicast_id(handle
, "nl80211", group
);
240 ALOGE("Could not find group %s", group
);
244 int ret
= nl_socket_add_membership(info
->event_sock
, id
);
246 ALOGE("Could not add membership to group %s", group
);
251 static void internal_cleaned_up_handler(wifi_handle handle
)
253 hal_info
*info
= getHalInfo(handle
);
254 wifi_cleaned_up_handler cleaned_up_handler
= info
->cleaned_up_handler
;
256 if (info
->cmd_sock
!= 0) {
257 close(info
->cleanup_socks
[0]);
258 close(info
->cleanup_socks
[1]);
259 nl_socket_free(info
->cmd_sock
);
260 nl_socket_free(info
->event_sock
);
261 info
->cmd_sock
= NULL
;
262 info
->event_sock
= NULL
;
265 (*cleaned_up_handler
)(handle
);
266 pthread_mutex_destroy(&info
->cb_lock
);
270 void wifi_cleanup(wifi_handle handle
, wifi_cleaned_up_handler handler
)
272 hal_info
*info
= getHalInfo(handle
);
275 info
->cleaned_up_handler
= handler
;
276 if (write(info
->cleanup_socks
[0], "Exit", 4) < 1) {
277 ALOGE("could not write to the cleanup socket");
279 // Listen to the response
280 // Hopefully we dont get errors or get hung up
281 // Not much can be done in that case, but assume that
282 // it has rx'ed the Exit message to exit the thread.
283 // As a fallback set the cleanup flag to TRUE
284 memset(buf
, 0, sizeof(buf
));
285 int result
= read(info
->cleanup_socks
[0], buf
, sizeof(buf
));
286 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result
, errno
);
287 if (strncmp(buf
, "Done", 4) != 0) {
288 ALOGD("Rx'ed %s", buf
);
291 info
->clean_up
= true;
292 pthread_mutex_lock(&info
->cb_lock
);
294 int bad_commands
= 0;
296 while (info
->num_cmd
> bad_commands
) {
297 int num_cmd
= info
->num_cmd
;
298 cmd_info
*cmdi
= &(info
->cmd
[bad_commands
]);
299 WifiCommand
*cmd
= cmdi
->cmd
;
301 pthread_mutex_unlock(&info
->cb_lock
);
303 pthread_mutex_lock(&info
->cb_lock
);
304 /* release reference added when command is saved */
306 if (num_cmd
== info
->num_cmd
) {
312 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
313 cb_info
*cbi
= &(info
->event_cb
[i
]);
314 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
315 ALOGE("Leaked command %p", cmd
);
317 pthread_mutex_unlock(&info
->cb_lock
);
318 internal_cleaned_up_handler(handle
);
321 static int internal_pollin_handler(wifi_handle handle
)
323 hal_info
*info
= getHalInfo(handle
);
324 struct nl_cb
*cb
= nl_socket_get_cb(info
->event_sock
);
325 int res
= nl_recvmsgs(info
->event_sock
, cb
);
330 /* Run event handler */
331 void wifi_event_loop(wifi_handle handle
)
333 hal_info
*info
= getHalInfo(handle
);
334 if (info
->in_event_loop
) {
337 info
->in_event_loop
= true;
341 memset(&pfd
[0], 0, sizeof(pollfd
) * 2);
343 pfd
[0].fd
= nl_socket_get_fd(info
->event_sock
);
344 pfd
[0].events
= POLLIN
;
345 pfd
[1].fd
= info
->cleanup_socks
[1];
346 pfd
[1].events
= POLLIN
;
351 int timeout
= -1; /* Infinite timeout */
354 int result
= poll(pfd
, 2, timeout
);
356 } else if (pfd
[0].revents
& POLLERR
) {
357 int prev_err
= (int)errno
;
358 int result2
= read(pfd
[0].fd
, buf
, sizeof(buf
));
359 ALOGE("Poll err:%d | Read after POLL returned %d, error no = %d", prev_err
, result2
, errno
);
360 } else if (pfd
[0].revents
& POLLHUP
) {
361 ALOGE("Remote side hung up");
363 } else if (pfd
[0].revents
& POLLIN
) {
364 internal_pollin_handler(handle
);
365 } else if (pfd
[1].revents
& POLLIN
) {
366 memset(buf
, 0, sizeof(buf
));
367 int result2
= read(pfd
[1].fd
, buf
, sizeof(buf
));
368 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result2
, errno
);
369 if (strncmp(buf
, "Exit", 4) == 0) {
370 ALOGD("Got a signal to exit!!!");
371 if (write(pfd
[1].fd
, "Done", 4) < 1) {
372 ALOGE("could not write to the cleanup socket");
376 ALOGD("Rx'ed %s on the cleanup socket\n", buf
);
379 ALOGE("Unknown event - %0x, %0x", pfd
[0].revents
, pfd
[1].revents
);
381 } while (!info
->clean_up
);
384 ///////////////////////////////////////////////////////////////////////////////////////
386 static int internal_no_seq_check(struct nl_msg
*msg
, void *arg
)
391 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
)
393 wifi_handle handle
= (wifi_handle
)arg
;
394 hal_info
*info
= getHalInfo(handle
);
396 WifiEvent
event(msg
);
397 int res
= event
.parse();
399 ALOGE("Failed to parse event: %d", res
);
403 int cmd
= event
.get_cmd();
404 uint32_t vendor_id
= 0;
407 if (cmd
== NL80211_CMD_VENDOR
) {
408 vendor_id
= event
.get_u32(NL80211_ATTR_VENDOR_ID
);
409 subcmd
= event
.get_u32(NL80211_ATTR_VENDOR_SUBCMD
);
411 ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
412 event.get_cmdString(), vendor_id, subcmd);*/
415 //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
418 pthread_mutex_lock(&info
->cb_lock
);
420 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
421 if (cmd
== info
->event_cb
[i
].nl_cmd
) {
422 if (cmd
== NL80211_CMD_VENDOR
423 && ((vendor_id
!= info
->event_cb
[i
].vendor_id
)
424 || (subcmd
!= info
->event_cb
[i
].vendor_subcmd
)))
426 /* event for a different vendor, ignore it */
430 cb_info
*cbi
= &(info
->event_cb
[i
]);
431 nl_recvmsg_msg_cb_t cb_func
= cbi
->cb_func
;
432 void *cb_arg
= cbi
->cb_arg
;
433 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
438 pthread_mutex_unlock(&info
->cb_lock
);
440 (*cb_func
)(msg
, cb_arg
);
449 pthread_mutex_unlock(&info
->cb_lock
);
453 ///////////////////////////////////////////////////////////////////////////////////////
455 class GetMulticastIdCommand
: public WifiCommand
462 GetMulticastIdCommand(wifi_handle handle
, const char *name
, const char *group
)
463 : WifiCommand(handle
, 0)
474 virtual int create() {
475 int nlctrlFamily
= genl_ctrl_resolve(mInfo
->cmd_sock
, "nlctrl");
476 int ret
= mMsg
.create(nlctrlFamily
, CTRL_CMD_GETFAMILY
, 0, 0);
480 ret
= mMsg
.put_string(CTRL_ATTR_FAMILY_NAME
, mName
);
484 virtual int handleResponse(WifiEvent
& reply
) {
485 struct nlattr
**tb
= reply
.attributes();
486 struct nlattr
*mcgrp
= NULL
;
489 if (!tb
[CTRL_ATTR_MCAST_GROUPS
]) {
490 ALOGE("No multicast groups found");
494 for_each_attr(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
496 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
497 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, (nlattr
*)nla_data(mcgrp
),
498 nla_len(mcgrp
), NULL
);
499 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] || !tb2
[CTRL_ATTR_MCAST_GRP_ID
]) {
503 char *grpName
= (char *)nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
504 int grpNameLen
= nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
506 if (strncmp(grpName
, mGroup
, grpNameLen
) != 0)
509 mId
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
518 class SetPnoMacAddrOuiCommand
: public WifiCommand
{
523 feature_set
*feature_matrix
;
527 SetPnoMacAddrOuiCommand(wifi_interface_handle handle
, oui scan_oui
)
528 : WifiCommand(handle
, 0)
532 feature_matrix
= NULL
;
537 int createRequest(WifiRequest
& request
, int subcmd
, byte
*scan_oui
) {
538 int result
= request
.create(GOOGLE_OUI
, subcmd
);
543 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
544 result
= request
.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
, scan_oui
, DOT11_OUI_LEN
);
549 request
.attr_end(data
);
555 WifiRequest
request(familyId(), ifaceId());
556 int result
= createRequest(request
, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI
, mOui
);
557 if (result
!= WIFI_SUCCESS
) {
558 ALOGE("failed to create request; result = %d", result
);
562 result
= requestResponse(request
);
563 if (result
!= WIFI_SUCCESS
) {
564 ALOGE("failed to set scanning mac OUI; result = %d", result
);
570 virtual int handleResponse(WifiEvent
& reply
) {
571 /* Nothing to do on response! */
576 class SetNodfsCommand
: public WifiCommand
{
581 SetNodfsCommand(wifi_interface_handle handle
, u32 nodfs
)
582 : WifiCommand(handle
, 0) {
585 virtual int create() {
588 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS
);
590 ALOGE("Can't create message to send to driver - %d", ret
);
594 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
595 ret
= mMsg
.put_u32(ATTR_NODFS_VALUE
, mNoDfs
);
605 class SetRSSIMonitorCommand
: public WifiCommand
{
609 wifi_rssi_event_handler mHandler
;
611 SetRSSIMonitorCommand(wifi_request_id id
, wifi_interface_handle handle
,
612 s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
613 : WifiCommand(handle
, id
), mMax_rssi(max_rssi
), mMin_rssi
614 (min_rssi
), mHandler(eh
)
617 int createRequest(WifiRequest
& request
, int enable
) {
618 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR
);
623 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
624 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
, (enable
? mMax_rssi
: 0));
629 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
, (enable
? mMin_rssi
: 0));
633 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_START
, enable
);
637 request
.attr_end(data
);
642 WifiRequest
request(familyId(), ifaceId());
643 int result
= createRequest(request
, 1);
647 result
= requestResponse(request
);
649 ALOGI("Failed to set RSSI Monitor, result = %d", result
);
652 ALOGI("Successfully set RSSI monitoring");
653 registerVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
658 virtual int cancel() {
660 WifiRequest
request(familyId(), ifaceId());
661 int result
= createRequest(request
, 0);
662 if (result
!= WIFI_SUCCESS
) {
663 ALOGE("failed to create request; result = %d", result
);
665 result
= requestResponse(request
);
666 if (result
!= WIFI_SUCCESS
) {
667 ALOGE("failed to stop RSSI monitoring = %d", result
);
670 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
674 virtual int handleResponse(WifiEvent
& reply
) {
675 /* Nothing to do on response! */
679 virtual int handleEvent(WifiEvent
& event
) {
681 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
682 int len
= event
.get_vendor_data_len();
684 if (vendor_data
== NULL
|| len
== 0) {
685 ALOGI("RSSI monitor: No data");
694 rssi_monitor_evt
*data
= (rssi_monitor_evt
*)event
.get_vendor_data();
696 if (*mHandler
.on_rssi_threshold_breached
) {
697 (*mHandler
.on_rssi_threshold_breached
)(id(), data
->BSSID
, data
->cur_rssi
);
699 ALOGW("No RSSI monitor handler registered");
707 class SetCountryCodeCommand
: public WifiCommand
{
709 const char *mCountryCode
;
711 SetCountryCodeCommand(wifi_interface_handle handle
, const char *country_code
)
712 : WifiCommand(handle
, 0) {
713 mCountryCode
= country_code
;
715 virtual int create() {
718 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_COUNTRY_CODE
);
720 ALOGE("Can't create message to send to driver - %d", ret
);
724 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
725 ret
= mMsg
.put_string(ATTR_COUNTRY_CODE
, mCountryCode
);
736 class GetFeatureSetCommand
: public WifiCommand
{
743 GetFeatureSetCommand(wifi_interface_handle handle
, feature_set
*set
)
744 : WifiCommand(handle
, 0)
749 virtual int create() {
752 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_GET_FEATURE_SET
);
754 ALOGE("create failed - %d", ret
);
761 virtual int handleResponse(WifiEvent
& reply
) {
763 int id
= reply
.get_vendor_id();
764 int subcmd
= reply
.get_vendor_subcmd();
766 if (reply
.get_cmd() != NL80211_CMD_VENDOR
) {
767 ALOGD("Ignore reply; cmd = %d", reply
.get_cmd());
771 nlattr
*vendor_data
= reply
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
772 int len
= reply
.get_vendor_data_len();
774 if (vendor_data
== NULL
|| len
== 0) {
775 ALOGE("vendor data in GetFeatureSetCommand missing!!");
779 void *data
= reply
.get_vendor_data();
781 ALOGE("feature_set Pointer not set");
784 memcpy(fset
, data
, min(len
, (int) sizeof(*fset
)));
790 class SetNdoffloadCommand
: public WifiCommand
{
795 SetNdoffloadCommand(wifi_interface_handle handle
, u8 enable
)
796 : WifiCommand(handle
, 0) {
799 virtual int create() {
802 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_CONFIGURE_ND_OFFLOAD
);
804 ALOGE("Can't create message to send to driver - %d", ret
);
805 return WIFI_ERROR_NOT_AVAILABLE
;
808 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
809 ret
= mMsg
.put_u8(ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_CONFIG
, mEnable
);
813 ALOGD("Driver message has been created successfully--> %d", mEnable
);
819 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
)
821 GetMulticastIdCommand
cmd(handle
, name
, group
);
822 int res
= cmd
.requestResponse();
829 /////////////////////////////////////////////////////////////////////////
831 static bool is_wifi_interface(const char *name
)
833 if (strncmp(name
, "wlan", 4) != 0 && strncmp(name
, "p2p", 3) != 0) {
834 /* not a wifi interface; ignore it */
841 static int get_interface(const char *name
, interface_info
*info
)
843 strcpy(info
->name
, name
);
844 info
->id
= if_nametoindex(name
);
848 wifi_error
wifi_init_interfaces(wifi_handle handle
)
850 hal_info
*info
= (hal_info
*)handle
;
853 DIR *d
= opendir("/sys/class/net");
855 return WIFI_ERROR_UNKNOWN
;
858 while ((de
= readdir(d
))) {
859 if (de
->d_name
[0] == '.')
861 if (is_wifi_interface(de
->d_name
) ) {
868 d
= opendir("/sys/class/net");
870 return WIFI_ERROR_UNKNOWN
;
872 info
->interfaces
= (interface_info
**)malloc(sizeof(interface_info
*) * n
);
875 while ((de
= readdir(d
))) {
876 if (de
->d_name
[0] == '.')
878 if (is_wifi_interface(de
->d_name
)) {
879 interface_info
*ifinfo
= (interface_info
*)malloc(sizeof(interface_info
));
880 if (get_interface(de
->d_name
, ifinfo
) != WIFI_SUCCESS
) {
884 ifinfo
->handle
= handle
;
885 info
->interfaces
[i
] = ifinfo
;
892 info
->num_interfaces
= n
;
896 wifi_error
wifi_get_ifaces(wifi_handle handle
, int *num
, wifi_interface_handle
**interfaces
)
898 hal_info
*info
= (hal_info
*)handle
;
900 *interfaces
= (wifi_interface_handle
*)info
->interfaces
;
901 *num
= info
->num_interfaces
;
906 wifi_error
wifi_get_iface_name(wifi_interface_handle handle
, char *name
, size_t size
)
908 interface_info
*info
= (interface_info
*)handle
;
909 strcpy(name
, info
->name
);
913 wifi_error
wifi_get_concurrency_matrix(wifi_interface_handle handle
, int set_size_max
,
914 feature_set set
[], int *set_size
)
916 return WIFI_ERROR_NOT_SUPPORTED
;
919 wifi_error
wifi_set_scanning_mac_oui(wifi_interface_handle handle
, oui scan_oui
)
921 SetPnoMacAddrOuiCommand
command(handle
, scan_oui
);
922 return (wifi_error
)command
.start();
926 wifi_error
wifi_set_nodfs_flag(wifi_interface_handle handle
, u32 nodfs
)
928 SetNodfsCommand
command(handle
, nodfs
);
929 return (wifi_error
) command
.requestResponse();
932 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
933 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
935 ALOGD("Start RSSI monitor %d", id
);
936 wifi_handle handle
= getWifiHandle(iface
);
937 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
, max_rssi
, min_rssi
, eh
);
938 wifi_register_cmd(handle
, id
, cmd
);
940 wifi_error result
= (wifi_error
)cmd
->start();
941 if (result
!= WIFI_SUCCESS
) {
942 wifi_unregister_cmd(handle
, id
);
948 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
)
950 ALOGD("Stopping RSSI monitor");
953 wifi_rssi_event_handler handler
;
954 wifi_handle handle
= getWifiHandle(iface
);
955 memset(&handler
, 0, sizeof(handler
));
956 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
,
962 return wifi_cancel_cmd(id
, iface
);
965 wifi_error
wifi_get_supported_feature_set(wifi_interface_handle handle
, feature_set
*set
)
967 GetFeatureSetCommand
command(handle
, set
);
968 return (wifi_error
) command
.requestResponse();
971 wifi_error
wifi_set_country_code(wifi_interface_handle handle
, const char *country_code
)
973 SetCountryCodeCommand
command(handle
, country_code
);
974 return (wifi_error
) command
.requestResponse();
977 wifi_error
wifi_configure_nd_offload(wifi_interface_handle handle
, u8 enable
)
979 SetNdoffloadCommand
command(handle
, enable
);
980 int ret
= command
.requestResponse();
981 if (ret
!= WIFI_SUCCESS
) {
982 if (ret
== -EPERM
) { /*This is just to pass VTS test */
983 ALOGD("return value from driver--> %d",ret
);
987 return (wifi_error
)ret
;
990 wifi_error
wifi_get_packet_filter_capabilities(wifi_interface_handle handle
,
991 u32
*version
, u32
*max_len
)
993 /*Return success to pass VTS test.*/
994 ALOGD("Packet filter not supported");
1002 /////////////////////////////////////////////////////////////////////////////