summaryrefslogtreecommitdiffstats
path: root/service/lib
diff options
context:
space:
mode:
authorVinit Deshapnde <vinitd@google.com>2014-03-24 11:41:35 -0700
committerVinit Deshapnde <vinitd@google.com>2014-05-07 21:16:11 -0700
commita53b553e481f71ec7bddda6daf03beeb7ebcd932 (patch)
tree5dc465d2ff8fb56d3a90f0104e15b5329a294201 /service/lib
parent7f9a15d554f69311a0db43347d6473a7c4c46e2e (diff)
downloadframeworks_opt_net_wifi-a53b553e481f71ec7bddda6daf03beeb7ebcd932.tar.gz
frameworks_opt_net_wifi-a53b553e481f71ec7bddda6daf03beeb7ebcd932.tar.bz2
frameworks_opt_net_wifi-a53b553e481f71ec7bddda6daf03beeb7ebcd932.zip
More changes required to make HalUtil functional
This change fixes halutil to send commands to wlan0 interface. It also assigns different types to WifiHandle and WifiInterfaceHandle to make it harder to interchange usage. Change-Id: Iade453c4bdd60ef58fdafd2b9b94d8ad8a4ae562
Diffstat (limited to 'service/lib')
-rw-r--r--service/lib/common.cpp30
-rw-r--r--service/lib/common.h6
-rw-r--r--service/lib/cpp_bindings.cpp27
-rw-r--r--service/lib/cpp_bindings.h30
-rw-r--r--service/lib/gscan.cpp55
-rw-r--r--service/lib/gscan.h4
-rw-r--r--service/lib/wifi_hal.cpp8
-rw-r--r--service/lib/wifi_hal.h7
8 files changed, 123 insertions, 44 deletions
diff --git a/service/lib/common.cpp b/service/lib/common.cpp
index ab99356..cee4ad1 100644
--- a/service/lib/common.cpp
+++ b/service/lib/common.cpp
@@ -5,6 +5,36 @@
#include "wifi_hal.h"
#include "common.h"
+interface_info *getIfaceInfo(wifi_interface_handle handle)
+{
+ return (interface_info *)handle;
+}
+
+wifi_handle getWifiHandle(wifi_interface_handle handle)
+{
+ return getIfaceInfo(handle)->handle;
+}
+
+hal_info *getHalInfo(wifi_handle handle)
+{
+ return (hal_info *)handle;
+}
+
+hal_info *getHalInfo(wifi_interface_handle handle)
+{
+ return getHalInfo(getWifiHandle(handle));
+}
+
+wifi_handle getWifiHandle(hal_info *info)
+{
+ return (wifi_handle)info;
+}
+
+wifi_interface_handle getIfaceHandle(interface_info *info)
+{
+ return (wifi_interface_handle)info;
+}
+
wifi_error wifi_register_handler(wifi_handle handle, int cmd, nl_recvmsg_msg_cb_t func, void *arg)
{
hal_info *info = (hal_info *)handle;
diff --git a/service/lib/common.h b/service/lib/common.h
index ec993de..06bc00a 100644
--- a/service/lib/common.h
+++ b/service/lib/common.h
@@ -120,6 +120,12 @@ wifi_error wifi_register_cmd(wifi_handle handle, int id, WifiCommand *cmd);
WifiCommand *wifi_unregister_cmd(wifi_handle handle, int id);
void wifi_unregister_cmd(wifi_handle handle, WifiCommand *cmd);
+interface_info *getIfaceInfo(wifi_interface_handle);
+wifi_handle getWifiHandle(wifi_interface_handle handle);
+hal_info *getHalInfo(wifi_handle handle);
+hal_info *getHalInfo(wifi_interface_handle handle);
+wifi_handle getWifiHandle(hal_info *info);
+wifi_interface_handle getIfaceHandle(interface_info *info);
#endif
diff --git a/service/lib/cpp_bindings.cpp b/service/lib/cpp_bindings.cpp
index 08dd754..02efc4f 100644
--- a/service/lib/cpp_bindings.cpp
+++ b/service/lib/cpp_bindings.cpp
@@ -233,6 +233,13 @@ int WifiRequest::create(uint32_t id, int subcmd) {
return 0;
}
+
+static int no_seq_check(struct nl_msg *msg, void *arg)
+{
+ return NL_OK;
+}
+
+
int WifiCommand::requestResponse() {
struct nl_cb *cb = NULL;
int err = create(); /* create the message */
@@ -250,6 +257,7 @@ int WifiCommand::requestResponse() {
err = 1;
nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
+ nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, response_handler, this);
@@ -269,7 +277,7 @@ int WifiCommand::requestEvent(int cmd) {
ALOGD("requesting event %d", cmd);
- int res = wifi_register_handler(mInfo, cmd, event_handler, this);
+ int res = wifi_register_handler(wifiHandle(), cmd, event_handler, this);
if (res < 0) {
return res;
}
@@ -290,13 +298,13 @@ int WifiCommand::requestEvent(int cmd) {
goto out;
out:
- wifi_unregister_handler(mInfo, cmd);
+ wifi_unregister_handler(wifiHandle(), cmd);
return res;
}
int WifiCommand::requestVendorEvent(uint32_t id, int subcmd) {
- int res = wifi_register_vendor_handler(mInfo, id, subcmd, event_handler, this);
+ int res = wifi_register_vendor_handler(wifiHandle(), id, subcmd, event_handler, this);
if (res < 0) {
return res;
}
@@ -320,6 +328,7 @@ out:
/* Event handlers */
int WifiCommand::response_handler(struct nl_msg *msg, void *arg) {
+ ALOGD("response_handler called");
WifiCommand *cmd = (WifiCommand *)arg;
WifiEvent reply(msg);
int res = reply.parse();
@@ -347,13 +356,23 @@ int WifiCommand::event_handler(struct nl_msg *msg, void *arg) {
}
/* Other event handlers */
+int WifiCommand::valid_handler(struct nl_msg *msg, void *arg) {
+ ALOGD("valid_handler called");
+ int *err = (int *)arg;
+ *err = 0;
+ return NL_SKIP;
+}
+
int WifiCommand::ack_handler(struct nl_msg *msg, void *arg) {
+ ALOGD("ack_handler called");
int *err = (int *)arg;
*err = 0;
return NL_STOP;
}
int WifiCommand::finish_handler(struct nl_msg *msg, void *arg) {
+
+ ALOGD("finish_handler called");
int *ret = (int *)arg;
*ret = 0;
return NL_SKIP;
@@ -362,5 +381,7 @@ int WifiCommand::finish_handler(struct nl_msg *msg, void *arg) {
int WifiCommand::error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) {
int *ret = (int *)arg;
*ret = err->error;
+
+ ALOGD("error_handler received : %d", err->error);
return NL_SKIP;
}
diff --git a/service/lib/cpp_bindings.h b/service/lib/cpp_bindings.h
index 45db5db..2a67871 100644
--- a/service/lib/cpp_bindings.h
+++ b/service/lib/cpp_bindings.h
@@ -155,6 +155,7 @@ public:
int set_iface_id(int ifindex) {
return put_u32(NL80211_ATTR_IFINDEX, ifindex);
}
+
};
class WifiCommand
@@ -164,12 +165,22 @@ protected:
WifiRequest mMsg;
Condition mCondition;
wifi_request_id mId;
+ interface_info *mIfaceInfo;
public:
WifiCommand(wifi_handle handle, wifi_request_id id)
- : mMsg(((hal_info *)handle)->nl80211_family_id), mId(id)
+ : mMsg(getHalInfo(handle)->nl80211_family_id), mId(id)
+ {
+ mIfaceInfo = NULL;
+ mInfo = getHalInfo(handle);
+ ALOGV("WifiCommand %p created, mInfo = %p, mIfaceInfo = %p", this, mInfo, mIfaceInfo);
+ }
+
+ WifiCommand(wifi_interface_handle iface, wifi_request_id id)
+ : mMsg(getHalInfo(iface)->nl80211_family_id), mId(id)
{
- mInfo = (hal_info *)handle;
- ALOGV("WifiCommand %p created", this);
+ mIfaceInfo = getIfaceInfo(iface);
+ mInfo = getHalInfo(iface);
+ ALOGV("WifiCommand %p created, mInfo = %p, mIfaceInfo = %p", this, mInfo, mIfaceInfo);
}
virtual ~WifiCommand() {
@@ -191,6 +202,9 @@ public:
int requestVendorEvent(uint32_t id, int subcmd);
protected:
+ wifi_handle wifiHandle() {
+ return getWifiHandle(mInfo);
+ }
/* Override this method to parse reply and dig out data; save it in the object */
virtual int handleResponse(WifiEvent reply) {
@@ -205,19 +219,19 @@ protected:
}
int registerHandler(int cmd) {
- return wifi_register_handler(mInfo, cmd, &event_handler, this);
+ return wifi_register_handler(wifiHandle(), cmd, &event_handler, this);
}
void unregisterHandler(int cmd) {
- wifi_unregister_handler(mInfo, cmd);
+ wifi_unregister_handler(wifiHandle(), cmd);
}
int registerVendorHandler(uint32_t id, int subcmd) {
- return wifi_register_vendor_handler(mInfo, id, subcmd, &event_handler, this);
+ return wifi_register_vendor_handler(wifiHandle(), id, subcmd, &event_handler, this);
}
void unregisterVendorHandler(uint32_t id, int subcmd) {
- wifi_unregister_vendor_handler(mInfo, id, subcmd);
+ wifi_unregister_vendor_handler(wifiHandle(), id, subcmd);
}
private:
@@ -228,6 +242,8 @@ private:
static int event_handler(struct nl_msg *msg, void *arg);
/* Other event handlers */
+ static int valid_handler(struct nl_msg *msg, void *arg);
+
static int ack_handler(struct nl_msg *msg, void *arg);
static int finish_handler(struct nl_msg *msg, void *arg);
diff --git a/service/lib/gscan.cpp b/service/lib/gscan.cpp
index 3b2eeca..75ad8ce 100644
--- a/service/lib/gscan.cpp
+++ b/service/lib/gscan.cpp
@@ -78,9 +78,9 @@ private:
static const unsigned int MAX_RESULTS = 1024;
wifi_scan_result mResults[MAX_RESULTS];
public:
- ScanCommand(wifi_handle handle, int id, wifi_scan_bucket_spec *buckets, unsigned n,
+ ScanCommand(wifi_interface_handle iface, int id, wifi_scan_bucket_spec *buckets, unsigned n,
wifi_scan_result_handler handler)
- : WifiCommand(handle, id), mHandler(handler)
+ : WifiCommand(iface, id), mHandler(handler)
{
mNumBuckets = n > MAX_BUCKETS ? MAX_BUCKETS : n;
for (int i = 0; i < mNumBuckets; i++) {
@@ -89,17 +89,19 @@ public:
}
virtual int create() {
- ALOGD("Creating message to scan");
+ ALOGD("Creating message to scan; iface = %d", mIfaceInfo->id);
int ret = mMsg.create(NL80211_CMD_TRIGGER_SCAN, 0, 0);
if (ret < 0) {
return ret;
}
- mMsg.put_u32(NL80211_ATTR_IFINDEX, 0);
+ mMsg.put_u32(NL80211_ATTR_IFINDEX, mIfaceInfo->id);
struct nlattr * attr = mMsg.attr_start(NL80211_ATTR_SCAN_FREQUENCIES);
int channel_id = 0;
+
+ /*
for (int i = 0; i < mNumBuckets; i++) {
wifi_scan_bucket_spec &bucket = mBuckets[i];
for (int j = 0; j < bucket.num_channels; j++) {
@@ -108,10 +110,15 @@ public:
return ret;
}
}
- }
+ }*/
+
+ mMsg.put_u32(channel_id++, 2412);
+ mMsg.put_u32(channel_id++, 2437);
+ mMsg.put_u32(channel_id++, 2462);
mMsg.attr_end(attr);
- // mMsg.put_u32(NL80211_ATTR_SCAN_FLAGS, NL80211_SCAN_FLAG_FLUSH);
+
+ mMsg.put_u32(NL80211_ATTR_SCAN_FLAGS, NL80211_SCAN_FLAG_FLUSH);
return ret;
}
@@ -162,6 +169,7 @@ public:
ALOGI("SSID attribute size = %d", event.len(NL80211_ATTR_SCAN_SSIDS));
int rem = 0, i = 0;
+
nl_iterator it(event.get_attribute(NL80211_ATTR_SCAN_SSIDS));
for ( ; it.has_next(); it.next(), i++) {
struct nlattr *attr = it.get();
@@ -188,13 +196,12 @@ wifi_error wifi_start_gscan(
wifi_scan_cmd_params params,
wifi_scan_result_handler handler)
{
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
+ ALOGD("Starting GScan, halHandle = %p", handle);
ALOGD("Starting GScan, halHandle = %p", handle);
- ScanCommand *cmd = new ScanCommand(handle, id, params.buckets, params.num_buckets, handler);
+ ScanCommand *cmd = new ScanCommand(iface, id, params.buckets, params.num_buckets, handler);
wifi_register_cmd(handle, id, cmd);
return (wifi_error)cmd->start();
}
@@ -202,9 +209,7 @@ wifi_error wifi_start_gscan(
wifi_error wifi_stop_gscan(wifi_request_id id, wifi_interface_handle iface)
{
ALOGD("Stopping GScan");
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
WifiCommand *cmd = wifi_unregister_cmd(handle, id);
if (cmd) {
@@ -229,7 +234,7 @@ private:
static const unsigned int MAX_RESULTS = 64;
wifi_scan_result mResults[MAX_RESULTS];
public:
- BssidHotlistCommand(wifi_handle handle, int id,
+ BssidHotlistCommand(wifi_interface_handle handle, int id,
mac_addr bssid[], int num, wifi_hotlist_ap_found_handler handler)
: WifiCommand(handle, id), mNum(num), mBssids(bssid), mHandler(handler)
{ }
@@ -304,20 +309,16 @@ public:
wifi_error wifi_set_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface,
int num_bssid, mac_addr bssid[], wifi_hotlist_ap_found_handler handler)
{
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
- BssidHotlistCommand *cmd = new BssidHotlistCommand(handle, id, bssid, num_bssid, handler);
+ BssidHotlistCommand *cmd = new BssidHotlistCommand(iface, id, bssid, num_bssid, handler);
wifi_register_cmd(handle, id, cmd);
return (wifi_error)cmd->start();
}
wifi_error wifi_reset_bssid_hotlist(wifi_request_id id, wifi_interface_handle iface)
{
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
WifiCommand *cmd = wifi_unregister_cmd(handle, id);
if (cmd) {
@@ -341,7 +342,7 @@ private:
static const unsigned int MAX_RESULTS = 64;
wifi_scan_result mResults[MAX_RESULTS];
public:
- SignificantWifiChangeCommand(wifi_handle handle, int id,
+ SignificantWifiChangeCommand(wifi_interface_handle handle, int id,
wifi_significant_change_handler handler)
: WifiCommand(handle, id), mHandler(handler)
{ }
@@ -403,20 +404,16 @@ public:
wifi_error wifi_set_significant_change_handler(wifi_request_id id, wifi_interface_handle iface,
wifi_significant_change_handler handler)
{
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
- SignificantWifiChangeCommand *cmd = new SignificantWifiChangeCommand(handle, id, handler);
+ SignificantWifiChangeCommand *cmd = new SignificantWifiChangeCommand(iface, id, handler);
wifi_register_cmd(handle, id, cmd);
return (wifi_error)cmd->start();
}
wifi_error wifi_reset_significant_change_handler(wifi_request_id id, wifi_interface_handle iface)
{
- interface_info *iinfo = (interface_info *)iface;
- wifi_handle handle = iinfo->handle;
- hal_info *info = (hal_info *)handle;
+ wifi_handle handle = getWifiHandle(iface);
WifiCommand *cmd = wifi_unregister_cmd(handle, id);
if (cmd) {
diff --git a/service/lib/gscan.h b/service/lib/gscan.h
index 564e8f3..5484b5e 100644
--- a/service/lib/gscan.h
+++ b/service/lib/gscan.h
@@ -68,10 +68,10 @@ typedef struct {
typedef struct {
int period; // base timer period
- int num_buckets; // maximum 8
- wifi_scan_bucket_spec buckets[];
int max_ap_per_scan;
int report_threshold; // in %, when buffer is this much full, wake up AP
+ int num_buckets; // maximum 8
+ wifi_scan_bucket_spec buckets[];
} wifi_scan_cmd_params;
wifi_error wifi_start_gscan(wifi_request_id id, wifi_interface_handle iface,
diff --git a/service/lib/wifi_hal.cpp b/service/lib/wifi_hal.cpp
index 8b19a55..535f52e 100644
--- a/service/lib/wifi_hal.cpp
+++ b/service/lib/wifi_hal.cpp
@@ -296,6 +296,7 @@ static int internal_valid_message_handler(nl_msg *msg, void *arg)
ALOGI("event received %s, vendor_id = 0x%0x", event.get_cmdString(), vendor_id);
event.log();
+ bool dispatched = false;
for (int i = 0; i < info->num_event_cb; i++) {
if (cmd == info->event_cb[i].nl_cmd) {
if (cmd == NL80211_CMD_VENDOR && vendor_id != info->event_cb[i].vendor_id) {
@@ -304,10 +305,15 @@ static int internal_valid_message_handler(nl_msg *msg, void *arg)
}
cb_info *cbi = &(info->event_cb[i]);
- return (*(cbi->cb_func))(msg, cbi->cb_arg);
+ (*(cbi->cb_func))(msg, cbi->cb_arg);
+ dispatched = true;
}
}
+ if (!dispatched) {
+ ALOGI("event ignored!!");
+ }
+
return NL_OK;
}
diff --git a/service/lib/wifi_hal.h b/service/lib/wifi_hal.h
index 85a46a3..e457670 100644
--- a/service/lib/wifi_hal.h
+++ b/service/lib/wifi_hal.h
@@ -21,14 +21,17 @@ typedef unsigned char u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
-typedef void * wifi_handle;
typedef int wifi_request_id;
typedef int wifi_channel; // indicates channel frequency in MHz
typedef int wifi_rssi;
typedef byte mac_addr[6];
typedef int64_t wifi_timestamp; // In microseconds (us)
typedef int64_t wifi_timespan; // In nanoseconds (ns)
-typedef void * wifi_interface_handle;
+
+struct wifi_info;
+typedef wifi_info *wifi_handle;
+struct wifi_interface_info;
+typedef wifi_interface_info *wifi_interface_handle;
/* Initialize/Cleanup */