summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSasha Levitskiy <sanek@google.com>2012-07-30 16:12:55 -0700
committerSasha Levitskiy <sanek@google.com>2012-08-02 14:42:40 -0700
commitda7f23fd19752991f8e7f47ebf3477b17d788e02 (patch)
treed2b2d580134abd3d221262bb7561aeb26e24924a
parentd7a54937447ed8bbb6869783a499d48200b5ed74 (diff)
downloadhardware_broadcom_wlan-da7f23fd19752991f8e7f47ebf3477b17d788e02.zip
hardware_broadcom_wlan-da7f23fd19752991f8e7f47ebf3477b17d788e02.tar.gz
hardware_broadcom_wlan-da7f23fd19752991f8e7f47ebf3477b17d788e02.tar.bz2
Adds a dynamic interface command library for Broadcom bcmdhd
Change-Id: Ie1d1bdd94a26d5647c739d86806dae528301fa00
-rw-r--r--bcmdhd/bcmdhd_net_iface/Android.mk30
-rw-r--r--bcmdhd/bcmdhd_net_iface/bcmdhd_net_iface.c84
2 files changed, 114 insertions, 0 deletions
diff --git a/bcmdhd/bcmdhd_net_iface/Android.mk b/bcmdhd/bcmdhd_net_iface/Android.mk
new file mode 100644
index 0000000..be22624
--- /dev/null
+++ b/bcmdhd/bcmdhd_net_iface/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2012 Google, inc.
+#
+# $Id: Android.mk,v 2.6 2009-05-07 18:25:15 hharte Exp $
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
+#
+# lib_net_iface_cmd
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := bcmdhd_net_iface.c
+LOCAL_MODULE := libnetcmdiface
+LOCAL_CFLAGS := -mabi=aapcs-linux
+LOCAL_MODULE_TAGS := optional
+LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
+include $(BUILD_SHARED_LIBRARY)
diff --git a/bcmdhd/bcmdhd_net_iface/bcmdhd_net_iface.c b/bcmdhd/bcmdhd_net_iface/bcmdhd_net_iface.c
new file mode 100644
index 0000000..9aed684
--- /dev/null
+++ b/bcmdhd/bcmdhd_net_iface/bcmdhd_net_iface.c
@@ -0,0 +1,84 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <linux/in.h>
+#include <net/if.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <cutils/log.h>
+#include <netutils/ifc.h>
+#include <private/android_filesystem_config.h>
+
+#define INTERFACE_MAX_BUFFER_SIZE 4096
+
+typedef struct android_wifi_priv_cmd {
+ char *buf;
+ int used_len;
+ int total_len;
+} android_wifi_priv_cmd;
+
+static struct net_if_snd_cmd_state {
+ int sock;
+ char cmd[INTERFACE_MAX_BUFFER_SIZE];
+ char ibuf[INTERFACE_MAX_BUFFER_SIZE];
+} state;
+
+int net_iface_send_command_init(void) {
+ state.sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (state.sock < 0) {
+ return -ENOTCONN;
+ } else {
+ return 0;
+ }
+}
+
+/*
+ * Arguments:
+ * argv[2] - wlan interface
+ * argv[3] - command
+ * argv[4] - argument
+ */
+int net_iface_send_command(int argc, char *argv[], char **rbuf) {
+ int ret, i;
+ size_t bc = 0;
+ struct ifreq ifr;
+ android_wifi_priv_cmd priv_cmd;
+
+ if (argc < 3) {
+ return -EINVAL;
+ }
+ for (i = 3; i < argc; i++) {
+ bc += snprintf(&state.cmd[bc], sizeof(state.cmd) - bc, "%s ", argv[i]);
+ if (bc >= sizeof(state.cmd)) {
+ return -ENOBUFS;
+ }
+ }
+ state.cmd[bc] = '\0';
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, argv[2], IFNAMSIZ);
+ strncpy(state.ibuf, state.cmd, INTERFACE_MAX_BUFFER_SIZE);
+
+ priv_cmd.buf = state.ibuf;
+ priv_cmd.used_len = INTERFACE_MAX_BUFFER_SIZE;
+ priv_cmd.total_len = INTERFACE_MAX_BUFFER_SIZE;
+
+ ifr.ifr_data = &priv_cmd;
+
+ if ((ret = ioctl(state.sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) {
+ return ret;
+ }
+
+ if (rbuf)
+ *rbuf = state.ibuf;
+ else
+ ret = -EFAULT;
+
+ return ret;
+}