4 #include <sys/socket.h>
5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8 #include <linux/rtnetlink.h>
9 #include <netpacket/packet.h>
10 #include <linux/filter.h>
11 #include <linux/errqueue.h>
13 #include <linux/pkt_sched.h>
14 #include <netlink/object-api.h>
15 #include <netlink/netlink.h>
16 #include <netlink/socket.h>
17 #include <netlink/attr.h>
18 #include <netlink/handlers.h>
19 #include <netlink/msg.h>
26 #define LOG_TAG "WifiHAL"
28 #include <utils/Log.h>
31 #include "cpp_bindings.h"
34 #define WIFI_HAL_CMD_SOCK_PORT 644
35 #define WIFI_HAL_EVENT_SOCK_PORT 645
38 #define FEATURE_SET_MATRIX 1
39 #define ATTR_NODFS_VALUE 3
41 static void internal_event_handler(wifi_handle handle
, int events
);
42 static int internal_no_seq_check(nl_msg
*msg
, void *arg
);
43 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
);
44 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
);
45 static int wifi_add_membership(wifi_handle handle
, const char *group
);
46 static wifi_error
wifi_init_interfaces(wifi_handle handle
);
48 typedef enum wifi_attr
{
49 ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET
,
50 ANDR_WIFI_ATTRIBUTE_FEATURE_SET
,
51 ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
54 enum wifi_rssi_monitor_attr
{
55 RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
,
56 RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
,
57 RSSI_MONITOR_ATTRIBUTE_START
,
60 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
61 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
);
62 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
);
64 /* Initialize/Cleanup */
66 void wifi_socket_set_local_port(struct nl_sock
*sock
, uint32_t port
)
68 uint32_t pid
= getpid() & 0x3FFFFF;
69 nl_socket_set_local_port(sock
, pid
+ (port
<< 22));
72 static nl_sock
* wifi_create_nl_socket(int port
)
74 ALOGI("Creating socket");
75 struct nl_sock
*sock
= nl_socket_alloc();
77 ALOGE("Could not create handle");
81 wifi_socket_set_local_port(sock
, port
);
83 ALOGI("Connecting socket");
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
;
123 fn
->wifi_set_epno_list
= wifi_set_epno_list
;
124 fn
->wifi_set_passpoint_list
= wifi_set_passpoint_list
;
125 fn
->wifi_reset_passpoint_list
= wifi_reset_passpoint_list
;
127 fn
->wifi_set_bssid_blacklist
= wifi_set_bssid_blacklist
;
128 fn
->wifi_start_rssi_monitoring
= wifi_start_rssi_monitoring
;
129 fn
->wifi_stop_rssi_monitoring
= wifi_stop_rssi_monitoring
;
130 fn
->wifi_get_link_stats
= wifi_get_link_stats
;
135 wifi_error
wifi_initialize(wifi_handle
*handle
)
139 ALOGI("Initializing wifi");
140 hal_info
*info
= (hal_info
*)malloc(sizeof(hal_info
));
142 ALOGE("Could not allocate hal_info");
143 return WIFI_ERROR_UNKNOWN
;
146 memset(info
, 0, sizeof(*info
));
148 ALOGI("Creating socket");
149 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, info
->cleanup_socks
) == -1) {
150 ALOGE("Could not create cleanup sockets");
152 return WIFI_ERROR_UNKNOWN
;
155 struct nl_sock
*cmd_sock
= wifi_create_nl_socket(WIFI_HAL_CMD_SOCK_PORT
);
156 if (cmd_sock
== NULL
) {
157 ALOGE("Could not create handle");
159 return WIFI_ERROR_UNKNOWN
;
162 struct nl_sock
*event_sock
= wifi_create_nl_socket(WIFI_HAL_EVENT_SOCK_PORT
);
163 if (event_sock
== NULL
) {
164 ALOGE("Could not create handle");
165 nl_socket_free(cmd_sock
);
167 return WIFI_ERROR_UNKNOWN
;
170 struct nl_cb
*cb
= nl_socket_get_cb(event_sock
);
172 ALOGE("Could not create handle");
173 nl_socket_free(cmd_sock
);
174 nl_socket_free(event_sock
);
176 return WIFI_ERROR_UNKNOWN
;
179 // ALOGI("cb->refcnt = %d", cb->cb_refcnt);
180 nl_cb_set(cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, internal_no_seq_check
, info
);
181 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, internal_valid_message_handler
, info
);
184 info
->cmd_sock
= cmd_sock
;
185 info
->event_sock
= event_sock
;
186 info
->clean_up
= false;
187 info
->in_event_loop
= false;
189 info
->event_cb
= (cb_info
*)malloc(sizeof(cb_info
) * DEFAULT_EVENT_CB_SIZE
);
190 info
->alloc_event_cb
= DEFAULT_EVENT_CB_SIZE
;
191 info
->num_event_cb
= 0;
193 info
->cmd
= (cmd_info
*)malloc(sizeof(cmd_info
) * DEFAULT_CMD_SIZE
);
194 info
->alloc_cmd
= DEFAULT_CMD_SIZE
;
197 info
->nl80211_family_id
= genl_ctrl_resolve(cmd_sock
, "nl80211");
198 if (info
->nl80211_family_id
< 0) {
199 ALOGE("Could not resolve nl80211 familty id");
200 nl_socket_free(cmd_sock
);
201 nl_socket_free(event_sock
);
203 return WIFI_ERROR_UNKNOWN
;
206 pthread_mutex_init(&info
->cb_lock
, NULL
);
208 *handle
= (wifi_handle
) info
;
209 ALOGD("wifi_initialize, handle = %p\n", handle
);
210 ALOGD("wifi_initialize, *handle = %p\n", *handle
);
211 ALOGD("wifi_initialize, info = %p\n", info
);
212 ALOGD("wifi_initialize, *info = %pn", *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 ALOGD("Found %d interfaces", info
->num_interfaces
);
222 ALOGI("Initialized Wifi HAL Successfully; vendor cmd = %d", NL80211_CMD_VENDOR
);
226 static int wifi_add_membership(wifi_handle handle
, const char *group
)
228 hal_info
*info
= getHalInfo(handle
);
230 int id
= wifi_get_multicast_id(handle
, "nl80211", group
);
232 ALOGE("Could not find group %s", group
);
236 int ret
= nl_socket_add_membership(info
->event_sock
, id
);
238 ALOGE("Could not add membership to group %s", group
);
241 ALOGI("Successfully added membership for group %s", group
);
245 static void internal_cleaned_up_handler(wifi_handle handle
)
247 hal_info
*info
= getHalInfo(handle
);
248 wifi_cleaned_up_handler cleaned_up_handler
= info
->cleaned_up_handler
;
250 if (info
->cmd_sock
!= 0) {
251 close(info
->cleanup_socks
[0]);
252 close(info
->cleanup_socks
[1]);
253 nl_socket_free(info
->cmd_sock
);
254 nl_socket_free(info
->event_sock
);
255 info
->cmd_sock
= NULL
;
256 info
->event_sock
= NULL
;
259 (*cleaned_up_handler
)(handle
);
260 pthread_mutex_destroy(&info
->cb_lock
);
263 ALOGI("Internal cleanup completed");
266 void wifi_cleanup(wifi_handle handle
, wifi_cleaned_up_handler handler
)
268 hal_info
*info
= getHalInfo(handle
);
271 info
->cleaned_up_handler
= handler
;
272 if (write(info
->cleanup_socks
[0], "Exit", 4) < 1) {
273 ALOGE("could not write to the cleanup socket");
275 // Listen to the response
276 // Hopefully we dont get errors or get hung up
277 // Not much can be done in that case, but assume that
278 // it has rx'ed the Exit message to exit the thread.
279 // As a fallback set the cleanup flag to TRUE
280 memset(buf
, 0, sizeof(buf
));
281 int result
= read(info
->cleanup_socks
[0], buf
, sizeof(buf
));
282 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result
, errno
);
283 if (strncmp(buf
, "Done", 4) == 0) {
284 ALOGE("Event processing terminated");
286 ALOGD("Rx'ed %s", buf
);
289 info
->clean_up
= true;
290 pthread_mutex_lock(&info
->cb_lock
);
292 int bad_commands
= 0;
294 while (info
->num_cmd
> bad_commands
) {
295 int num_cmd
= info
->num_cmd
;
296 cmd_info
*cmdi
= &(info
->cmd
[bad_commands
]);
297 WifiCommand
*cmd
= cmdi
->cmd
;
299 pthread_mutex_unlock(&info
->cb_lock
);
301 pthread_mutex_lock(&info
->cb_lock
);
302 /* release reference added when command is saved */
304 if (num_cmd
== info
->num_cmd
) {
310 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
311 cb_info
*cbi
= &(info
->event_cb
[i
]);
312 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
313 ALOGE("Leaked command %p", cmd
);
315 pthread_mutex_unlock(&info
->cb_lock
);
316 internal_cleaned_up_handler(handle
);
319 static int internal_pollin_handler(wifi_handle handle
)
321 hal_info
*info
= getHalInfo(handle
);
322 ALOGI("even_loop info = %p", info
);
323 struct nl_cb
*cb
= nl_socket_get_cb(info
->event_sock
);
324 int res
= nl_recvmsgs(info
->event_sock
, cb
);
325 ALOGD("nl_recvmsgs returned %d", res
);
330 /* Run event handler */
331 void wifi_event_loop(wifi_handle handle
)
333 hal_info
*info
= getHalInfo(handle
);
334 ALOGI("even_loop info = %p", info
);
335 ALOGI("even_loop info = %p", handle
);
336 if (info
->in_event_loop
) {
339 info
->in_event_loop
= true;
343 memset(&pfd
[0], 0, sizeof(pollfd
) * 2);
345 pfd
[0].fd
= nl_socket_get_fd(info
->event_sock
);
346 pfd
[0].events
= POLLIN
;
347 pfd
[1].fd
= info
->cleanup_socks
[1];
348 pfd
[1].events
= POLLIN
;
353 int timeout
= -1; /* Infinite timeout */
356 int result
= poll(pfd
, 2, timeout
);
358 } else if (pfd
[0].revents
& POLLERR
) {
359 ALOGE("POLL Error; error no = %d", errno
);
360 int result2
= read(pfd
[0].fd
, buf
, sizeof(buf
));
361 ALOGE("Read after POLL returned %d, error no = %d", result2
, errno
);
362 } else if (pfd
[0].revents
& POLLHUP
) {
363 ALOGE("Remote side hung up");
365 } else if (pfd
[0].revents
& POLLIN
) {
366 internal_pollin_handler(handle
);
367 } else if (pfd
[1].revents
& POLLIN
) {
368 memset(buf
, 0, sizeof(buf
));
369 int result2
= read(pfd
[1].fd
, buf
, sizeof(buf
));
370 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result2
, errno
);
371 if (strncmp(buf
, "Exit", 4) == 0) {
372 ALOGD("Got a signal to exit!!!");
373 if (write(pfd
[1].fd
, "Done", 4) < 1) {
374 ALOGE("could not write to the cleanup socket");
378 ALOGD("Rx'ed %s on the cleanup socket\n", buf
);
381 ALOGE("Unknown event - %0x, %0x", pfd
[0].revents
, pfd
[1].revents
);
383 } while (!info
->clean_up
);
384 ALOGI("Exit %s", __FUNCTION__
);
387 ///////////////////////////////////////////////////////////////////////////////////////
389 static int internal_no_seq_check(struct nl_msg
*msg
, void *arg
)
394 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
)
396 wifi_handle handle
= (wifi_handle
)arg
;
397 hal_info
*info
= getHalInfo(handle
);
398 ALOGI("even_loop info = %p", handle
);
399 ALOGD("internal_valid_message_handler, info = %p", info
);
401 WifiEvent
event(msg
);
402 int res
= event
.parse();
404 ALOGE("Failed to parse event: %d", res
);
408 int cmd
= event
.get_cmd();
409 uint32_t vendor_id
= 0;
412 if (cmd
== NL80211_CMD_VENDOR
) {
413 vendor_id
= event
.get_u32(NL80211_ATTR_VENDOR_ID
);
414 subcmd
= event
.get_u32(NL80211_ATTR_VENDOR_SUBCMD
);
415 ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
416 event
.get_cmdString(), vendor_id
, subcmd
);
418 ALOGI("event received %s", event
.get_cmdString());
421 //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
424 pthread_mutex_lock(&info
->cb_lock
);
426 ALOGI("Number of events %d", info
->num_event_cb
);
428 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
429 if (cmd
== info
->event_cb
[i
].nl_cmd
) {
430 if (cmd
== NL80211_CMD_VENDOR
431 && ((vendor_id
!= info
->event_cb
[i
].vendor_id
)
432 || (subcmd
!= info
->event_cb
[i
].vendor_subcmd
)))
434 /* event for a different vendor, ignore it */
438 cb_info
*cbi
= &(info
->event_cb
[i
]);
439 nl_recvmsg_msg_cb_t cb_func
= cbi
->cb_func
;
440 void *cb_arg
= cbi
->cb_arg
;
441 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
446 pthread_mutex_unlock(&info
->cb_lock
);
448 (*cb_func
)(msg
, cb_arg
);
457 pthread_mutex_unlock(&info
->cb_lock
);
461 ///////////////////////////////////////////////////////////////////////////////////////
463 class GetMulticastIdCommand
: public WifiCommand
470 GetMulticastIdCommand(wifi_handle handle
, const char *name
, const char *group
)
471 : WifiCommand(handle
, 0)
482 virtual int create() {
483 int nlctrlFamily
= genl_ctrl_resolve(mInfo
->cmd_sock
, "nlctrl");
484 ALOGI("ctrl family = %d", nlctrlFamily
);
485 int ret
= mMsg
.create(nlctrlFamily
, CTRL_CMD_GETFAMILY
, 0, 0);
489 ret
= mMsg
.put_string(CTRL_ATTR_FAMILY_NAME
, mName
);
493 virtual int handleResponse(WifiEvent
& reply
) {
495 ALOGE("handling reponse in %s", __func__
);
497 struct nlattr
**tb
= reply
.attributes();
498 struct nlattr
*mcgrp
= NULL
;
501 if (!tb
[CTRL_ATTR_MCAST_GROUPS
]) {
502 ALOGE("No multicast groups found");
505 ALOGE("Multicast groups attr size = %d", nla_len(tb
[CTRL_ATTR_MCAST_GROUPS
]));
508 for_each_attr(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
510 ALOGE("Processing group");
511 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
512 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, (nlattr
*)nla_data(mcgrp
),
513 nla_len(mcgrp
), NULL
);
514 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] || !tb2
[CTRL_ATTR_MCAST_GRP_ID
]) {
518 char *grpName
= (char *)nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
519 int grpNameLen
= nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
521 ALOGE("Found group name %s", grpName
);
523 if (strncmp(grpName
, mGroup
, grpNameLen
) != 0)
526 mId
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
535 class SetPnoMacAddrOuiCommand
: public WifiCommand
{
540 feature_set
*feature_matrix
;
544 SetPnoMacAddrOuiCommand(wifi_interface_handle handle
, oui scan_oui
)
545 : WifiCommand(handle
, 0)
550 int createRequest(WifiRequest
& request
, int subcmd
, byte
*scan_oui
) {
551 int result
= request
.create(GOOGLE_OUI
, subcmd
);
556 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
557 result
= request
.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
, scan_oui
, DOT11_OUI_LEN
);
562 request
.attr_end(data
);
568 ALOGD("Sending mac address OUI");
569 WifiRequest
request(familyId(), ifaceId());
570 int result
= createRequest(request
, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI
, mOui
);
571 if (result
!= WIFI_SUCCESS
) {
572 ALOGE("failed to create request; result = %d", result
);
576 result
= requestResponse(request
);
577 if (result
!= WIFI_SUCCESS
) {
578 ALOGE("failed to set scanning mac OUI; result = %d", result
);
584 virtual int handleResponse(WifiEvent
& reply
) {
585 ALOGD("Request complete!");
586 /* Nothing to do on response! */
591 class SetNodfsCommand
: public WifiCommand
{
596 SetNodfsCommand(wifi_interface_handle handle
, u32 nodfs
)
597 : WifiCommand(handle
, 0) {
600 virtual int create() {
603 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS
);
605 ALOGE("Can't create message to send to driver - %d", ret
);
609 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
610 ret
= mMsg
.put_u32(ATTR_NODFS_VALUE
, mNoDfs
);
620 class SetRSSIMonitorCommand
: public WifiCommand
{
624 wifi_rssi_event_handler mHandler
;
626 SetRSSIMonitorCommand(wifi_request_id id
, wifi_interface_handle handle
,
627 s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
628 : WifiCommand(handle
, id
), mMax_rssi(max_rssi
), mMin_rssi
629 (min_rssi
), mHandler(eh
)
632 int createRequest(WifiRequest
& request
, int enable
) {
633 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR
);
638 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
639 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
, (enable
? mMax_rssi
: 0));
643 ALOGD("create request");
644 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
, (enable
? mMin_rssi
: 0));
648 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_START
, enable
);
652 request
.attr_end(data
);
657 WifiRequest
request(familyId(), ifaceId());
658 int result
= createRequest(request
, 1);
662 result
= requestResponse(request
);
664 ALOGI("Failed to set RSSI Monitor, result = %d", result
);
667 ALOGI("Successfully set RSSI monitoring");
668 registerVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
672 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
679 virtual int cancel() {
681 WifiRequest
request(familyId(), ifaceId());
682 int result
= createRequest(request
, 0);
683 if (result
!= WIFI_SUCCESS
) {
684 ALOGE("failed to create request; result = %d", result
);
686 result
= requestResponse(request
);
687 if (result
!= WIFI_SUCCESS
) {
688 ALOGE("failed to stop RSSI monitoring = %d", result
);
691 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
695 virtual int handleResponse(WifiEvent
& reply
) {
696 /* Nothing to do on response! */
700 virtual int handleEvent(WifiEvent
& event
) {
701 ALOGI("Got a RSSI monitor event");
703 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
704 int len
= event
.get_vendor_data_len();
706 if (vendor_data
== NULL
|| len
== 0) {
707 ALOGI("RSSI monitor: No data");
716 rssi_monitor_evt
*data
= (rssi_monitor_evt
*)event
.get_vendor_data();
718 if (*mHandler
.on_rssi_threshold_breached
) {
719 (*mHandler
.on_rssi_threshold_breached
)(id(), data
->BSSID
, data
->cur_rssi
);
721 ALOGW("No RSSI monitor handler registered");
731 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
)
733 GetMulticastIdCommand
cmd(handle
, name
, group
);
734 int res
= cmd
.requestResponse();
741 /////////////////////////////////////////////////////////////////////////
743 static bool is_wifi_interface(const char *name
)
745 if (strncmp(name
, "wlan", 4) != 0 && strncmp(name
, "p2p", 3) != 0) {
746 /* not a wifi interface; ignore it */
753 static int get_interface(const char *name
, interface_info
*info
)
755 strcpy(info
->name
, name
);
756 info
->id
= if_nametoindex(name
);
757 ALOGI("found an interface : %s, id = %d", name
, info
->id
);
761 wifi_error
wifi_init_interfaces(wifi_handle handle
)
763 hal_info
*info
= (hal_info
*)handle
;
764 ALOGD("wifi_init_interfaces, info = %p", info
);
768 DIR *d
= opendir("/sys/class/net");
770 return WIFI_ERROR_UNKNOWN
;
773 while ((de
= readdir(d
))) {
774 if (de
->d_name
[0] == '.')
776 if (is_wifi_interface(de
->d_name
) ) {
783 d
= opendir("/sys/class/net");
785 return WIFI_ERROR_UNKNOWN
;
787 info
->interfaces
= (interface_info
**)malloc(sizeof(interface_info
*) * n
);
790 while ((de
= readdir(d
))) {
791 if (de
->d_name
[0] == '.')
793 if (is_wifi_interface(de
->d_name
)) {
794 interface_info
*ifinfo
= (interface_info
*)malloc(sizeof(interface_info
));
795 if (get_interface(de
->d_name
, ifinfo
) != WIFI_SUCCESS
) {
799 ifinfo
->handle
= handle
;
800 info
->interfaces
[i
] = ifinfo
;
807 info
->num_interfaces
= n
;
811 wifi_error
wifi_get_ifaces(wifi_handle handle
, int *num
, wifi_interface_handle
**interfaces
)
813 hal_info
*info
= (hal_info
*)handle
;
815 *interfaces
= (wifi_interface_handle
*)info
->interfaces
;
816 *num
= info
->num_interfaces
;
821 wifi_error
wifi_get_iface_name(wifi_interface_handle handle
, char *name
, size_t size
)
823 interface_info
*info
= (interface_info
*)handle
;
824 strcpy(name
, info
->name
);
828 wifi_error
wifi_get_supported_feature_set(wifi_interface_handle handle
, feature_set
*set
)
830 return WIFI_ERROR_NOT_SUPPORTED
;
833 wifi_error
wifi_get_concurrency_matrix(wifi_interface_handle handle
, int set_size_max
,
834 feature_set set
[], int *set_size
)
836 return WIFI_ERROR_NOT_SUPPORTED
;
839 wifi_error
wifi_set_scanning_mac_oui(wifi_interface_handle handle
, oui scan_oui
)
841 SetPnoMacAddrOuiCommand
command(handle
, scan_oui
);
842 return (wifi_error
)command
.start();
846 wifi_error
wifi_set_nodfs_flag(wifi_interface_handle handle
, u32 nodfs
)
848 SetNodfsCommand
command(handle
, nodfs
);
849 return (wifi_error
) command
.requestResponse();
852 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
853 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
855 ALOGD("Start RSSI monitor %d", id
);
856 wifi_handle handle
= getWifiHandle(iface
);
857 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
, max_rssi
, min_rssi
, eh
);
858 wifi_register_cmd(handle
, id
, cmd
);
860 wifi_error result
= (wifi_error
)cmd
->start();
861 if (result
!= WIFI_SUCCESS
) {
862 wifi_unregister_cmd(handle
, id
);
868 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
)
870 ALOGD("Stopping RSSI monitor");
873 wifi_rssi_event_handler handler
;
874 wifi_handle handle
= getWifiHandle(iface
);
875 memset(&handler
, 0, sizeof(handler
));
876 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
,
882 return wifi_cancel_cmd(id
, iface
);
885 /////////////////////////////////////////////////////////////////////////////