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_set_link_stats
= wifi_set_link_stats
;
131 fn
->wifi_get_link_stats
= wifi_get_link_stats
;
132 fn
->wifi_clear_link_stats
= wifi_clear_link_stats
;
137 wifi_error
wifi_initialize(wifi_handle
*handle
)
141 ALOGI("Initializing wifi");
142 hal_info
*info
= (hal_info
*)malloc(sizeof(hal_info
));
144 ALOGE("Could not allocate hal_info");
145 return WIFI_ERROR_UNKNOWN
;
148 memset(info
, 0, sizeof(*info
));
150 ALOGI("Creating socket");
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
;
211 ALOGD("wifi_initialize, handle = %p\n", handle
);
212 ALOGD("wifi_initialize, *handle = %p\n", *handle
);
213 ALOGD("wifi_initialize, info = %p\n", info
);
214 ALOGD("wifi_initialize, *info = %pn", *info
);
215 wifi_add_membership(*handle
, "scan");
216 wifi_add_membership(*handle
, "mlme");
217 wifi_add_membership(*handle
, "regulatory");
218 wifi_add_membership(*handle
, "vendor");
220 wifi_init_interfaces(*handle
);
221 ALOGD("Found %d interfaces", info
->num_interfaces
);
224 ALOGI("Initialized Wifi HAL Successfully; vendor cmd = %d", NL80211_CMD_VENDOR
);
228 static int wifi_add_membership(wifi_handle handle
, const char *group
)
230 hal_info
*info
= getHalInfo(handle
);
232 int id
= wifi_get_multicast_id(handle
, "nl80211", group
);
234 ALOGE("Could not find group %s", group
);
238 int ret
= nl_socket_add_membership(info
->event_sock
, id
);
240 ALOGE("Could not add membership to group %s", group
);
243 ALOGI("Successfully added membership for group %s", group
);
247 static void internal_cleaned_up_handler(wifi_handle handle
)
249 hal_info
*info
= getHalInfo(handle
);
250 wifi_cleaned_up_handler cleaned_up_handler
= info
->cleaned_up_handler
;
252 if (info
->cmd_sock
!= 0) {
253 close(info
->cleanup_socks
[0]);
254 close(info
->cleanup_socks
[1]);
255 nl_socket_free(info
->cmd_sock
);
256 nl_socket_free(info
->event_sock
);
257 info
->cmd_sock
= NULL
;
258 info
->event_sock
= NULL
;
261 (*cleaned_up_handler
)(handle
);
262 pthread_mutex_destroy(&info
->cb_lock
);
265 ALOGI("Internal cleanup completed");
268 void wifi_cleanup(wifi_handle handle
, wifi_cleaned_up_handler handler
)
270 hal_info
*info
= getHalInfo(handle
);
273 info
->cleaned_up_handler
= handler
;
274 if (write(info
->cleanup_socks
[0], "Exit", 4) < 1) {
275 ALOGE("could not write to the cleanup socket");
277 // Listen to the response
278 // Hopefully we dont get errors or get hung up
279 // Not much can be done in that case, but assume that
280 // it has rx'ed the Exit message to exit the thread.
281 // As a fallback set the cleanup flag to TRUE
282 memset(buf
, 0, sizeof(buf
));
283 int result
= read(info
->cleanup_socks
[0], buf
, sizeof(buf
));
284 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result
, errno
);
285 if (strncmp(buf
, "Done", 4) == 0) {
286 ALOGE("Event processing terminated");
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 ALOGI("even_loop info = %p", info
);
325 struct nl_cb
*cb
= nl_socket_get_cb(info
->event_sock
);
326 int res
= nl_recvmsgs(info
->event_sock
, cb
);
327 ALOGD("nl_recvmsgs returned %d", res
);
332 /* Run event handler */
333 void wifi_event_loop(wifi_handle handle
)
335 hal_info
*info
= getHalInfo(handle
);
336 ALOGI("even_loop info = %p", info
);
337 ALOGI("even_loop info = %p", handle
);
338 if (info
->in_event_loop
) {
341 info
->in_event_loop
= true;
345 memset(&pfd
[0], 0, sizeof(pollfd
) * 2);
347 pfd
[0].fd
= nl_socket_get_fd(info
->event_sock
);
348 pfd
[0].events
= POLLIN
;
349 pfd
[1].fd
= info
->cleanup_socks
[1];
350 pfd
[1].events
= POLLIN
;
355 int timeout
= -1; /* Infinite timeout */
358 int result
= poll(pfd
, 2, timeout
);
360 } else if (pfd
[0].revents
& POLLERR
) {
361 ALOGE("POLL Error; error no = %d", errno
);
362 int result2
= read(pfd
[0].fd
, buf
, sizeof(buf
));
363 ALOGE("Read after POLL returned %d, error no = %d", result2
, errno
);
364 } else if (pfd
[0].revents
& POLLHUP
) {
365 ALOGE("Remote side hung up");
367 } else if (pfd
[0].revents
& POLLIN
) {
368 internal_pollin_handler(handle
);
369 } else if (pfd
[1].revents
& POLLIN
) {
370 memset(buf
, 0, sizeof(buf
));
371 int result2
= read(pfd
[1].fd
, buf
, sizeof(buf
));
372 ALOGE("%s: Read after POLL returned %d, error no = %d", __FUNCTION__
, result2
, errno
);
373 if (strncmp(buf
, "Exit", 4) == 0) {
374 ALOGD("Got a signal to exit!!!");
375 if (write(pfd
[1].fd
, "Done", 4) < 1) {
376 ALOGE("could not write to the cleanup socket");
380 ALOGD("Rx'ed %s on the cleanup socket\n", buf
);
383 ALOGE("Unknown event - %0x, %0x", pfd
[0].revents
, pfd
[1].revents
);
385 } while (!info
->clean_up
);
386 ALOGI("Exit %s", __FUNCTION__
);
389 ///////////////////////////////////////////////////////////////////////////////////////
391 static int internal_no_seq_check(struct nl_msg
*msg
, void *arg
)
396 static int internal_valid_message_handler(nl_msg
*msg
, void *arg
)
398 wifi_handle handle
= (wifi_handle
)arg
;
399 hal_info
*info
= getHalInfo(handle
);
400 ALOGI("even_loop info = %p", handle
);
401 ALOGD("internal_valid_message_handler, info = %p", info
);
403 WifiEvent
event(msg
);
404 int res
= event
.parse();
406 ALOGE("Failed to parse event: %d", res
);
410 int cmd
= event
.get_cmd();
411 uint32_t vendor_id
= 0;
414 if (cmd
== NL80211_CMD_VENDOR
) {
415 vendor_id
= event
.get_u32(NL80211_ATTR_VENDOR_ID
);
416 subcmd
= event
.get_u32(NL80211_ATTR_VENDOR_SUBCMD
);
417 ALOGI("event received %s, vendor_id = 0x%0x, subcmd = 0x%0x",
418 event
.get_cmdString(), vendor_id
, subcmd
);
420 ALOGI("event received %s", event
.get_cmdString());
423 //ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
426 pthread_mutex_lock(&info
->cb_lock
);
428 ALOGI("Number of events %d", info
->num_event_cb
);
430 for (int i
= 0; i
< info
->num_event_cb
; i
++) {
431 if (cmd
== info
->event_cb
[i
].nl_cmd
) {
432 if (cmd
== NL80211_CMD_VENDOR
433 && ((vendor_id
!= info
->event_cb
[i
].vendor_id
)
434 || (subcmd
!= info
->event_cb
[i
].vendor_subcmd
)))
436 /* event for a different vendor, ignore it */
440 cb_info
*cbi
= &(info
->event_cb
[i
]);
441 nl_recvmsg_msg_cb_t cb_func
= cbi
->cb_func
;
442 void *cb_arg
= cbi
->cb_arg
;
443 WifiCommand
*cmd
= (WifiCommand
*)cbi
->cb_arg
;
448 pthread_mutex_unlock(&info
->cb_lock
);
450 (*cb_func
)(msg
, cb_arg
);
459 pthread_mutex_unlock(&info
->cb_lock
);
463 ///////////////////////////////////////////////////////////////////////////////////////
465 class GetMulticastIdCommand
: public WifiCommand
472 GetMulticastIdCommand(wifi_handle handle
, const char *name
, const char *group
)
473 : WifiCommand(handle
, 0)
484 virtual int create() {
485 int nlctrlFamily
= genl_ctrl_resolve(mInfo
->cmd_sock
, "nlctrl");
486 ALOGI("ctrl family = %d", nlctrlFamily
);
487 int ret
= mMsg
.create(nlctrlFamily
, CTRL_CMD_GETFAMILY
, 0, 0);
491 ret
= mMsg
.put_string(CTRL_ATTR_FAMILY_NAME
, mName
);
495 virtual int handleResponse(WifiEvent
& reply
) {
497 ALOGE("handling reponse in %s", __func__
);
499 struct nlattr
**tb
= reply
.attributes();
500 struct nlattr
*mcgrp
= NULL
;
503 if (!tb
[CTRL_ATTR_MCAST_GROUPS
]) {
504 ALOGE("No multicast groups found");
507 ALOGE("Multicast groups attr size = %d", nla_len(tb
[CTRL_ATTR_MCAST_GROUPS
]));
510 for_each_attr(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
512 ALOGE("Processing group");
513 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
514 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, (nlattr
*)nla_data(mcgrp
),
515 nla_len(mcgrp
), NULL
);
516 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] || !tb2
[CTRL_ATTR_MCAST_GRP_ID
]) {
520 char *grpName
= (char *)nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
521 int grpNameLen
= nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]);
523 ALOGE("Found group name %s", grpName
);
525 if (strncmp(grpName
, mGroup
, grpNameLen
) != 0)
528 mId
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
537 class SetPnoMacAddrOuiCommand
: public WifiCommand
{
542 feature_set
*feature_matrix
;
546 SetPnoMacAddrOuiCommand(wifi_interface_handle handle
, oui scan_oui
)
547 : WifiCommand(handle
, 0)
552 int createRequest(WifiRequest
& request
, int subcmd
, byte
*scan_oui
) {
553 int result
= request
.create(GOOGLE_OUI
, subcmd
);
558 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
559 result
= request
.put(ANDR_WIFI_ATTRIBUTE_PNO_RANDOM_MAC_OUI
, scan_oui
, DOT11_OUI_LEN
);
564 request
.attr_end(data
);
570 ALOGD("Sending mac address OUI");
571 WifiRequest
request(familyId(), ifaceId());
572 int result
= createRequest(request
, SLSI_NL80211_VENDOR_SUBCMD_SET_GSCAN_OUI
, mOui
);
573 if (result
!= WIFI_SUCCESS
) {
574 ALOGE("failed to create request; result = %d", result
);
578 result
= requestResponse(request
);
579 if (result
!= WIFI_SUCCESS
) {
580 ALOGE("failed to set scanning mac OUI; result = %d", result
);
586 virtual int handleResponse(WifiEvent
& reply
) {
587 ALOGD("Request complete!");
588 /* Nothing to do on response! */
593 class SetNodfsCommand
: public WifiCommand
{
598 SetNodfsCommand(wifi_interface_handle handle
, u32 nodfs
)
599 : WifiCommand(handle
, 0) {
602 virtual int create() {
605 ret
= mMsg
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_NODFS
);
607 ALOGE("Can't create message to send to driver - %d", ret
);
611 nlattr
*data
= mMsg
.attr_start(NL80211_ATTR_VENDOR_DATA
);
612 ret
= mMsg
.put_u32(ATTR_NODFS_VALUE
, mNoDfs
);
622 class SetRSSIMonitorCommand
: public WifiCommand
{
626 wifi_rssi_event_handler mHandler
;
628 SetRSSIMonitorCommand(wifi_request_id id
, wifi_interface_handle handle
,
629 s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
630 : WifiCommand(handle
, id
), mMax_rssi(max_rssi
), mMin_rssi
631 (min_rssi
), mHandler(eh
)
634 int createRequest(WifiRequest
& request
, int enable
) {
635 int result
= request
.create(GOOGLE_OUI
, SLSI_NL80211_VENDOR_SUBCMD_SET_RSSI_MONITOR
);
640 nlattr
*data
= request
.attr_start(NL80211_ATTR_VENDOR_DATA
);
641 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MAX_RSSI
, (enable
? mMax_rssi
: 0));
645 ALOGD("create request");
646 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_MIN_RSSI
, (enable
? mMin_rssi
: 0));
650 result
= request
.put_u8(RSSI_MONITOR_ATTRIBUTE_START
, enable
);
654 request
.attr_end(data
);
659 WifiRequest
request(familyId(), ifaceId());
660 int result
= createRequest(request
, 1);
664 result
= requestResponse(request
);
666 ALOGI("Failed to set RSSI Monitor, result = %d", result
);
669 ALOGI("Successfully set RSSI monitoring");
670 registerVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
674 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
681 virtual int cancel() {
683 WifiRequest
request(familyId(), ifaceId());
684 int result
= createRequest(request
, 0);
685 if (result
!= WIFI_SUCCESS
) {
686 ALOGE("failed to create request; result = %d", result
);
688 result
= requestResponse(request
);
689 if (result
!= WIFI_SUCCESS
) {
690 ALOGE("failed to stop RSSI monitoring = %d", result
);
693 unregisterVendorHandler(GOOGLE_OUI
, WIFI_RSSI_REPORT_EVENT
);
697 virtual int handleResponse(WifiEvent
& reply
) {
698 /* Nothing to do on response! */
702 virtual int handleEvent(WifiEvent
& event
) {
703 ALOGI("Got a RSSI monitor event");
705 nlattr
*vendor_data
= event
.get_attribute(NL80211_ATTR_VENDOR_DATA
);
706 int len
= event
.get_vendor_data_len();
708 if (vendor_data
== NULL
|| len
== 0) {
709 ALOGI("RSSI monitor: No data");
718 rssi_monitor_evt
*data
= (rssi_monitor_evt
*)event
.get_vendor_data();
720 if (*mHandler
.on_rssi_threshold_breached
) {
721 (*mHandler
.on_rssi_threshold_breached
)(id(), data
->BSSID
, data
->cur_rssi
);
723 ALOGW("No RSSI monitor handler registered");
733 static int wifi_get_multicast_id(wifi_handle handle
, const char *name
, const char *group
)
735 GetMulticastIdCommand
cmd(handle
, name
, group
);
736 int res
= cmd
.requestResponse();
743 /////////////////////////////////////////////////////////////////////////
745 static bool is_wifi_interface(const char *name
)
747 if (strncmp(name
, "wlan", 4) != 0 && strncmp(name
, "p2p", 3) != 0) {
748 /* not a wifi interface; ignore it */
755 static int get_interface(const char *name
, interface_info
*info
)
757 strcpy(info
->name
, name
);
758 info
->id
= if_nametoindex(name
);
759 ALOGI("found an interface : %s, id = %d", name
, info
->id
);
763 wifi_error
wifi_init_interfaces(wifi_handle handle
)
765 hal_info
*info
= (hal_info
*)handle
;
766 ALOGD("wifi_init_interfaces, info = %p", info
);
770 DIR *d
= opendir("/sys/class/net");
772 return WIFI_ERROR_UNKNOWN
;
775 while ((de
= readdir(d
))) {
776 if (de
->d_name
[0] == '.')
778 if (is_wifi_interface(de
->d_name
) ) {
785 d
= opendir("/sys/class/net");
787 return WIFI_ERROR_UNKNOWN
;
789 info
->interfaces
= (interface_info
**)malloc(sizeof(interface_info
*) * n
);
792 while ((de
= readdir(d
))) {
793 if (de
->d_name
[0] == '.')
795 if (is_wifi_interface(de
->d_name
)) {
796 interface_info
*ifinfo
= (interface_info
*)malloc(sizeof(interface_info
));
797 if (get_interface(de
->d_name
, ifinfo
) != WIFI_SUCCESS
) {
801 ifinfo
->handle
= handle
;
802 info
->interfaces
[i
] = ifinfo
;
809 info
->num_interfaces
= n
;
813 wifi_error
wifi_get_ifaces(wifi_handle handle
, int *num
, wifi_interface_handle
**interfaces
)
815 hal_info
*info
= (hal_info
*)handle
;
817 *interfaces
= (wifi_interface_handle
*)info
->interfaces
;
818 *num
= info
->num_interfaces
;
823 wifi_error
wifi_get_iface_name(wifi_interface_handle handle
, char *name
, size_t size
)
825 interface_info
*info
= (interface_info
*)handle
;
826 strcpy(name
, info
->name
);
830 wifi_error
wifi_get_supported_feature_set(wifi_interface_handle handle
, feature_set
*set
)
832 return WIFI_ERROR_NOT_SUPPORTED
;
835 wifi_error
wifi_get_concurrency_matrix(wifi_interface_handle handle
, int set_size_max
,
836 feature_set set
[], int *set_size
)
838 return WIFI_ERROR_NOT_SUPPORTED
;
841 wifi_error
wifi_set_scanning_mac_oui(wifi_interface_handle handle
, oui scan_oui
)
843 SetPnoMacAddrOuiCommand
command(handle
, scan_oui
);
844 return (wifi_error
)command
.start();
848 wifi_error
wifi_set_nodfs_flag(wifi_interface_handle handle
, u32 nodfs
)
850 SetNodfsCommand
command(handle
, nodfs
);
851 return (wifi_error
) command
.requestResponse();
854 static wifi_error
wifi_start_rssi_monitoring(wifi_request_id id
, wifi_interface_handle
855 iface
, s8 max_rssi
, s8 min_rssi
, wifi_rssi_event_handler eh
)
857 ALOGD("Start RSSI monitor %d", id
);
858 wifi_handle handle
= getWifiHandle(iface
);
859 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
, max_rssi
, min_rssi
, eh
);
860 wifi_register_cmd(handle
, id
, cmd
);
862 wifi_error result
= (wifi_error
)cmd
->start();
863 if (result
!= WIFI_SUCCESS
) {
864 wifi_unregister_cmd(handle
, id
);
870 static wifi_error
wifi_stop_rssi_monitoring(wifi_request_id id
, wifi_interface_handle iface
)
872 ALOGD("Stopping RSSI monitor");
875 wifi_rssi_event_handler handler
;
876 wifi_handle handle
= getWifiHandle(iface
);
877 memset(&handler
, 0, sizeof(handler
));
878 SetRSSIMonitorCommand
*cmd
= new SetRSSIMonitorCommand(id
, iface
,
884 return wifi_cancel_cmd(id
, iface
);
887 /////////////////////////////////////////////////////////////////////////////