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_NUM_FEATURE_SET
,
53 ANDR_WIFI_ATTRIBUTE_FEATURE_SET
,
54 ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
57 enum wifi_rssi_monitor_attr
{
58 RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
,
59 RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
,
60 RSSI_MONITOR_ATTRIBUTE_START
,
63 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
64 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
);
65 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
);
67 /* Initialize/Cleanup */
69 void wifi_socket_set_local_port(struct nl_sock
*sock
, uint32_t port
)
71 uint32_t pid
= getpid() & 0x3FFFFF;
72 nl_socket_set_local_port(sock
, pid
+ (port
<< 22));
75 static nl_sock
* wifi_create_nl_socket(int port
)
77 struct nl_sock
*sock
= nl_socket_alloc();
79 ALOGE("Could not create handle");
83 wifi_socket_set_local_port(sock
, port
);
85 if (nl_connect(sock
, NETLINK_GENERIC
)) {
86 ALOGE("Could not connect handle");
94 /* Initialize HAL function pointer table */
95 wifi_error
init_wifi_vendor_hal_func_table(wifi_hal_fn
*fn
)
98 return WIFI_ERROR_UNKNOWN
;
100 fn
->wifi_initialize
= wifi_initialize
;
101 fn
->wifi_cleanup
= wifi_cleanup
;
102 fn
->wifi_event_loop
= wifi_event_loop
;
103 fn
->wifi_get_supported_feature_set
= wifi_get_supported_feature_set
;
104 fn
->wifi_get_concurrency_matrix
= wifi_get_concurrency_matrix
;
105 fn
->wifi_set_scanning_mac_oui
= wifi_set_scanning_mac_oui
;
106 fn
->wifi_get_ifaces
= wifi_get_ifaces
;
107 fn
->wifi_get_iface_name
= wifi_get_iface_name
;
108 fn
->wifi_start_gscan
= wifi_start_gscan
;
109 fn
->wifi_stop_gscan
= wifi_stop_gscan
;
110 fn
->wifi_get_cached_gscan_results
= wifi_get_cached_gscan_results
;
111 fn
->wifi_set_bssid_hotlist
= wifi_set_bssid_hotlist
;
112 fn
->wifi_reset_bssid_hotlist
= wifi_reset_bssid_hotlist
;
113 fn
->wifi_set_significant_change_handler
= wifi_set_significant_change_handler
;
114 fn
->wifi_reset_significant_change_handler
= wifi_reset_significant_change_handler
;
115 fn
->wifi_get_gscan_capabilities
= wifi_get_gscan_capabilities
;
116 fn
->wifi_get_valid_channels
= wifi_get_valid_channels
;
117 fn
->wifi_rtt_range_request
= wifi_rtt_range_request
;
118 fn
->wifi_rtt_range_cancel
= wifi_rtt_range_cancel
;
119 fn
->wifi_get_rtt_capabilities
= wifi_get_rtt_capabilities
;
120 fn
->wifi_set_nodfs_flag
= wifi_set_nodfs_flag
;
121 fn
->wifi_start_sending_offloaded_packet
= wifi_start_sending_offloaded_packet
;
122 fn
->wifi_stop_sending_offloaded_packet
= wifi_stop_sending_offloaded_packet
;
123 fn
->wifi_set_epno_list
= wifi_set_epno_list
;
124 fn
->wifi_reset_epno_list
= wifi_reset_epno_list
;
125 fn
->wifi_set_passpoint_list
= wifi_set_passpoint_list
;
126 fn
->wifi_reset_passpoint_list
= wifi_reset_passpoint_list
;
127 fn
->wifi_start_rssi_monitoring
= wifi_start_rssi_monitoring
;
128 fn
->wifi_stop_rssi_monitoring
= wifi_stop_rssi_monitoring
;
129 fn
->wifi_set_link_stats
= wifi_set_link_stats
;
130 fn
->wifi_get_link_stats
= wifi_get_link_stats
;
131 fn
->wifi_clear_link_stats
= wifi_clear_link_stats
;
132 fn
->wifi_set_country_code
= wifi_set_country_code
;
133 fn
->wifi_configure_roaming
= wifi_configure_roaming
;
138 wifi_error
wifi_initialize(wifi_handle
*handle
)
142 ALOGI("Initializing wifi");
143 hal_info
*info
= (hal_info
*)malloc(sizeof(hal_info
));
145 ALOGE("Could not allocate hal_info");
146 return WIFI_ERROR_UNKNOWN
;
149 memset(info
, 0, sizeof(*info
));
151 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, info
->cleanup_socks
) == -1) {
152 ALOGE("Could not create cleanup sockets");
154 return WIFI_ERROR_UNKNOWN
;
157 struct nl_sock
*cmd_sock
= wifi_create_nl_socket(WIFI_HAL_CMD_SOCK_PORT
);
158 if (cmd_sock
== NULL
) {
159 ALOGE("Could not create handle");
161 return WIFI_ERROR_UNKNOWN
;
164 struct nl_sock
*event_sock
= wifi_create_nl_socket(WIFI_HAL_EVENT_SOCK_PORT
);
165 if (event_sock
== NULL
) {
166 ALOGE("Could not create handle");
167 nl_socket_free(cmd_sock
);
169 return WIFI_ERROR_UNKNOWN
;
172 struct nl_cb
*cb
= nl_socket_get_cb(event_sock
);
174 ALOGE("Could not create handle");
175 nl_socket_free(cmd_sock
);
176 nl_socket_free(event_sock
);
178 return WIFI_ERROR_UNKNOWN
;
181 // ALOGI("cb->refcnt = %d", cb->cb_refcnt);
182 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, internal_no_seq_check
, info
);
183 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, internal_valid_message_handler
, info
);
186 info
->cmd_sock
= cmd_sock
;
187 info
->event_sock
= event_sock
;
188 info
->clean_up
= false;
189 info
->in_event_loop
= false;
191 info
->event_cb
= (cb_info
*)malloc(sizeof(cb_info
) * DEFAULT_EVENT_CB_SIZE
);
192 info
->alloc_event_cb
= DEFAULT_EVENT_CB_SIZE
;
193 info
->num_event_cb
= 0;
195 info
->cmd
= (cmd_info
*)malloc(sizeof(cmd_info
) * DEFAULT_CMD_SIZE
);
196 info
->alloc_cmd
= DEFAULT_CMD_SIZE
;
199 info
->nl80211_family_id
= genl_ctrl_resolve(cmd_sock
, "nl80211");
200 if (info
->nl80211_family_id
< 0) {
201 ALOGE("Could not resolve nl80211 familty id");
202 nl_socket_free(cmd_sock
);
203 nl_socket_free(event_sock
);
205 return WIFI_ERROR_UNKNOWN
;
208 pthread_mutex_init(&info
->cb_lock
, NULL
);
210 *handle
= (wifi_handle
) info
;
212 wifi_add_membership(*handle
, "scan");
213 wifi_add_membership(*handle
, "mlme");
214 wifi_add_membership(*handle
, "regulatory");
215 wifi_add_membership(*handle
, "vendor");
217 wifi_init_interfaces(*handle
);
218 char intf_name_buff
[10 * 10 + 4]; /* Randomly choosen max interface 10. each interface name max 9 + 1(for space) */
219 char *pos
= intf_name_buff
;
220 for (int i
= 0; i
< (info
->num_interfaces
< 10 ? info
->num_interfaces
: 10); i
++) {
221 strncpy(pos
, info
->interfaces
[i
]->name
, sizeof(intf_name_buff
) - (pos
- intf_name_buff
));
224 if (info
->num_interfaces
> 10) {
225 strncpy(pos
, "...", 3);
228 ALOGD("Found %d interfaces[%s]. Initialized Wifi HAL Successfully", info
->num_interfaces
, intf_name_buff
);
233 static int wifi_add_membership(wifi_handle handle
, const char *group
)
235 hal_info
*info
= getHalInfo(handle
);
237 int id
= wifi_get_multicast_id(handle
, "nl80211", group
);
239 ALOGE("Could not find group %s", group
);
243 int ret
= nl_socket_add_membership(info
->event_sock
, id
);
245 ALOGE("Could not add membership to group %s", group
);
250 static void internal_cleaned_up_handler(wifi_handle handle
)
252 hal_info
*info
= getHalInfo(handle
);
253 wifi_cleaned_up_handler cleaned_up_handler
= info
->cleaned_up_handler
;
255 if (info
->cmd_sock
!= 0) {
256 close(info
->cleanup_socks
[0]);
257 close(info
->cleanup_socks
[1]);
258 nl_socket_free(info
->cmd_sock
);
259 nl_socket_free(info
->event_sock
);
260 info
->cmd_sock
= NULL
;
261 info
->event_sock
= NULL
;
264 (*cleaned_up_handler
)(handle
);
265 pthread_mutex_destroy(&info
->cb_lock
);
269 void wifi_cleanup(wifi_handle handle
, wifi_cleaned_up_handler handler
)
271 hal_info
*info
= getHalInfo(handle
);
274 info
->cleaned_up_handler
= handler
;
275 if (write(info
->cleanup_socks
[0], "Exit", 4) < 1) {
276 ALOGE("could not write to the cleanup socket");
278 // Listen to the response
279 // Hopefully we dont get errors or get hung up
280 // Not much can be done in that case, but assume that
281 // it has rx'ed the Exit message to exit the thread.
282 // As a fallback set the cleanup flag to TRUE
283 memset(buf
, 0, sizeof(buf
));
284 int result
= read(info
->cleanup_socks
[0], buf
, sizeof(buf
));
285 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result
, errno
);
286 if (strncmp(buf
, "Done", 4) != 0) {
287 ALOGD("Rx'ed %s", buf
);
290 info
->clean_up
= true;
291 pthread_mutex_lock(&info
->cb_lock
);
293 int bad_commands
= 0;
295 while (info
->num_cmd
> bad_commands
) {
296 int num_cmd
= info
->num_cmd
;
297 cmd_info
*cmdi
= &(info
->cmd
[bad_commands
]);
298 WifiCommand
*cmd
= cmdi
->cmd
;
300 pthread_mutex_unlock(&info
->cb_lock
);
302 pthread_mutex_lock(&info
->cb_lock
);
303 /* release reference added when command is saved */
305 if (num_cmd
== info
->num_cmd
) {
311 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
312 cb_info
*cbi
= &(info
->event_cb
[i
]);
313 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
314 ALOGE("Leaked command %p", cmd
);
316 pthread_mutex_unlock(&info
->cb_lock
);
317 internal_cleaned_up_handler(handle
);
320 static int internal_pollin_handler(wifi_handle handle
)
322 hal_info
*info
= getHalInfo(handle
);
323 struct nl_cb
*cb
= nl_socket_get_cb(info
->event_sock
);
324 int res
= nl_recvmsgs(info
->event_sock
, cb
);
329 /* Run event handler */
330 void wifi_event_loop(wifi_handle handle
)
332 hal_info
*info
= getHalInfo(handle
);
333 if (info
->in_event_loop
) {
336 info
->in_event_loop
= true;
340 memset(&pfd
[0], 0, sizeof(pollfd
) * 2);
342 pfd
[0].fd
= nl_socket_get_fd(info
->event_sock
);
343 pfd
[0].events
= POLLIN
;
344 pfd
[1].fd
= info
->cleanup_socks
[1];
345 pfd
[1].events
= POLLIN
;
350 int timeout
= -1; /* Infinite timeout */
353 int result
= poll(pfd
, 2, timeout
);
355 } else if (pfd
[0].revents
& POLLERR
) {
356 int prev_err
= (int)errno
;
357 int result2
= read(pfd
[0].fd
, buf
, sizeof(buf
));
358 ALOGE("Poll err:%d | Read after POLL returned %d, error no = %d", prev_err
, result2
, errno
);
359 } else if (pfd
[0].revents
& POLLHUP
) {
360 ALOGE("Remote side hung up");
362 } else if (pfd
[0].revents
& POLLIN
) {
363 internal_pollin_handler(handle
);
364 } else if (pfd
[1].revents
& POLLIN
) {
365 memset(buf
, 0, sizeof(buf
));
366 int result2
= read(pfd
[1].fd
, buf
, sizeof(buf
));
367 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result2
, errno
);
368 if (strncmp(buf
, "Exit", 4) == 0) {
369 ALOGD("Got a signal to exit!!!");
370 if (write(pfd
[1].fd
, "Done", 4) < 1) {
371 ALOGE("could not write to the cleanup socket");
375 ALOGD("Rx'ed %s on the cleanup socket\n", buf
);
378 ALOGE("Unknown event - %0x, %0x", pfd
[0].revents
, pfd
[1].revents
);
380 } while (!info
->clean_up
);
383 ///////////////////////////////////////////////////////////////////////////////////////
385 static int internal_no_seq_check(struct nl_msg
*msg
, void *arg
)
390 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
)
392 wifi_handle handle
= (wifi_handle
)arg
;
393 hal_info
*info
= getHalInfo(handle
);
395 WifiEvent
event(msg
);
396 int res
= event
.parse();
398 ALOGE("Failed to parse event: %d", res
);
402 int cmd
= event
.get_cmd();
403 uint32_t vendor_id
= 0;
406 if (cmd
== NL80211_CMD_VENDOR
) {
407 vendor_id
= event
.get_u32(NL80211_ATTR_VENDOR_ID
);
408 subcmd
= event
.get_u32(NL80211_ATTR_VENDOR_SUBCMD
);
410 ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
411 event.get_cmdString(), vendor_id, subcmd);*/
414 //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
417 pthread_mutex_lock(&info
->cb_lock
);
419 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
420 if (cmd
== info
->event_cb
[i
].nl_cmd
) {
421 if (cmd
== NL80211_CMD_VENDOR
422 && ((vendor_id
!= info
->event_cb
[i
].vendor_id
)
423 || (subcmd
!= info
->event_cb
[i
].vendor_subcmd
)))
425 /* event for a different vendor, ignore it */
429 cb_info
*cbi
= &(info
->event_cb
[i
]);
430 nl_recvmsg_msg_cb_t cb_func
= cbi
->cb_func
;
431 void *cb_arg
= cbi
->cb_arg
;
432 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
437 pthread_mutex_unlock(&info
->cb_lock
);
439 (*cb_func
)(msg
, cb_arg
);
448 pthread_mutex_unlock(&info
->cb_lock
);
452 ///////////////////////////////////////////////////////////////////////////////////////
454 class GetMulticastIdCommand
: public WifiCommand
461 GetMulticastIdCommand(wifi_handle handle
, const char *name
, const char *group
)
462 : WifiCommand(handle
, 0)
473 virtual int create() {
474 int nlctrlFamily
= genl_ctrl_resolve(mInfo
->cmd_sock
, "nlctrl");
475 int ret
= mMsg
.create(nlctrlFamily
, CTRL_CMD_GETFAMILY
, 0, 0);
479 ret
= mMsg
.put_string(CTRL_ATTR_FAMILY_NAME
, mName
);
483 virtual int handleResponse(WifiEvent
& reply
) {
484 struct nlattr
**tb
= reply
.attributes();
485 struct nlattr
*mcgrp
= NULL
;
488 if (!tb
[CTRL_ATTR_MCAST_GROUPS
]) {
489 ALOGE("No multicast groups found");
493 for_each_attr(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
495 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
496 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, (nlattr
*)nla_data(mcgrp
),
497 nla_len(mcgrp
), NULL
);
498 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] || !tb2
[CTRL_ATTR_MCAST_GRP_ID
]) {
502 char *grpName
= (char *)nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
503 int grpNameLen
= nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
505 if (strncmp(grpName
, mGroup
, grpNameLen
) != 0)
508 mId
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
517 class SetPnoMacAddrOuiCommand
: public WifiCommand
{
522 feature_set
*feature_matrix
;
526 SetPnoMacAddrOuiCommand(wifi_interface_handle handle
, oui scan_oui
)
527 : WifiCommand(handle
, 0)
531 feature_matrix
= NULL
;
536 int createRequest(WifiRequest
& request
, int subcmd
, byte
*scan_oui
) {
537 int result
= request
.create(GOOGLE_OUI
, subcmd
);
542 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
543 result
= request
.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
, scan_oui
, DOT11_OUI_LEN
);
548 request
.attr_end(data
);
554 WifiRequest
request(familyId(), ifaceId());
555 int result
= createRequest(request
, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI
, mOui
);
556 if (result
!= WIFI_SUCCESS
) {
557 ALOGE("failed to create request; result = %d", result
);
561 result
= requestResponse(request
);
562 if (result
!= WIFI_SUCCESS
) {
563 ALOGE("failed to set scanning mac OUI; result = %d", result
);
569 virtual int handleResponse(WifiEvent
& reply
) {
570 /* Nothing to do on response! */
575 class SetNodfsCommand
: public WifiCommand
{
580 SetNodfsCommand(wifi_interface_handle handle
, u32 nodfs
)
581 : WifiCommand(handle
, 0) {
584 virtual int create() {
587 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS
);
589 ALOGE("Can't create message to send to driver - %d", ret
);
593 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
594 ret
= mMsg
.put_u32(ATTR_NODFS_VALUE
, mNoDfs
);
604 class SetRSSIMonitorCommand
: public WifiCommand
{
608 wifi_rssi_event_handler mHandler
;
610 SetRSSIMonitorCommand(wifi_request_id id
, wifi_interface_handle handle
,
611 s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
612 : WifiCommand(handle
, id
), mMax_rssi(max_rssi
), mMin_rssi
613 (min_rssi
), mHandler(eh
)
616 int createRequest(WifiRequest
& request
, int enable
) {
617 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR
);
622 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
623 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
, (enable
? mMax_rssi
: 0));
628 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
, (enable
? mMin_rssi
: 0));
632 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_START
, enable
);
636 request
.attr_end(data
);
641 WifiRequest
request(familyId(), ifaceId());
642 int result
= createRequest(request
, 1);
646 result
= requestResponse(request
);
648 ALOGI("Failed to set RSSI Monitor, result = %d", result
);
651 ALOGI("Successfully set RSSI monitoring");
652 registerVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
657 virtual int cancel() {
659 WifiRequest
request(familyId(), ifaceId());
660 int result
= createRequest(request
, 0);
661 if (result
!= WIFI_SUCCESS
) {
662 ALOGE("failed to create request; result = %d", result
);
664 result
= requestResponse(request
);
665 if (result
!= WIFI_SUCCESS
) {
666 ALOGE("failed to stop RSSI monitoring = %d", result
);
669 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
673 virtual int handleResponse(WifiEvent
& reply
) {
674 /* Nothing to do on response! */
678 virtual int handleEvent(WifiEvent
& event
) {
680 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
681 int len
= event
.get_vendor_data_len();
683 if (vendor_data
== NULL
|| len
== 0) {
684 ALOGI("RSSI monitor: No data");
693 rssi_monitor_evt
*data
= (rssi_monitor_evt
*)event
.get_vendor_data();
695 if (*mHandler
.on_rssi_threshold_breached
) {
696 (*mHandler
.on_rssi_threshold_breached
)(id(), data
->BSSID
, data
->cur_rssi
);
698 ALOGW("No RSSI monitor handler registered");
706 class SetCountryCodeCommand
: public WifiCommand
{
708 const char *mCountryCode
;
710 SetCountryCodeCommand(wifi_interface_handle handle
, const char *country_code
)
711 : WifiCommand(handle
, 0) {
712 mCountryCode
= country_code
;
714 virtual int create() {
717 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_COUNTRY_CODE
);
719 ALOGE("Can't create message to send to driver - %d", ret
);
723 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
724 ret
= mMsg
.put_string(ATTR_COUNTRY_CODE
, mCountryCode
);
735 class GetFeatureSetCommand
: public WifiCommand
{
742 GetFeatureSetCommand(wifi_interface_handle handle
, feature_set
*set
)
743 : WifiCommand(handle
, 0)
748 virtual int create() {
751 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_GET_FEATURE_SET
);
753 ALOGE("create failed - %d", ret
);
760 virtual int handleResponse(WifiEvent
& reply
) {
762 int id
= reply
.get_vendor_id();
763 int subcmd
= reply
.get_vendor_subcmd();
765 if (reply
.get_cmd() != NL80211_CMD_VENDOR
) {
766 ALOGD("Ignore reply; cmd = %d", reply
.get_cmd());
770 nlattr
*vendor_data
= reply
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
771 int len
= reply
.get_vendor_data_len();
773 if (vendor_data
== NULL
|| len
== 0) {
774 ALOGE("vendor data in GetFeatureSetCommand missing!!");
778 void *data
= reply
.get_vendor_data();
780 ALOGE("feature_set Pointer not set");
783 memcpy(fset
, data
, min(len
, (int) sizeof(*fset
)));
789 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
)
791 GetMulticastIdCommand
cmd(handle
, name
, group
);
792 int res
= cmd
.requestResponse();
799 /////////////////////////////////////////////////////////////////////////
801 static bool is_wifi_interface(const char *name
)
803 if (strncmp(name
, "wlan", 4) != 0 && strncmp(name
, "p2p", 3) != 0) {
804 /* not a wifi interface; ignore it */
811 static int get_interface(const char *name
, interface_info
*info
)
813 strcpy(info
->name
, name
);
814 info
->id
= if_nametoindex(name
);
818 wifi_error
wifi_init_interfaces(wifi_handle handle
)
820 hal_info
*info
= (hal_info
*)handle
;
823 DIR *d
= opendir("/sys/class/net");
825 return WIFI_ERROR_UNKNOWN
;
828 while ((de
= readdir(d
))) {
829 if (de
->d_name
[0] == '.')
831 if (is_wifi_interface(de
->d_name
) ) {
838 d
= opendir("/sys/class/net");
840 return WIFI_ERROR_UNKNOWN
;
842 info
->interfaces
= (interface_info
**)malloc(sizeof(interface_info
*) * n
);
845 while ((de
= readdir(d
))) {
846 if (de
->d_name
[0] == '.')
848 if (is_wifi_interface(de
->d_name
)) {
849 interface_info
*ifinfo
= (interface_info
*)malloc(sizeof(interface_info
));
850 if (get_interface(de
->d_name
, ifinfo
) != WIFI_SUCCESS
) {
854 ifinfo
->handle
= handle
;
855 info
->interfaces
[i
] = ifinfo
;
862 info
->num_interfaces
= n
;
866 wifi_error
wifi_get_ifaces(wifi_handle handle
, int *num
, wifi_interface_handle
**interfaces
)
868 hal_info
*info
= (hal_info
*)handle
;
870 *interfaces
= (wifi_interface_handle
*)info
->interfaces
;
871 *num
= info
->num_interfaces
;
876 wifi_error
wifi_get_iface_name(wifi_interface_handle handle
, char *name
, size_t size
)
878 interface_info
*info
= (interface_info
*)handle
;
879 strcpy(name
, info
->name
);
883 wifi_error
wifi_get_concurrency_matrix(wifi_interface_handle handle
, int set_size_max
,
884 feature_set set
[], int *set_size
)
886 return WIFI_ERROR_NOT_SUPPORTED
;
889 wifi_error
wifi_set_scanning_mac_oui(wifi_interface_handle handle
, oui scan_oui
)
891 SetPnoMacAddrOuiCommand
command(handle
, scan_oui
);
892 return (wifi_error
)command
.start();
896 wifi_error
wifi_set_nodfs_flag(wifi_interface_handle handle
, u32 nodfs
)
898 SetNodfsCommand
command(handle
, nodfs
);
899 return (wifi_error
) command
.requestResponse();
902 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
903 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
905 ALOGD("Start RSSI monitor %d", id
);
906 wifi_handle handle
= getWifiHandle(iface
);
907 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
, max_rssi
, min_rssi
, eh
);
908 wifi_register_cmd(handle
, id
, cmd
);
910 wifi_error result
= (wifi_error
)cmd
->start();
911 if (result
!= WIFI_SUCCESS
) {
912 wifi_unregister_cmd(handle
, id
);
918 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
)
920 ALOGD("Stopping RSSI monitor");
923 wifi_rssi_event_handler handler
;
924 wifi_handle handle
= getWifiHandle(iface
);
925 memset(&handler
, 0, sizeof(handler
));
926 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
,
932 return wifi_cancel_cmd(id
, iface
);
935 wifi_error
wifi_get_supported_feature_set(wifi_interface_handle handle
, feature_set
*set
)
937 GetFeatureSetCommand
command(handle
, set
);
938 return (wifi_error
) command
.requestResponse();
941 wifi_error
wifi_set_country_code(wifi_interface_handle handle
, const char *country_code
)
943 SetCountryCodeCommand
command(handle
, country_code
);
944 return (wifi_error
) command
.requestResponse();
947 /////////////////////////////////////////////////////////////////////////////